Skip to content

Commit

Permalink
signhub: orchestrator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
attente committed Oct 24, 2023
1 parent bceaecf commit d1ccd06
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
10 changes: 5 additions & 5 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { migrator, defaults, version } from '@0xsequence/migration'
import { ChainId, NetworkConfig } from '@0xsequence/network'
import { FeeOption, FeeQuote, isRelayer, Relayer, RpcRelayer } from '@0xsequence/relayer'
import { tracker } from '@0xsequence/sessions'
import { Orchestrator } from '@0xsequence/signhub'
import { OrchestratorInterface } from '@0xsequence/signhub'
import { encodeTypedDataDigest, getDefaultConnectionInfo } from '@0xsequence/utils'
import { Wallet } from '@0xsequence/wallet'
import { ethers, TypedDataDomain, TypedDataField } from 'ethers'
Expand Down Expand Up @@ -48,7 +48,7 @@ export type AccountOptions = {
migrations?: migrator.Migrations

// Orchestrator manages signing messages and transactions
orchestrator: Orchestrator
orchestrator: OrchestratorInterface

// Networks information and providers
networks: NetworkConfig[]
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Account {
public readonly migrator: migrator.Migrator
public readonly migrations: migrator.Migrations

private orchestrator: Orchestrator
private orchestrator: OrchestratorInterface

constructor(options: AccountOptions) {
this.address = ethers.utils.getAddress(options.address)
Expand All @@ -115,7 +115,7 @@ export class Account {
config: commons.config.SimpleConfig
tracker: tracker.ConfigTracker & migrator.PresignedMigrationTracker
contexts: commons.context.VersionedContext
orchestrator: Orchestrator
orchestrator: OrchestratorInterface
networks: NetworkConfig[]
migrations?: migrator.Migrations
}): Promise<Account> {
Expand Down Expand Up @@ -195,7 +195,7 @@ export class Account {
return new RpcRelayer(found.relayer)
}

setOrchestrator(orchestrator: Orchestrator) {
setOrchestrator(orchestrator: OrchestratorInterface) {
this.orchestrator = orchestrator
}

Expand Down
6 changes: 3 additions & 3 deletions packages/auth/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jwtDecodeClaims } from '@0xsequence/utils'
import { Account } from '@0xsequence/account'
import { ethers } from 'ethers'
import { tracker, trackers } from '@0xsequence/sessions'
import { Orchestrator } from '@0xsequence/signhub'
import { Orchestrator, OrchestratorInterface } from '@0xsequence/signhub'
import { migrator } from '@0xsequence/migration'
import { commons, universal, v1 } from '@0xsequence/core'
import { Services, ServicesSettings, SessionJWT, SessionMeta } from './services'
Expand Down Expand Up @@ -137,7 +137,7 @@ export class Session {

static async open(args: {
settings?: Partial<SessionSettings>
orchestrator: Orchestrator
orchestrator: OrchestratorInterface
addSigners?: commons.config.SimpleSigner[]
referenceSigner: string
threshold?: ethers.BigNumberish
Expand Down Expand Up @@ -286,7 +286,7 @@ export class Session {

static async load(args: {
settings?: Partial<SessionSettings>
orchestrator: Orchestrator
orchestrator: OrchestratorInterface
dump: SessionDumpV1 | SessionDumpV2
editConfigOnMigration: (config: commons.config.Config) => commons.config.Config
onMigration?: (account: Account) => Promise<boolean>
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/tests/session.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { migrator } from '@0xsequence/migration'
import { NetworkConfig } from '@0xsequence/network'
import { LocalRelayer } from '@0xsequence/relayer'
import { tracker, trackers } from '@0xsequence/sessions'
import { Orchestrator } from '@0xsequence/signhub'
import { Orchestrator, OrchestratorInterface } from '@0xsequence/signhub'
import * as utils from '@0xsequence/tests'
import { CallReceiverMock, HookCallerMock } from '@0xsequence/wallet-contracts'
import * as chai from 'chai'
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Wallet integration', function () {
let networks: NetworkConfig[]

let tracker: tracker.ConfigTracker & migrator.PresignedMigrationTracker
let orchestrator: Orchestrator
let orchestrator: OrchestratorInterface
let simpleSettings: SessionSettings

before(async () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/signhub/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export function isSignerStatusPending(status: SignerStatus): status is SignerSta

export const InitialSituation = 'Initial'

export interface OrchestratorInterface {
getSigners(): Promise<string[]>

signMessage(args: {
candidates: string[]
message: ethers.BytesLike
metadata: Object
callback: (status: Status, onNewMetadata: (metadata: Object) => void) => boolean
}): Promise<Status>
}

/**
* It orchestrates the signing of a single digest by multiple signers.
* It can provide internal visibility of the signing process, and it also
Expand Down
8 changes: 4 additions & 4 deletions packages/wallet/src/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'ethers'
import { commons, v1, v2 } from '@0xsequence/core'
import { isSignerStatusSigned, Orchestrator, Status } from '@0xsequence/signhub'
import { isSignerStatusSigned, OrchestratorInterface, Status } from '@0xsequence/signhub'
import { Deferrable, subDigestOf } from '@0xsequence/utils'
import { FeeQuote, Relayer, SimulateResult } from '@0xsequence/relayer'
import { walletContracts } from '@0xsequence/abi'
Expand All @@ -24,7 +24,7 @@ export type WalletOptions<
chainId: ethers.BigNumberish
address: string

orchestrator: Orchestrator
orchestrator: OrchestratorInterface
reader?: commons.reader.Reader

provider?: ethers.providers.Provider
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Wallet<
config: commons.config.ConfigCoder<Y>
}

private orchestrator: Orchestrator
private orchestrator: OrchestratorInterface
private _reader?: commons.reader.Reader

constructor(options: WalletOptions<T, Y, Z>) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export class Wallet<
this.config = config
}

setOrchestrator(orchestrator: Orchestrator) {
setOrchestrator(orchestrator: OrchestratorInterface) {
this.orchestrator = orchestrator
}

Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/tests/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { commons, v1, v2 } from '@0xsequence/core'
import { context } from '@0xsequence/tests'
import { ethers } from 'ethers'
import { SequenceOrchestratorWrapper, Wallet } from '../src/index'
import { Orchestrator, signers as hubsigners } from '@0xsequence/signhub'
import { Orchestrator, OrchestratorInterface, signers as hubsigners } from '@0xsequence/signhub'
import { LocalRelayer } from '@0xsequence/relayer'

const { expect } = chai
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('Wallet (primitive)', () => {
}
].map(({ name, signers }) => {
describe(`Using ${name}`, () => {
let orchestrator: Orchestrator
let orchestrator: OrchestratorInterface
let config: commons.config.Config

beforeEach(async () => {
Expand Down

0 comments on commit d1ccd06

Please sign in to comment.