1
- import { Buff } from '@cmdcode/buff'
1
+ import { Buff , Bytes } from '@cmdcode/buff'
2
2
import { Signer , Wallet } from '@cmdcode/signer'
3
- import { SignerConfig } from '@/client/types.js'
4
3
import { EscrowClient } from './client.js'
5
4
6
5
import deposit_api from '../api/depositor.js'
@@ -9,16 +8,35 @@ import proposal_api from '../api/proposal.js'
9
8
import request_api from '../api/request.js'
10
9
import witness_api from '../api/witness.js'
11
10
11
+ import {
12
+ ClientConfig ,
13
+ SignerConfig
14
+ } from '@/client/types.js'
15
+
12
16
import {
13
17
CredSignerAPI ,
18
+ Network ,
14
19
WalletAPI
15
20
} from '@/types/index.js'
16
21
17
22
const DEFAULT_IDXGEN = ( ) => Buff . now ( 4 ) . num
18
23
19
24
export class EscrowSigner {
20
25
26
+ static create (
27
+ config : ClientConfig ,
28
+ seed : Bytes ,
29
+ xpub ?: string
30
+ ) {
31
+ const signer = new Signer ( { seed } )
32
+ const wallet = ( xpub !== undefined )
33
+ ? new Wallet ( xpub )
34
+ : Wallet . generate ( { seed, network : config . network as Network } )
35
+ return new EscrowSigner ( { ...config , signer, wallet } )
36
+ }
37
+
21
38
static load (
39
+ config : ClientConfig ,
22
40
password : string ,
23
41
payload : string
24
42
) {
@@ -28,7 +46,7 @@ export class EscrowSigner {
28
46
const pass = Buff . str ( password )
29
47
const signer = Signer . restore ( pass , encdata )
30
48
const wallet = new Wallet ( xpub )
31
- return new EscrowSigner ( { signer, wallet } )
49
+ return new EscrowSigner ( { ... config , signer, wallet } )
32
50
}
33
51
34
52
readonly _client : EscrowClient
0 commit comments