@openzeppelin/miden-multisig-client 0.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -0
- package/dist/account/builder.d.ts +23 -0
- package/dist/account/builder.d.ts.map +1 -0
- package/dist/account/builder.js +85 -0
- package/dist/account/builder.js.map +1 -0
- package/dist/account/index.d.ts +6 -0
- package/dist/account/index.d.ts.map +1 -0
- package/dist/account/index.js +6 -0
- package/dist/account/index.js.map +1 -0
- package/dist/account/masm.d.ts +3 -0
- package/dist/account/masm.d.ts.map +1 -0
- package/dist/account/masm.js +605 -0
- package/dist/account/masm.js.map +1 -0
- package/dist/account/storage.d.ts +10 -0
- package/dist/account/storage.d.ts.map +1 -0
- package/dist/account/storage.js +56 -0
- package/dist/account/storage.js.map +1 -0
- package/dist/account.d.ts +104 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +136 -0
- package/dist/account.js.map +1 -0
- package/dist/builder.d.ts +54 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +78 -0
- package/dist/builder.js.map +1 -0
- package/dist/client.d.ts +73 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +104 -0
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +150 -0
- package/dist/client.test.js.map +1 -0
- package/dist/http.d.ts +64 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +162 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector.d.ts +49 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +120 -0
- package/dist/inspector.js.map +1 -0
- package/dist/inspector.test.d.ts +2 -0
- package/dist/inspector.test.d.ts.map +1 -0
- package/dist/inspector.test.js +205 -0
- package/dist/inspector.test.js.map +1 -0
- package/dist/keystore.d.ts +65 -0
- package/dist/keystore.d.ts.map +1 -0
- package/dist/keystore.js +121 -0
- package/dist/keystore.js.map +1 -0
- package/dist/miden.d.ts +9 -0
- package/dist/miden.d.ts.map +1 -0
- package/dist/miden.js +26 -0
- package/dist/miden.js.map +1 -0
- package/dist/multisig/helpers.d.ts +4 -0
- package/dist/multisig/helpers.d.ts.map +1 -0
- package/dist/multisig/helpers.js +21 -0
- package/dist/multisig/helpers.js.map +1 -0
- package/dist/multisig/helpers.test.d.ts +2 -0
- package/dist/multisig/helpers.test.d.ts.map +1 -0
- package/dist/multisig/helpers.test.js +94 -0
- package/dist/multisig/helpers.test.js.map +1 -0
- package/dist/multisig/metadata.d.ts +18 -0
- package/dist/multisig/metadata.d.ts.map +1 -0
- package/dist/multisig/metadata.js +100 -0
- package/dist/multisig/metadata.js.map +1 -0
- package/dist/multisig/metadata.test.d.ts +2 -0
- package/dist/multisig/metadata.test.d.ts.map +1 -0
- package/dist/multisig/metadata.test.js +323 -0
- package/dist/multisig/metadata.test.js.map +1 -0
- package/dist/multisig.d.ts +199 -0
- package/dist/multisig.d.ts.map +1 -0
- package/dist/multisig.js +821 -0
- package/dist/multisig.js.map +1 -0
- package/dist/multisig.test.d.ts +2 -0
- package/dist/multisig.test.d.ts.map +1 -0
- package/dist/multisig.test.js +1121 -0
- package/dist/multisig.test.js.map +1 -0
- package/dist/procedures.d.ts +57 -0
- package/dist/procedures.d.ts.map +1 -0
- package/dist/procedures.js +62 -0
- package/dist/procedures.js.map +1 -0
- package/dist/signer.d.ts +36 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +68 -0
- package/dist/signer.js.map +1 -0
- package/dist/signer.test.d.ts +2 -0
- package/dist/signer.test.d.ts.map +1 -0
- package/dist/signer.test.js +117 -0
- package/dist/signer.test.js.map +1 -0
- package/dist/transaction/consumeNotes.d.ts +7 -0
- package/dist/transaction/consumeNotes.d.ts.map +1 -0
- package/dist/transaction/consumeNotes.js +28 -0
- package/dist/transaction/consumeNotes.js.map +1 -0
- package/dist/transaction/index.d.ts +7 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +6 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/options.d.ts +6 -0
- package/dist/transaction/options.d.ts.map +1 -0
- package/dist/transaction/options.js +2 -0
- package/dist/transaction/options.js.map +1 -0
- package/dist/transaction/p2id.d.ts +7 -0
- package/dist/transaction/p2id.d.ts.map +1 -0
- package/dist/transaction/p2id.js +43 -0
- package/dist/transaction/p2id.js.map +1 -0
- package/dist/transaction/summary.d.ts +3 -0
- package/dist/transaction/summary.d.ts.map +1 -0
- package/dist/transaction/summary.js +6 -0
- package/dist/transaction/summary.js.map +1 -0
- package/dist/transaction/updatePsm.d.ts +7 -0
- package/dist/transaction/updatePsm.d.ts.map +1 -0
- package/dist/transaction/updatePsm.js +43 -0
- package/dist/transaction/updatePsm.js.map +1 -0
- package/dist/transaction/updateSigners.d.ts +8 -0
- package/dist/transaction/updateSigners.d.ts.map +1 -0
- package/dist/transaction/updateSigners.js +60 -0
- package/dist/transaction/updateSigners.js.map +1 -0
- package/dist/transaction.d.ts +6 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +8 -0
- package/dist/transaction.js.map +1 -0
- package/dist/transaction.test.d.ts +2 -0
- package/dist/transaction.test.d.ts.map +1 -0
- package/dist/transaction.test.js +117 -0
- package/dist/transaction.test.js.map +1 -0
- package/dist/transport/http.d.ts +64 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +162 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/index.d.ts +5 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/types/proposal.d.ts +74 -0
- package/dist/types/proposal.d.ts.map +1 -0
- package/dist/types/proposal.js +2 -0
- package/dist/types/proposal.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/encoding.d.ts +7 -0
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/encoding.js +54 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/encoding.test.d.ts +2 -0
- package/dist/utils/encoding.test.d.ts.map +1 -0
- package/dist/utils/encoding.test.js +185 -0
- package/dist/utils/encoding.test.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/random.d.ts +3 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +14 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/signature.d.ts +12 -0
- package/dist/utils/signature.d.ts.map +1 -0
- package/dist/utils/signature.js +28 -0
- package/dist/utils/signature.js.map +1 -0
- package/dist/utils/signature.test.d.ts +2 -0
- package/dist/utils/signature.test.d.ts.map +1 -0
- package/dist/utils/signature.test.js +149 -0
- package/dist/utils/signature.test.js.map +1 -0
- package/dist/utils/word.d.ts +4 -0
- package/dist/utils/word.d.ts.map +1 -0
- package/dist/utils/word.js +8 -0
- package/dist/utils/word.js.map +1 -0
- package/dist/utils/word.test.d.ts +2 -0
- package/dist/utils/word.test.d.ts.map +1 -0
- package/dist/utils/word.test.js +54 -0
- package/dist/utils/word.test.js.map +1 -0
- package/masm/multisig.masm +423 -0
- package/masm/psm.masm +178 -0
- package/package.json +42 -0
- package/src/account/builder.ts +112 -0
- package/src/account/index.ts +15 -0
- package/src/account/masm.ts +606 -0
- package/src/account/storage.ts +70 -0
- package/src/client.test.ts +177 -0
- package/src/client.ts +129 -0
- package/src/index.ts +118 -0
- package/src/inspector.test.ts +237 -0
- package/src/inspector.ts +142 -0
- package/src/multisig/helpers.test.ts +114 -0
- package/src/multisig/helpers.ts +23 -0
- package/src/multisig.test.ts +1294 -0
- package/src/multisig.ts +1097 -0
- package/src/procedures.ts +72 -0
- package/src/signer.test.ts +135 -0
- package/src/signer.ts +75 -0
- package/src/transaction/consumeNotes.ts +41 -0
- package/src/transaction/index.ts +7 -0
- package/src/transaction/options.ts +7 -0
- package/src/transaction/p2id.ts +105 -0
- package/src/transaction/summary.ts +12 -0
- package/src/transaction/updatePsm.ts +69 -0
- package/src/transaction/updateSigners.ts +96 -0
- package/src/transaction.test.ts +136 -0
- package/src/transaction.ts +16 -0
- package/src/types/proposal.ts +80 -0
- package/src/types.ts +81 -0
- package/src/utils/encoding.test.ts +233 -0
- package/src/utils/encoding.ts +60 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/random.ts +15 -0
- package/src/utils/signature.test.ts +187 -0
- package/src/utils/signature.ts +36 -0
- package/src/utils/word.test.ts +64 -0
- package/src/utils/word.ts +11 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MultisigAccount wrapper class.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed wrapper around Miden accounts with multisig + PSM configuration.
|
|
5
|
+
* Mirrors the Rust MultisigAccount struct from miden-multisig-client.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper around a Miden account with multisig + PSM configuration.
|
|
9
|
+
*
|
|
10
|
+
* Provides typed accessors for storage slots following the layout:
|
|
11
|
+
*
|
|
12
|
+
* **Multisig Component (4 slots):**
|
|
13
|
+
* - Slot 0: Threshold config `[threshold, num_signers, 0, 0]`
|
|
14
|
+
* - Slot 1: Signer public keys map `[index, 0, 0, 0] => COMMITMENT`
|
|
15
|
+
* - Slot 2: Executed transactions map (for replay protection)
|
|
16
|
+
* - Slot 3: Procedure threshold overrides map
|
|
17
|
+
*
|
|
18
|
+
* **PSM Component (2 slots, offset by 4):**
|
|
19
|
+
* - Slot 4: PSM selector `[1, 0, 0, 0]` (ON) or `[0, 0, 0, 0]` (OFF)
|
|
20
|
+
* - Slot 5: PSM public key map `[0, 0, 0, 0] => PSM_COMMITMENT`
|
|
21
|
+
*/
|
|
22
|
+
export declare class MultisigAccount {
|
|
23
|
+
/**
|
|
24
|
+
* The underlying Miden account (from SDK).
|
|
25
|
+
*/
|
|
26
|
+
readonly account: unknown;
|
|
27
|
+
/**
|
|
28
|
+
* The account ID as hex string.
|
|
29
|
+
*/
|
|
30
|
+
readonly id: string;
|
|
31
|
+
/**
|
|
32
|
+
* The PSM server endpoint for this account.
|
|
33
|
+
*/
|
|
34
|
+
readonly psmEndpoint: string;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration values extracted from storage.
|
|
37
|
+
*/
|
|
38
|
+
private readonly _threshold;
|
|
39
|
+
private readonly _numSigners;
|
|
40
|
+
private readonly _cosignerCommitments;
|
|
41
|
+
private readonly _psmEnabled;
|
|
42
|
+
private readonly _psmCommitment;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a MultisigAccount wrapper.
|
|
45
|
+
*
|
|
46
|
+
* @param account - The underlying Miden account
|
|
47
|
+
* @param id - The account ID
|
|
48
|
+
* @param psmEndpoint - The PSM server endpoint
|
|
49
|
+
* @param config - Pre-extracted configuration
|
|
50
|
+
*/
|
|
51
|
+
constructor(account: unknown, id: string, psmEndpoint: string, config: {
|
|
52
|
+
threshold: number;
|
|
53
|
+
numSigners: number;
|
|
54
|
+
cosignerCommitments: string[];
|
|
55
|
+
psmEnabled: boolean;
|
|
56
|
+
psmCommitment: string;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* The number of signatures required to authorize a transaction.
|
|
60
|
+
*/
|
|
61
|
+
get threshold(): number;
|
|
62
|
+
/**
|
|
63
|
+
* The number of cosigners.
|
|
64
|
+
*/
|
|
65
|
+
get numSigners(): number;
|
|
66
|
+
/**
|
|
67
|
+
* The public key commitments of all cosigners.
|
|
68
|
+
*/
|
|
69
|
+
get cosignerCommitments(): readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
* Whether PSM verification is enabled.
|
|
72
|
+
*/
|
|
73
|
+
get psmEnabled(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The PSM server's public key commitment.
|
|
76
|
+
*/
|
|
77
|
+
get psmCommitment(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a commitment belongs to a cosigner of this account.
|
|
80
|
+
*
|
|
81
|
+
* @param commitment - The commitment to check (hex string)
|
|
82
|
+
* @returns True if the commitment is a cosigner
|
|
83
|
+
*/
|
|
84
|
+
isCosigner(commitment: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a MultisigAccount from a newly created account and config.
|
|
87
|
+
*
|
|
88
|
+
* @param account - The created Miden account
|
|
89
|
+
* @param id - The account ID
|
|
90
|
+
* @param psmEndpoint - The PSM server endpoint
|
|
91
|
+
* @param config - The multisig configuration used to create the account
|
|
92
|
+
*/
|
|
93
|
+
static fromConfig(account: unknown, id: string, psmEndpoint: string, config: {
|
|
94
|
+
threshold: number;
|
|
95
|
+
signerCommitments: string[];
|
|
96
|
+
psmCommitment: string;
|
|
97
|
+
psmEnabled?: boolean;
|
|
98
|
+
}): MultisigAccount;
|
|
99
|
+
/**
|
|
100
|
+
* Serializes the account configuration to JSON.
|
|
101
|
+
*/
|
|
102
|
+
toJSON(): object;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAExC;;;;;;;OAOG;gBAED,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,mBAAmB,EAAE,MAAM,EAAE,CAAC;QAC9B,UAAU,EAAE,OAAO,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;KACvB;IAYH;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,IAAI,mBAAmB,IAAI,SAAS,MAAM,EAAE,CAE3C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAOvC;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CACf,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,EAAE,CAAC;QAC5B,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,GACA,eAAe;IAUlB;;OAEG;IACH,MAAM,IAAI,MAAM;CAWjB"}
|
package/dist/account.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MultisigAccount wrapper class.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed wrapper around Miden accounts with multisig + PSM configuration.
|
|
5
|
+
* Mirrors the Rust MultisigAccount struct from miden-multisig-client.
|
|
6
|
+
*/
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// MultisigAccount Class
|
|
9
|
+
// =============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Wrapper around a Miden account with multisig + PSM configuration.
|
|
12
|
+
*
|
|
13
|
+
* Provides typed accessors for storage slots following the layout:
|
|
14
|
+
*
|
|
15
|
+
* **Multisig Component (4 slots):**
|
|
16
|
+
* - Slot 0: Threshold config `[threshold, num_signers, 0, 0]`
|
|
17
|
+
* - Slot 1: Signer public keys map `[index, 0, 0, 0] => COMMITMENT`
|
|
18
|
+
* - Slot 2: Executed transactions map (for replay protection)
|
|
19
|
+
* - Slot 3: Procedure threshold overrides map
|
|
20
|
+
*
|
|
21
|
+
* **PSM Component (2 slots, offset by 4):**
|
|
22
|
+
* - Slot 4: PSM selector `[1, 0, 0, 0]` (ON) or `[0, 0, 0, 0]` (OFF)
|
|
23
|
+
* - Slot 5: PSM public key map `[0, 0, 0, 0] => PSM_COMMITMENT`
|
|
24
|
+
*/
|
|
25
|
+
export class MultisigAccount {
|
|
26
|
+
/**
|
|
27
|
+
* The underlying Miden account (from SDK).
|
|
28
|
+
*/
|
|
29
|
+
account;
|
|
30
|
+
/**
|
|
31
|
+
* The account ID as hex string.
|
|
32
|
+
*/
|
|
33
|
+
id;
|
|
34
|
+
/**
|
|
35
|
+
* The PSM server endpoint for this account.
|
|
36
|
+
*/
|
|
37
|
+
psmEndpoint;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration values extracted from storage.
|
|
40
|
+
*/
|
|
41
|
+
_threshold;
|
|
42
|
+
_numSigners;
|
|
43
|
+
_cosignerCommitments;
|
|
44
|
+
_psmEnabled;
|
|
45
|
+
_psmCommitment;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a MultisigAccount wrapper.
|
|
48
|
+
*
|
|
49
|
+
* @param account - The underlying Miden account
|
|
50
|
+
* @param id - The account ID
|
|
51
|
+
* @param psmEndpoint - The PSM server endpoint
|
|
52
|
+
* @param config - Pre-extracted configuration
|
|
53
|
+
*/
|
|
54
|
+
constructor(account, id, psmEndpoint, config) {
|
|
55
|
+
this.account = account;
|
|
56
|
+
this.id = id;
|
|
57
|
+
this.psmEndpoint = psmEndpoint;
|
|
58
|
+
this._threshold = config.threshold;
|
|
59
|
+
this._numSigners = config.numSigners;
|
|
60
|
+
this._cosignerCommitments = config.cosignerCommitments;
|
|
61
|
+
this._psmEnabled = config.psmEnabled;
|
|
62
|
+
this._psmCommitment = config.psmCommitment;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The number of signatures required to authorize a transaction.
|
|
66
|
+
*/
|
|
67
|
+
get threshold() {
|
|
68
|
+
return this._threshold;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The number of cosigners.
|
|
72
|
+
*/
|
|
73
|
+
get numSigners() {
|
|
74
|
+
return this._numSigners;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The public key commitments of all cosigners.
|
|
78
|
+
*/
|
|
79
|
+
get cosignerCommitments() {
|
|
80
|
+
return this._cosignerCommitments;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether PSM verification is enabled.
|
|
84
|
+
*/
|
|
85
|
+
get psmEnabled() {
|
|
86
|
+
return this._psmEnabled;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The PSM server's public key commitment.
|
|
90
|
+
*/
|
|
91
|
+
get psmCommitment() {
|
|
92
|
+
return this._psmCommitment;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Checks if a commitment belongs to a cosigner of this account.
|
|
96
|
+
*
|
|
97
|
+
* @param commitment - The commitment to check (hex string)
|
|
98
|
+
* @returns True if the commitment is a cosigner
|
|
99
|
+
*/
|
|
100
|
+
isCosigner(commitment) {
|
|
101
|
+
const normalizedCommitment = commitment.toLowerCase().replace(/^0x/, '');
|
|
102
|
+
return this._cosignerCommitments.some((c) => c.toLowerCase().replace(/^0x/, '') === normalizedCommitment);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a MultisigAccount from a newly created account and config.
|
|
106
|
+
*
|
|
107
|
+
* @param account - The created Miden account
|
|
108
|
+
* @param id - The account ID
|
|
109
|
+
* @param psmEndpoint - The PSM server endpoint
|
|
110
|
+
* @param config - The multisig configuration used to create the account
|
|
111
|
+
*/
|
|
112
|
+
static fromConfig(account, id, psmEndpoint, config) {
|
|
113
|
+
return new MultisigAccount(account, id, psmEndpoint, {
|
|
114
|
+
threshold: config.threshold,
|
|
115
|
+
numSigners: config.signerCommitments.length,
|
|
116
|
+
cosignerCommitments: [...config.signerCommitments],
|
|
117
|
+
psmEnabled: config.psmEnabled !== false,
|
|
118
|
+
psmCommitment: config.psmCommitment,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Serializes the account configuration to JSON.
|
|
123
|
+
*/
|
|
124
|
+
toJSON() {
|
|
125
|
+
return {
|
|
126
|
+
id: this.id,
|
|
127
|
+
psmEndpoint: this.psmEndpoint,
|
|
128
|
+
threshold: this._threshold,
|
|
129
|
+
numSigners: this._numSigners,
|
|
130
|
+
cosignerCommitments: this._cosignerCommitments,
|
|
131
|
+
psmEnabled: this._psmEnabled,
|
|
132
|
+
psmCommitment: this._psmCommitment,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,eAAe;IAC1B;;OAEG;IACM,OAAO,CAAU;IAE1B;;OAEG;IACM,EAAE,CAAS;IAEpB;;OAEG;IACM,WAAW,CAAS;IAE7B;;OAEG;IACc,UAAU,CAAS;IACnB,WAA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AK,oBAAoB,CACnE,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CACf,OAAgB,EAChB,EAAU,EACV,WAAmB,EACnB,MAKC;QAED,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE;YACnD,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,UAAU,EAAE,MAAM,CAAC,iBAAiB,CAAC,MAAM;YAC3C,mBAAmB,EAAE,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC;YAClD,UAAU,EAAE,MAAM,CAAC,UAAU,KAAK,KAAK;YACvC,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,mBAAmB,EAAE,IAAI,CAAC,oBAAoB;YAC9C,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,aAAa,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder pattern for constructing MultisigClient instances.
|
|
3
|
+
*
|
|
4
|
+
* This mirrors the Rust MultisigClientBuilder pattern, providing a fluent API
|
|
5
|
+
* for client construction.
|
|
6
|
+
*/
|
|
7
|
+
import { MultisigClient } from './client.js';
|
|
8
|
+
import type { Signer } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Builder for constructing MultisigClient instances.
|
|
11
|
+
*
|
|
12
|
+
* Provides a fluent API for configuring and creating clients.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const client = await MultisigClientBuilder.create()
|
|
17
|
+
* .psmEndpoint('http://localhost:8080')
|
|
18
|
+
* .withSigner(signer)
|
|
19
|
+
* .build();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class MultisigClientBuilder {
|
|
23
|
+
private _psmEndpoint;
|
|
24
|
+
private _signer;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new builder instance.
|
|
27
|
+
*/
|
|
28
|
+
static create(): MultisigClientBuilder;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the PSM server endpoint.
|
|
31
|
+
*
|
|
32
|
+
* @param endpoint - The PSM server URL (e.g., 'http://localhost:8080')
|
|
33
|
+
*/
|
|
34
|
+
psmEndpoint(endpoint: string): this;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the signer.
|
|
37
|
+
*
|
|
38
|
+
* @param signer - A Signer instance (created via createSignerFromSecretKey)
|
|
39
|
+
*/
|
|
40
|
+
withSigner(signer: Signer): this;
|
|
41
|
+
/**
|
|
42
|
+
* Builds and returns the MultisigClient.
|
|
43
|
+
*
|
|
44
|
+
* @throws Error if required configuration is missing
|
|
45
|
+
*/
|
|
46
|
+
build(): MultisigClient;
|
|
47
|
+
/**
|
|
48
|
+
* Builds the client asynchronously.
|
|
49
|
+
*
|
|
50
|
+
* Currently just wraps build(), but allows for future async initialization.
|
|
51
|
+
*/
|
|
52
|
+
buildAsync(): Promise<MultisigClient>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAA6B,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAMzC;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,OAAO,CAAuB;IAEtC;;OAEG;IACH,MAAM,CAAC,MAAM,IAAI,qBAAqB;IAItC;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKnC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKhC;;;;OAIG;IACH,KAAK,IAAI,cAAc;IAgBvB;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;CAG5C"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder pattern for constructing MultisigClient instances.
|
|
3
|
+
*
|
|
4
|
+
* This mirrors the Rust MultisigClientBuilder pattern, providing a fluent API
|
|
5
|
+
* for client construction.
|
|
6
|
+
*/
|
|
7
|
+
import { MultisigClient } from './client.js';
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Builder
|
|
10
|
+
// =============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Builder for constructing MultisigClient instances.
|
|
13
|
+
*
|
|
14
|
+
* Provides a fluent API for configuring and creating clients.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const client = await MultisigClientBuilder.create()
|
|
19
|
+
* .psmEndpoint('http://localhost:8080')
|
|
20
|
+
* .withSigner(signer)
|
|
21
|
+
* .build();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class MultisigClientBuilder {
|
|
25
|
+
_psmEndpoint = null;
|
|
26
|
+
_signer = null;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new builder instance.
|
|
29
|
+
*/
|
|
30
|
+
static create() {
|
|
31
|
+
return new MultisigClientBuilder();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the PSM server endpoint.
|
|
35
|
+
*
|
|
36
|
+
* @param endpoint - The PSM server URL (e.g., 'http://localhost:8080')
|
|
37
|
+
*/
|
|
38
|
+
psmEndpoint(endpoint) {
|
|
39
|
+
this._psmEndpoint = endpoint;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets the signer.
|
|
44
|
+
*
|
|
45
|
+
* @param signer - A Signer instance (created via createSignerFromSecretKey)
|
|
46
|
+
*/
|
|
47
|
+
withSigner(signer) {
|
|
48
|
+
this._signer = signer;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds and returns the MultisigClient.
|
|
53
|
+
*
|
|
54
|
+
* @throws Error if required configuration is missing
|
|
55
|
+
*/
|
|
56
|
+
build() {
|
|
57
|
+
if (!this._psmEndpoint) {
|
|
58
|
+
throw new Error('PSM endpoint is required. Call psmEndpoint() first.');
|
|
59
|
+
}
|
|
60
|
+
if (!this._signer) {
|
|
61
|
+
throw new Error('Signer is required. Call withSigner() first.');
|
|
62
|
+
}
|
|
63
|
+
const config = {
|
|
64
|
+
psmEndpoint: this._psmEndpoint,
|
|
65
|
+
signer: this._signer,
|
|
66
|
+
};
|
|
67
|
+
return new MultisigClient(config);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Builds the client asynchronously.
|
|
71
|
+
*
|
|
72
|
+
* Currently just wraps build(), but allows for future async initialization.
|
|
73
|
+
*/
|
|
74
|
+
async buildAsync() {
|
|
75
|
+
return this.build();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAA6B,MAAM,aAAa,CAAC;AAGxE,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAqB;IACxB,YAAY,GAAkB,IAAI,CAAC;IACnC,OAAO,GAAkB,IAAI,CAAC;IAEtC;;OAEG;IACH,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,qBAAqB,EAAE,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,QAAgB;QAC1B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,MAAc;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,MAAM,GAAyB;YACnC,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC;QAEF,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MultisigClient - Factory for creating and loading multisig accounts.
|
|
3
|
+
*
|
|
4
|
+
* This is the main entry point for the multisig SDK. It provides methods
|
|
5
|
+
* to create new multisig accounts and load existing ones.
|
|
6
|
+
*/
|
|
7
|
+
import { type WebClient } from '@demox-labs/miden-sdk';
|
|
8
|
+
import { PsmHttpClient } from '@openzeppelin/psm-client';
|
|
9
|
+
import { Multisig } from './multisig.js';
|
|
10
|
+
import type { MultisigConfig, Signer } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for MultisigClient.
|
|
13
|
+
*/
|
|
14
|
+
export interface MultisigClientConfig {
|
|
15
|
+
/** PSM server endpoint */
|
|
16
|
+
psmEndpoint?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Client for creating and loading multisig accounts.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { MultisigClient, FalconSigner } from '@openzeppelin/miden-multisig-client';
|
|
24
|
+
* import { WebClient, SecretKey } from '@demox-labs/miden-sdk';
|
|
25
|
+
*
|
|
26
|
+
* // Initialize
|
|
27
|
+
* const webClient = await WebClient.createClient('https://rpc.testnet.miden.io:443');
|
|
28
|
+
* const secretKey = SecretKey.rpoFalconWithRNG(seed);
|
|
29
|
+
* const signer = new FalconSigner(secretKey);
|
|
30
|
+
*
|
|
31
|
+
* // Create client
|
|
32
|
+
* const client = new MultisigClient(webClient, { psmEndpoint: 'http://localhost:3000' });
|
|
33
|
+
*
|
|
34
|
+
* // Get PSM pubkey for config
|
|
35
|
+
* const psmCommitment = await client.psmClient.getPubkey();
|
|
36
|
+
*
|
|
37
|
+
* // Create multisig
|
|
38
|
+
* const config = { threshold: 2, signerCommitments: [...], psmCommitment };
|
|
39
|
+
* const multisig = await client.create(config, signer);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class MultisigClient {
|
|
43
|
+
private readonly webClient;
|
|
44
|
+
private _psmClient;
|
|
45
|
+
constructor(webClient: WebClient, config?: MultisigClientConfig);
|
|
46
|
+
/**
|
|
47
|
+
* Change the PSM endpoint.
|
|
48
|
+
*
|
|
49
|
+
* @param endpoint - The new PSM server endpoint URL
|
|
50
|
+
*/
|
|
51
|
+
setPsmEndpoint(endpoint: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Access the internal PSM client.
|
|
54
|
+
*/
|
|
55
|
+
get psmClient(): PsmHttpClient;
|
|
56
|
+
/**
|
|
57
|
+
* Create a new multisig account.
|
|
58
|
+
*
|
|
59
|
+
* @param config - Multisig configuration (threshold, signers, PSM commitment)
|
|
60
|
+
* @param signer - The signer for this client (one of the cosigners)
|
|
61
|
+
* @returns A Multisig instance wrapping the created account
|
|
62
|
+
*/
|
|
63
|
+
create(config: MultisigConfig, signer: Signer): Promise<Multisig>;
|
|
64
|
+
/**
|
|
65
|
+
* Load an existing multisig account from PSM.
|
|
66
|
+
*
|
|
67
|
+
* @param accountId - The account ID to load
|
|
68
|
+
* @param signer - The signer for this client
|
|
69
|
+
* @returns A Multisig instance for the loaded account
|
|
70
|
+
*/
|
|
71
|
+
load(accountId: string, signer: Signer): Promise<Multisig>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAsB,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,UAAU,CAAgB;gBAEtB,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,oBAAyB;IAKnE;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAItC;;OAEG;IACH,IAAI,SAAS,IAAI,aAAa,CAE7B;IAED;;;;;;OAMG;IACG,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQvE;;;;;;OAMG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAmCjE"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MultisigClient - Factory for creating and loading multisig accounts.
|
|
3
|
+
*
|
|
4
|
+
* This is the main entry point for the multisig SDK. It provides methods
|
|
5
|
+
* to create new multisig accounts and load existing ones.
|
|
6
|
+
*/
|
|
7
|
+
import { Account, AccountId } from '@demox-labs/miden-sdk';
|
|
8
|
+
import { PsmHttpClient } from '@openzeppelin/psm-client';
|
|
9
|
+
import { Multisig } from './multisig.js';
|
|
10
|
+
import { createMultisigAccount } from './account/index.js';
|
|
11
|
+
import { AccountInspector } from './inspector.js';
|
|
12
|
+
/**
|
|
13
|
+
* Client for creating and loading multisig accounts.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { MultisigClient, FalconSigner } from '@openzeppelin/miden-multisig-client';
|
|
18
|
+
* import { WebClient, SecretKey } from '@demox-labs/miden-sdk';
|
|
19
|
+
*
|
|
20
|
+
* // Initialize
|
|
21
|
+
* const webClient = await WebClient.createClient('https://rpc.testnet.miden.io:443');
|
|
22
|
+
* const secretKey = SecretKey.rpoFalconWithRNG(seed);
|
|
23
|
+
* const signer = new FalconSigner(secretKey);
|
|
24
|
+
*
|
|
25
|
+
* // Create client
|
|
26
|
+
* const client = new MultisigClient(webClient, { psmEndpoint: 'http://localhost:3000' });
|
|
27
|
+
*
|
|
28
|
+
* // Get PSM pubkey for config
|
|
29
|
+
* const psmCommitment = await client.psmClient.getPubkey();
|
|
30
|
+
*
|
|
31
|
+
* // Create multisig
|
|
32
|
+
* const config = { threshold: 2, signerCommitments: [...], psmCommitment };
|
|
33
|
+
* const multisig = await client.create(config, signer);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class MultisigClient {
|
|
37
|
+
webClient;
|
|
38
|
+
_psmClient;
|
|
39
|
+
constructor(webClient, config = {}) {
|
|
40
|
+
this.webClient = webClient;
|
|
41
|
+
this._psmClient = new PsmHttpClient(config.psmEndpoint ?? 'http://localhost:3000');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Change the PSM endpoint.
|
|
45
|
+
*
|
|
46
|
+
* @param endpoint - The new PSM server endpoint URL
|
|
47
|
+
*/
|
|
48
|
+
setPsmEndpoint(endpoint) {
|
|
49
|
+
this._psmClient = new PsmHttpClient(endpoint);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Access the internal PSM client.
|
|
53
|
+
*/
|
|
54
|
+
get psmClient() {
|
|
55
|
+
return this._psmClient;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a new multisig account.
|
|
59
|
+
*
|
|
60
|
+
* @param config - Multisig configuration (threshold, signers, PSM commitment)
|
|
61
|
+
* @param signer - The signer for this client (one of the cosigners)
|
|
62
|
+
* @returns A Multisig instance wrapping the created account
|
|
63
|
+
*/
|
|
64
|
+
async create(config, signer) {
|
|
65
|
+
this._psmClient.setSigner(signer);
|
|
66
|
+
const { account } = await createMultisigAccount(this.webClient, config);
|
|
67
|
+
return new Multisig(account, config, this._psmClient, signer, this.webClient);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Load an existing multisig account from PSM.
|
|
71
|
+
*
|
|
72
|
+
* @param accountId - The account ID to load
|
|
73
|
+
* @param signer - The signer for this client
|
|
74
|
+
* @returns A Multisig instance for the loaded account
|
|
75
|
+
*/
|
|
76
|
+
async load(accountId, signer) {
|
|
77
|
+
this._psmClient.setSigner(signer);
|
|
78
|
+
const stateResponse = await this._psmClient.getState(accountId);
|
|
79
|
+
const accountBase64 = stateResponse.stateJson.data;
|
|
80
|
+
if (!accountBase64) {
|
|
81
|
+
throw new Error('No account data found in PSM state');
|
|
82
|
+
}
|
|
83
|
+
const binaryString = atob(accountBase64);
|
|
84
|
+
const accountBytes = new Uint8Array(binaryString.length);
|
|
85
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
86
|
+
accountBytes[i] = binaryString.charCodeAt(i);
|
|
87
|
+
}
|
|
88
|
+
const account = Account.deserialize(accountBytes);
|
|
89
|
+
const detected = AccountInspector.fromAccount(account);
|
|
90
|
+
const config = {
|
|
91
|
+
threshold: detected.threshold,
|
|
92
|
+
signerCommitments: detected.signerCommitments,
|
|
93
|
+
psmCommitment: detected.psmCommitment ?? '',
|
|
94
|
+
psmEnabled: detected.psmEnabled,
|
|
95
|
+
procedureThresholds: Array.from(detected.procedureThresholds.entries()).map(([procedure, threshold]) => ({ procedure, threshold })),
|
|
96
|
+
};
|
|
97
|
+
const existingAccount = await this.webClient.getAccount(AccountId.fromHex(accountId));
|
|
98
|
+
if (!existingAccount) {
|
|
99
|
+
await this.webClient.newAccount(account, true);
|
|
100
|
+
}
|
|
101
|
+
return new Multisig(null, config, this._psmClient, signer, this.webClient, accountId);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkB,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWlD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,cAAc;IACR,SAAS,CAAY;IAC9B,UAAU,CAAgB;IAElC,YAAY,SAAoB,EAAE,SAA+B,EAAE;QACj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