@openzeppelin/miden-multisig-client 0.12.7 → 0.13.0
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 +42 -4
- package/dist/account/builder.d.ts +1 -1
- package/dist/account/builder.d.ts.map +1 -1
- package/dist/account/builder.js +7 -5
- package/dist/account/builder.js.map +1 -1
- package/dist/account/masm.d.ts +3 -3
- package/dist/account/masm.d.ts.map +1 -1
- package/dist/account/masm.js +101 -98
- package/dist/account/masm.js.map +1 -1
- package/dist/account/storage.d.ts +1 -1
- package/dist/account/storage.d.ts.map +1 -1
- package/dist/account/storage.js +17 -7
- package/dist/account/storage.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/client.test.js +4 -4
- package/dist/client.test.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector.d.ts +1 -1
- package/dist/inspector.d.ts.map +1 -1
- package/dist/inspector.js +16 -10
- package/dist/inspector.js.map +1 -1
- package/dist/inspector.test.js +33 -22
- package/dist/inspector.test.js.map +1 -1
- package/dist/multisig/helpers.d.ts +1 -1
- package/dist/multisig/helpers.d.ts.map +1 -1
- package/dist/multisig/helpers.js +1 -1
- package/dist/multisig/helpers.js.map +1 -1
- package/dist/multisig/helpers.test.js +2 -2
- package/dist/multisig/helpers.test.js.map +1 -1
- package/dist/multisig/proposal/execution.d.ts +18 -0
- package/dist/multisig/proposal/execution.d.ts.map +1 -0
- package/dist/multisig/proposal/execution.js +147 -0
- package/dist/multisig/proposal/execution.js.map +1 -0
- package/dist/multisig/proposal/parser.d.ts +17 -0
- package/dist/multisig/proposal/parser.d.ts.map +1 -0
- package/dist/multisig/proposal/parser.js +147 -0
- package/dist/multisig/proposal/parser.js.map +1 -0
- package/dist/multisig/signing.d.ts +5 -0
- package/dist/multisig/signing.d.ts.map +1 -0
- package/dist/multisig/signing.js +14 -0
- package/dist/multisig/signing.js.map +1 -0
- package/dist/multisig.d.ts +9 -13
- package/dist/multisig.d.ts.map +1 -1
- package/dist/multisig.js +109 -337
- package/dist/multisig.js.map +1 -1
- package/dist/multisig.test.js +8 -4
- package/dist/multisig.test.js.map +1 -1
- package/dist/signer.d.ts +2 -20
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +2 -82
- package/dist/signer.js.map +1 -1
- package/dist/signer.test.js +24 -24
- package/dist/signer.test.js.map +1 -1
- package/dist/signers/ecdsa.d.ts +12 -0
- package/dist/signers/ecdsa.d.ts.map +1 -0
- package/dist/signers/ecdsa.js +30 -0
- package/dist/signers/ecdsa.js.map +1 -0
- package/dist/signers/falcon.d.ts +12 -0
- package/dist/signers/falcon.d.ts.map +1 -0
- package/dist/signers/falcon.js +31 -0
- package/dist/signers/falcon.js.map +1 -0
- package/dist/signers/falcon.test.d.ts +2 -0
- package/dist/signers/falcon.test.d.ts.map +1 -0
- package/dist/signers/falcon.test.js +113 -0
- package/dist/signers/falcon.test.js.map +1 -0
- package/dist/signers/index.d.ts +5 -0
- package/dist/signers/index.d.ts.map +1 -0
- package/dist/signers/index.js +5 -0
- package/dist/signers/index.js.map +1 -0
- package/dist/signers/miden-wallet.d.ts +16 -0
- package/dist/signers/miden-wallet.d.ts.map +1 -0
- package/dist/signers/miden-wallet.js +35 -0
- package/dist/signers/miden-wallet.js.map +1 -0
- package/dist/signers/miden-wallet.test.d.ts +2 -0
- package/dist/signers/miden-wallet.test.d.ts.map +1 -0
- package/dist/signers/miden-wallet.test.js +107 -0
- package/dist/signers/miden-wallet.test.js.map +1 -0
- package/dist/signers/para.d.ts +21 -0
- package/dist/signers/para.d.ts.map +1 -0
- package/dist/signers/para.js +43 -0
- package/dist/signers/para.js.map +1 -0
- package/dist/signers/para.test.d.ts +2 -0
- package/dist/signers/para.test.d.ts.map +1 -0
- package/dist/signers/para.test.js +88 -0
- package/dist/signers/para.test.js.map +1 -0
- package/dist/transaction/consumeNotes.d.ts +3 -3
- package/dist/transaction/consumeNotes.d.ts.map +1 -1
- package/dist/transaction/consumeNotes.js +11 -7
- package/dist/transaction/consumeNotes.js.map +1 -1
- package/dist/transaction/options.d.ts +2 -2
- package/dist/transaction/options.d.ts.map +1 -1
- package/dist/transaction/p2id.d.ts +1 -1
- package/dist/transaction/p2id.d.ts.map +1 -1
- package/dist/transaction/p2id.js +5 -5
- package/dist/transaction/p2id.js.map +1 -1
- package/dist/transaction/summary.d.ts +1 -1
- package/dist/transaction/summary.d.ts.map +1 -1
- package/dist/transaction/summary.js +1 -1
- package/dist/transaction/summary.js.map +1 -1
- package/dist/transaction/updatePsm.d.ts +1 -1
- package/dist/transaction/updatePsm.d.ts.map +1 -1
- package/dist/transaction/updatePsm.js +5 -5
- package/dist/transaction/updatePsm.js.map +1 -1
- package/dist/transaction/updateSigners.d.ts +1 -1
- package/dist/transaction/updateSigners.d.ts.map +1 -1
- package/dist/transaction/updateSigners.js +5 -5
- package/dist/transaction/updateSigners.js.map +1 -1
- package/dist/transaction.test.js +1 -1
- package/dist/transaction.test.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/digest.d.ts +6 -0
- package/dist/utils/digest.d.ts.map +1 -0
- package/dist/utils/digest.js +22 -0
- package/dist/utils/digest.js.map +1 -0
- package/dist/utils/ecdsa.d.ts +8 -0
- package/dist/utils/ecdsa.d.ts.map +1 -0
- package/dist/utils/ecdsa.js +60 -0
- package/dist/utils/ecdsa.js.map +1 -0
- package/dist/utils/ecdsa.test.d.ts +2 -0
- package/dist/utils/ecdsa.test.d.ts.map +1 -0
- package/dist/utils/ecdsa.test.js +85 -0
- package/dist/utils/ecdsa.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/key.d.ts +10 -0
- package/dist/utils/key.d.ts.map +1 -0
- package/dist/utils/key.js +38 -0
- package/dist/utils/key.js.map +1 -0
- package/dist/utils/key.test.d.ts +2 -0
- package/dist/utils/key.test.d.ts.map +1 -0
- package/dist/utils/key.test.js +80 -0
- package/dist/utils/key.test.js.map +1 -0
- package/dist/utils/random.d.ts +1 -1
- package/dist/utils/random.d.ts.map +1 -1
- package/dist/utils/random.js +1 -1
- package/dist/utils/random.js.map +1 -1
- package/dist/utils/signature.d.ts +2 -1
- package/dist/utils/signature.d.ts.map +1 -1
- package/dist/utils/signature.js +6 -3
- package/dist/utils/signature.js.map +1 -1
- package/dist/utils/signature.test.js +11 -11
- package/dist/utils/signature.test.js.map +1 -1
- package/dist/utils/word.d.ts +6 -1
- package/dist/utils/word.d.ts.map +1 -1
- package/dist/utils/word.js +11 -0
- package/dist/utils/word.js.map +1 -1
- package/dist/utils/word.test.js +54 -3
- package/dist/utils/word.test.js.map +1 -1
- package/package.json +4 -5
- package/src/account/builder.ts +7 -5
- package/src/account/masm.ts +103 -99
- package/src/account/storage.ts +19 -7
- package/src/client.test.ts +4 -4
- package/src/client.ts +3 -3
- package/src/index.ts +8 -1
- package/src/inspector.test.ts +38 -25
- package/src/inspector.ts +18 -10
- package/src/multisig/helpers.test.ts +2 -2
- package/src/multisig/helpers.ts +2 -1
- package/src/multisig/proposal/execution.ts +320 -0
- package/src/multisig/proposal/parser.ts +191 -0
- package/src/multisig/signing.ts +24 -0
- package/src/multisig.test.ts +8 -4
- package/src/multisig.ts +153 -434
- package/src/signer.ts +2 -95
- package/src/signers/ecdsa.ts +35 -0
- package/src/{signer.test.ts → signers/falcon.test.ts} +29 -33
- package/src/signers/falcon.ts +36 -0
- package/src/signers/index.ts +4 -0
- package/src/signers/miden-wallet.test.ts +119 -0
- package/src/signers/miden-wallet.ts +49 -0
- package/src/signers/para.test.ts +103 -0
- package/src/signers/para.ts +60 -0
- package/src/transaction/consumeNotes.ts +14 -10
- package/src/transaction/options.ts +2 -2
- package/src/transaction/p2id.ts +3 -8
- package/src/transaction/summary.ts +2 -2
- package/src/transaction/updatePsm.ts +5 -6
- package/src/transaction/updateSigners.ts +5 -6
- package/src/transaction.test.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/digest.ts +25 -0
- package/src/utils/ecdsa.test.ts +104 -0
- package/src/utils/ecdsa.ts +77 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/key.test.ts +89 -0
- package/src/utils/key.ts +49 -0
- package/src/utils/random.ts +1 -1
- package/src/utils/signature.test.ts +11 -11
- package/src/utils/signature.ts +10 -3
- package/src/utils/word.test.ts +57 -3
- package/src/utils/word.ts +13 -1
package/src/account/masm.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
|
|
1
2
|
export const MULTISIG_MASM = `# Multi-Signature RPO Falcon 512 Authentication Component
|
|
2
3
|
#
|
|
3
4
|
# This component provides multi-signature authentication for accounts.
|
|
4
5
|
# It integrates with the PSM component for optional PSM signature verification.
|
|
5
6
|
|
|
6
|
-
use miden::active_account
|
|
7
|
-
use miden::native_account
|
|
8
|
-
use miden::auth
|
|
7
|
+
use miden::protocol::active_account
|
|
8
|
+
use miden::protocol::native_account
|
|
9
|
+
use miden::standards::auth
|
|
9
10
|
use openzeppelin::psm
|
|
10
11
|
|
|
11
|
-
# Type definitions for v0.12 syntax
|
|
12
12
|
type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
|
|
13
13
|
|
|
14
14
|
# CONSTANTS
|
|
@@ -17,7 +17,7 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
|
|
|
17
17
|
# Auth Request Constants
|
|
18
18
|
|
|
19
19
|
# The event emitted when a signature is not found for a required signer.
|
|
20
|
-
const AUTH_UNAUTHORIZED_EVENT
|
|
20
|
+
const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
|
|
21
21
|
|
|
22
22
|
# Storage Layout Constants
|
|
23
23
|
#
|
|
@@ -32,29 +32,29 @@ const AUTH_UNAUTHORIZED_EVENT = event("miden::auth::unauthorized")
|
|
|
32
32
|
# number of approvers are stored as:
|
|
33
33
|
# [default_threshold, num_approvers, 0, 0].
|
|
34
34
|
# The threshold is guaranteed to be less than or equal to num_approvers.
|
|
35
|
-
const THRESHOLD_CONFIG_SLOT
|
|
35
|
+
const THRESHOLD_CONFIG_SLOT=word("openzeppelin::multisig::threshold_config")
|
|
36
36
|
|
|
37
37
|
# The slot in this component's storage layout where the public keys map is stored.
|
|
38
38
|
# Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
|
|
39
|
-
const PUBLIC_KEYS_MAP_SLOT
|
|
39
|
+
const PUBLIC_KEYS_MAP_SLOT=word("openzeppelin::multisig::signer_public_keys")
|
|
40
40
|
|
|
41
41
|
# The slot in this component's storage layout where executed transactions are stored.
|
|
42
42
|
# Map entries: transaction_message => [is_executed, 0, 0, 0]
|
|
43
|
-
const EXECUTED_TXS_SLOT
|
|
43
|
+
const EXECUTED_TXS_SLOT=word("openzeppelin::multisig::executed_transactions")
|
|
44
44
|
|
|
45
45
|
# The slot in this component's storage layout where procedure thresholds are stored.
|
|
46
46
|
# Map entries: PROC_ROOT => [proc_threshold, 0, 0, 0]
|
|
47
|
-
const PROC_THRESHOLD_ROOTS_SLOT
|
|
47
|
+
const PROC_THRESHOLD_ROOTS_SLOT=word("openzeppelin::multisig::procedure_thresholds")
|
|
48
48
|
|
|
49
49
|
# Executed Transaction Flag Constant
|
|
50
|
-
const IS_EXECUTED_FLAG
|
|
50
|
+
const IS_EXECUTED_FLAG=[1, 0, 0, 0]
|
|
51
51
|
|
|
52
52
|
# ERRORS
|
|
53
|
-
const ERR_TX_ALREADY_EXECUTED
|
|
53
|
+
const ERR_TX_ALREADY_EXECUTED="failed to approve multisig transaction as it was already executed"
|
|
54
54
|
|
|
55
|
-
const ERR_MALFORMED_MULTISIG_CONFIG
|
|
55
|
+
const ERR_MALFORMED_MULTISIG_CONFIG="number of approvers must be equal to or greater than threshold"
|
|
56
56
|
|
|
57
|
-
const ERR_ZERO_IN_MULTISIG_CONFIG
|
|
57
|
+
const ERR_ZERO_IN_MULTISIG_CONFIG="number of approvers or threshold must not be zero"
|
|
58
58
|
|
|
59
59
|
# MULTISIG PROCEDURES
|
|
60
60
|
# =================================================================================================
|
|
@@ -73,14 +73,14 @@ proc assert_new_tx(msg: BeWord)
|
|
|
73
73
|
swapw
|
|
74
74
|
# => [MSG, IS_EXECUTED_FLAG]
|
|
75
75
|
|
|
76
|
-
push.EXECUTED_TXS_SLOT
|
|
77
|
-
# => [
|
|
76
|
+
push.EXECUTED_TXS_SLOT[0..2]
|
|
77
|
+
# => [txs_slot_prefix, txs_slot_suffix, MSG, IS_EXECUTED_FLAG]
|
|
78
78
|
|
|
79
79
|
# Set the key value pair in the map to mark transaction as executed
|
|
80
80
|
exec.native_account::set_map_item
|
|
81
|
-
# => [
|
|
81
|
+
# => [[0, 0, 0, is_executed]]
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
drop drop drop
|
|
84
84
|
# => [is_executed]
|
|
85
85
|
|
|
86
86
|
assertz.err=ERR_TX_ALREADY_EXECUTED
|
|
@@ -119,13 +119,13 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
|
|
|
119
119
|
padw swapw
|
|
120
120
|
# => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
|
|
121
121
|
|
|
122
|
-
push.PUBLIC_KEYS_MAP_SLOT
|
|
123
|
-
# => [
|
|
122
|
+
push.PUBLIC_KEYS_MAP_SLOT[0..2]
|
|
123
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
|
|
124
124
|
|
|
125
125
|
exec.native_account::set_map_item
|
|
126
|
-
# => [
|
|
126
|
+
# => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
|
|
127
127
|
|
|
128
|
-
dropw
|
|
128
|
+
dropw
|
|
129
129
|
# => [i-1, new_num_of_approvers]
|
|
130
130
|
|
|
131
131
|
dup.1 dup.1
|
|
@@ -155,7 +155,8 @@ end
|
|
|
155
155
|
#! Locals:
|
|
156
156
|
#! 0: new_num_of_approvers
|
|
157
157
|
#! 1: init_num_of_approvers
|
|
158
|
-
|
|
158
|
+
@locals(2)
|
|
159
|
+
pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
|
|
159
160
|
adv.push_mapval
|
|
160
161
|
# => [MULTISIG_CONFIG_HASH, pad(12)]
|
|
161
162
|
|
|
@@ -182,8 +183,8 @@ pub proc update_signers_and_threshold.2(multisig_config_hash: BeWord)
|
|
|
182
183
|
eq.0 assertz.err=ERR_ZERO_IN_MULTISIG_CONFIG
|
|
183
184
|
# => [MULTISIG_CONFIG, pad(12)]
|
|
184
185
|
|
|
185
|
-
push.THRESHOLD_CONFIG_SLOT
|
|
186
|
-
# => [
|
|
186
|
+
push.THRESHOLD_CONFIG_SLOT[0..2]
|
|
187
|
+
# => [config_slot_prefix, config_slot_suffix, MULTISIG_CONFIG, pad(12)]
|
|
187
188
|
|
|
188
189
|
exec.native_account::set_item
|
|
189
190
|
# => [OLD_THRESHOLD_CONFIG, pad(12)]
|
|
@@ -209,13 +210,13 @@ pub proc update_signers_and_threshold.2(multisig_config_hash: BeWord)
|
|
|
209
210
|
swapw
|
|
210
211
|
# => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
|
|
211
212
|
|
|
212
|
-
push.PUBLIC_KEYS_MAP_SLOT
|
|
213
|
-
# => [
|
|
213
|
+
push.PUBLIC_KEYS_MAP_SLOT[0..2]
|
|
214
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
|
|
214
215
|
|
|
215
216
|
exec.native_account::set_map_item
|
|
216
|
-
# => [
|
|
217
|
+
# => [OLD_VALUE, i-1, pad(12)]
|
|
217
218
|
|
|
218
|
-
dropw
|
|
219
|
+
dropw
|
|
219
220
|
# => [i-1, pad(12)]
|
|
220
221
|
|
|
221
222
|
dup neq.0
|
|
@@ -242,7 +243,8 @@ end
|
|
|
242
243
|
#
|
|
243
244
|
#! Inputs: [default_threshold]
|
|
244
245
|
#! Outputs: [transaction_threshold]
|
|
245
|
-
|
|
246
|
+
@locals(1)
|
|
247
|
+
proc compute_transaction_threshold(default_threshold: u32) -> u32
|
|
246
248
|
# 1. initialize transaction_threshold = 0
|
|
247
249
|
# 2. iterate through all account procedures
|
|
248
250
|
# a. check if the procedure was called during the transaction
|
|
@@ -281,8 +283,8 @@ proc compute_transaction_threshold.1(default_threshold: u32) -> u32
|
|
|
281
283
|
if.true
|
|
282
284
|
# => [PROC_ROOT, num_procedures-1, transaction_threshold]
|
|
283
285
|
|
|
284
|
-
push.PROC_THRESHOLD_ROOTS_SLOT
|
|
285
|
-
# => [
|
|
286
|
+
push.PROC_THRESHOLD_ROOTS_SLOT[0..2]
|
|
287
|
+
# => [PROC_THRESHOLD_ROOTS_SLOT_prefix, PROC_THRESHOLD_ROOTS_SLOT_suffix, PROC_ROOT, num_procedures-1, transaction_threshold]
|
|
286
288
|
|
|
287
289
|
# 2b. get the override proc_threshold of that procedure
|
|
288
290
|
# if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
|
|
@@ -359,7 +361,8 @@ end
|
|
|
359
361
|
#! - PSM signature verification fails (if PSM is enabled).
|
|
360
362
|
#!
|
|
361
363
|
#! Invocation: call
|
|
362
|
-
|
|
364
|
+
@locals(1)
|
|
365
|
+
pub proc auth_tx_rpo_falcon512_multisig(salt: BeWord)
|
|
363
366
|
exec.native_account::incr_nonce drop
|
|
364
367
|
# => [SALT]
|
|
365
368
|
|
|
@@ -378,8 +381,8 @@ pub proc auth_tx_rpo_falcon512_multisig.1(salt: BeWord)
|
|
|
378
381
|
|
|
379
382
|
# ------ Verifying approver signatures ------
|
|
380
383
|
|
|
381
|
-
push.THRESHOLD_CONFIG_SLOT
|
|
382
|
-
# => [
|
|
384
|
+
push.THRESHOLD_CONFIG_SLOT[0..2]
|
|
385
|
+
# => [config_slot_prefix, config_slot_suffix, TX_SUMMARY_COMMITMENT]
|
|
383
386
|
|
|
384
387
|
exec.active_account::get_initial_item
|
|
385
388
|
# => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
|
|
@@ -390,10 +393,10 @@ pub proc auth_tx_rpo_falcon512_multisig.1(salt: BeWord)
|
|
|
390
393
|
swap movdn.5
|
|
391
394
|
# => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
|
|
392
395
|
|
|
393
|
-
push.PUBLIC_KEYS_MAP_SLOT
|
|
394
|
-
# => [
|
|
396
|
+
push.PUBLIC_KEYS_MAP_SLOT[0..2]
|
|
397
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
|
|
395
398
|
|
|
396
|
-
exec.::miden::auth::
|
|
399
|
+
exec.::miden::standards::auth::falcon512_rpo::verify_signatures
|
|
397
400
|
# => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
|
|
398
401
|
|
|
399
402
|
# ------ Checking threshold is >= num_verified_signatures ------
|
|
@@ -429,12 +432,11 @@ export const MULTISIG_ECDSA_MASM = `# Multi-Signature ECDSA secp256k1 Authentica
|
|
|
429
432
|
# ECDSA secp256k1 (k256/keccak) signatures instead of RPO Falcon 512.
|
|
430
433
|
# It integrates with the PSM component for optional PSM signature verification.
|
|
431
434
|
|
|
432
|
-
use miden::active_account
|
|
433
|
-
use miden::native_account
|
|
434
|
-
use miden::auth
|
|
435
|
+
use miden::protocol::active_account
|
|
436
|
+
use miden::protocol::native_account
|
|
437
|
+
use miden::standards::auth
|
|
435
438
|
use openzeppelin::psm_ecdsa
|
|
436
439
|
|
|
437
|
-
# Type definitions for v0.12 syntax
|
|
438
440
|
type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
|
|
439
441
|
|
|
440
442
|
# CONSTANTS
|
|
@@ -443,7 +445,7 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
|
|
|
443
445
|
# Auth Request Constants
|
|
444
446
|
|
|
445
447
|
# The event emitted when a signature is not found for a required signer.
|
|
446
|
-
const AUTH_UNAUTHORIZED_EVENT
|
|
448
|
+
const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
|
|
447
449
|
|
|
448
450
|
# Storage Layout Constants
|
|
449
451
|
#
|
|
@@ -458,29 +460,29 @@ const AUTH_UNAUTHORIZED_EVENT = event("miden::auth::unauthorized")
|
|
|
458
460
|
# number of approvers are stored as:
|
|
459
461
|
# [default_threshold, num_approvers, 0, 0].
|
|
460
462
|
# The threshold is guaranteed to be less than or equal to num_approvers.
|
|
461
|
-
const THRESHOLD_CONFIG_SLOT
|
|
463
|
+
const THRESHOLD_CONFIG_SLOT=word("openzeppelin::multisig::threshold_config")
|
|
462
464
|
|
|
463
465
|
# The slot in this component's storage layout where the public keys map is stored.
|
|
464
466
|
# Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
|
|
465
|
-
const PUBLIC_KEYS_MAP_SLOT
|
|
467
|
+
const PUBLIC_KEYS_MAP_SLOT=word("openzeppelin::multisig::signer_public_keys")
|
|
466
468
|
|
|
467
469
|
# The slot in this component's storage layout where executed transactions are stored.
|
|
468
470
|
# Map entries: transaction_message => [is_executed, 0, 0, 0]
|
|
469
|
-
const EXECUTED_TXS_SLOT
|
|
471
|
+
const EXECUTED_TXS_SLOT=word("openzeppelin::multisig::executed_transactions")
|
|
470
472
|
|
|
471
473
|
# The slot in this component's storage layout where procedure thresholds are stored.
|
|
472
474
|
# Map entries: PROC_ROOT => [proc_threshold, 0, 0, 0]
|
|
473
|
-
const PROC_THRESHOLD_ROOTS_SLOT
|
|
475
|
+
const PROC_THRESHOLD_ROOTS_SLOT=word("openzeppelin::multisig::procedure_thresholds")
|
|
474
476
|
|
|
475
477
|
# Executed Transaction Flag Constant
|
|
476
|
-
const IS_EXECUTED_FLAG
|
|
478
|
+
const IS_EXECUTED_FLAG=[1, 0, 0, 0]
|
|
477
479
|
|
|
478
480
|
# ERRORS
|
|
479
|
-
const ERR_TX_ALREADY_EXECUTED
|
|
481
|
+
const ERR_TX_ALREADY_EXECUTED="failed to approve multisig transaction as it was already executed"
|
|
480
482
|
|
|
481
|
-
const ERR_MALFORMED_MULTISIG_CONFIG
|
|
483
|
+
const ERR_MALFORMED_MULTISIG_CONFIG="number of approvers must be equal to or greater than threshold"
|
|
482
484
|
|
|
483
|
-
const ERR_ZERO_IN_MULTISIG_CONFIG
|
|
485
|
+
const ERR_ZERO_IN_MULTISIG_CONFIG="number of approvers or threshold must not be zero"
|
|
484
486
|
|
|
485
487
|
# MULTISIG PROCEDURES
|
|
486
488
|
# =================================================================================================
|
|
@@ -499,14 +501,14 @@ proc assert_new_tx(msg: BeWord)
|
|
|
499
501
|
swapw
|
|
500
502
|
# => [MSG, IS_EXECUTED_FLAG]
|
|
501
503
|
|
|
502
|
-
push.EXECUTED_TXS_SLOT
|
|
503
|
-
# => [
|
|
504
|
+
push.EXECUTED_TXS_SLOT[0..2]
|
|
505
|
+
# => [txs_slot_prefix, txs_slot_suffix, MSG, IS_EXECUTED_FLAG]
|
|
504
506
|
|
|
505
507
|
# Set the key value pair in the map to mark transaction as executed
|
|
506
508
|
exec.native_account::set_map_item
|
|
507
|
-
# => [
|
|
509
|
+
# => [[0, 0, 0, is_executed]]
|
|
508
510
|
|
|
509
|
-
|
|
511
|
+
drop drop drop
|
|
510
512
|
# => [is_executed]
|
|
511
513
|
|
|
512
514
|
assertz.err=ERR_TX_ALREADY_EXECUTED
|
|
@@ -545,13 +547,13 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
|
|
|
545
547
|
padw swapw
|
|
546
548
|
# => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
|
|
547
549
|
|
|
548
|
-
push.PUBLIC_KEYS_MAP_SLOT
|
|
549
|
-
# => [
|
|
550
|
+
push.PUBLIC_KEYS_MAP_SLOT[0..2]
|
|
551
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
|
|
550
552
|
|
|
551
553
|
exec.native_account::set_map_item
|
|
552
|
-
# => [
|
|
554
|
+
# => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
|
|
553
555
|
|
|
554
|
-
dropw
|
|
556
|
+
dropw
|
|
555
557
|
# => [i-1, new_num_of_approvers]
|
|
556
558
|
|
|
557
559
|
dup.1 dup.1
|
|
@@ -581,7 +583,8 @@ end
|
|
|
581
583
|
#! Locals:
|
|
582
584
|
#! 0: new_num_of_approvers
|
|
583
585
|
#! 1: init_num_of_approvers
|
|
584
|
-
|
|
586
|
+
@locals(2)
|
|
587
|
+
pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
|
|
585
588
|
adv.push_mapval
|
|
586
589
|
# => [MULTISIG_CONFIG_HASH, pad(12)]
|
|
587
590
|
|
|
@@ -608,8 +611,8 @@ pub proc update_signers_and_threshold.2(multisig_config_hash: BeWord)
|
|
|
608
611
|
eq.0 assertz.err=ERR_ZERO_IN_MULTISIG_CONFIG
|
|
609
612
|
# => [MULTISIG_CONFIG, pad(12)]
|
|
610
613
|
|
|
611
|
-
push.THRESHOLD_CONFIG_SLOT
|
|
612
|
-
# => [
|
|
614
|
+
push.THRESHOLD_CONFIG_SLOT[0..2]
|
|
615
|
+
# => [config_slot_prefix, config_slot_suffix, MULTISIG_CONFIG, pad(12)]
|
|
613
616
|
|
|
614
617
|
exec.native_account::set_item
|
|
615
618
|
# => [OLD_THRESHOLD_CONFIG, pad(12)]
|
|
@@ -635,13 +638,13 @@ pub proc update_signers_and_threshold.2(multisig_config_hash: BeWord)
|
|
|
635
638
|
swapw
|
|
636
639
|
# => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
|
|
637
640
|
|
|
638
|
-
push.PUBLIC_KEYS_MAP_SLOT
|
|
639
|
-
# => [
|
|
641
|
+
push.PUBLIC_KEYS_MAP_SLOT[0..2]
|
|
642
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
|
|
640
643
|
|
|
641
644
|
exec.native_account::set_map_item
|
|
642
|
-
# => [
|
|
645
|
+
# => [OLD_VALUE, i-1, pad(12)]
|
|
643
646
|
|
|
644
|
-
dropw
|
|
647
|
+
dropw
|
|
645
648
|
# => [i-1, pad(12)]
|
|
646
649
|
|
|
647
650
|
dup neq.0
|
|
@@ -668,7 +671,8 @@ end
|
|
|
668
671
|
#
|
|
669
672
|
#! Inputs: [default_threshold]
|
|
670
673
|
#! Outputs: [transaction_threshold]
|
|
671
|
-
|
|
674
|
+
@locals(1)
|
|
675
|
+
proc compute_transaction_threshold(default_threshold: u32) -> u32
|
|
672
676
|
# 1. initialize transaction_threshold = 0
|
|
673
677
|
# 2. iterate through all account procedures
|
|
674
678
|
# a. check if the procedure was called during the transaction
|
|
@@ -707,8 +711,8 @@ proc compute_transaction_threshold.1(default_threshold: u32) -> u32
|
|
|
707
711
|
if.true
|
|
708
712
|
# => [PROC_ROOT, num_procedures-1, transaction_threshold]
|
|
709
713
|
|
|
710
|
-
push.PROC_THRESHOLD_ROOTS_SLOT
|
|
711
|
-
# => [
|
|
714
|
+
push.PROC_THRESHOLD_ROOTS_SLOT[0..2]
|
|
715
|
+
# => [PROC_THRESHOLD_ROOTS_SLOT_prefix, PROC_THRESHOLD_ROOTS_SLOT_suffix, PROC_ROOT, num_procedures-1, transaction_threshold]
|
|
712
716
|
|
|
713
717
|
# 2b. get the override proc_threshold of that procedure
|
|
714
718
|
# if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
|
|
@@ -785,7 +789,8 @@ end
|
|
|
785
789
|
#! - PSM signature verification fails (if PSM is enabled).
|
|
786
790
|
#!
|
|
787
791
|
#! Invocation: call
|
|
788
|
-
|
|
792
|
+
@locals(1)
|
|
793
|
+
pub proc auth_tx_ecdsa_multisig(salt: BeWord)
|
|
789
794
|
exec.native_account::incr_nonce drop
|
|
790
795
|
# => [SALT]
|
|
791
796
|
|
|
@@ -804,8 +809,8 @@ pub proc auth_tx_ecdsa_multisig.1(salt: BeWord)
|
|
|
804
809
|
|
|
805
810
|
# ------ Verifying approver signatures ------
|
|
806
811
|
|
|
807
|
-
push.THRESHOLD_CONFIG_SLOT
|
|
808
|
-
# => [
|
|
812
|
+
push.THRESHOLD_CONFIG_SLOT[0..2]
|
|
813
|
+
# => [config_slot_prefix, config_slot_suffix, TX_SUMMARY_COMMITMENT]
|
|
809
814
|
|
|
810
815
|
exec.active_account::get_initial_item
|
|
811
816
|
# => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
|
|
@@ -816,10 +821,10 @@ pub proc auth_tx_ecdsa_multisig.1(salt: BeWord)
|
|
|
816
821
|
swap movdn.5
|
|
817
822
|
# => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
|
|
818
823
|
|
|
819
|
-
push.PUBLIC_KEYS_MAP_SLOT
|
|
820
|
-
# => [
|
|
824
|
+
push.PUBLIC_KEYS_MAP_SLOT[0..2]
|
|
825
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
|
|
821
826
|
|
|
822
|
-
exec.::miden::auth::ecdsa_k256_keccak::verify_signatures
|
|
827
|
+
exec.::miden::standards::auth::ecdsa_k256_keccak::verify_signatures
|
|
823
828
|
# => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
|
|
824
829
|
|
|
825
830
|
# ------ Checking threshold is >= num_verified_signatures ------
|
|
@@ -854,10 +859,9 @@ export const PSM_MASM = `# Private State Manager (PSM) Authentication Component
|
|
|
854
859
|
# This component provides PSM signature verification for accounts.
|
|
855
860
|
# It can be used standalone or in conjunction with other auth components like multisig.
|
|
856
861
|
|
|
857
|
-
use miden::active_account
|
|
858
|
-
use miden::native_account
|
|
862
|
+
use miden::protocol::active_account
|
|
863
|
+
use miden::protocol::native_account
|
|
859
864
|
|
|
860
|
-
# Type definitions for v0.12 syntax
|
|
861
865
|
type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
|
|
862
866
|
|
|
863
867
|
# IMPORTANT SECURITY NOTES
|
|
@@ -899,22 +903,22 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
|
|
|
899
903
|
# CONSTANTS
|
|
900
904
|
# =================================================================================================
|
|
901
905
|
|
|
902
|
-
# Slot where the PSM selector flag is stored:
|
|
906
|
+
# Slot where the PSM selector flag is stored (using word() for named slot access):
|
|
903
907
|
# - PSM_ON => PSM signature required
|
|
904
908
|
# - PSM_OFF => PSM signature skipped
|
|
905
|
-
const PSM_SELECTOR_SLOT
|
|
909
|
+
const PSM_SELECTOR_SLOT=word("openzeppelin::psm::selector")
|
|
906
910
|
|
|
907
911
|
# Map slot for PSM public key
|
|
908
912
|
# Uses exactly one PSM public key at index [0, 0, 0, 0]
|
|
909
913
|
# [0, 0, 0, 0] => PSM_PUBLIC_KEY
|
|
910
|
-
const PSM_PUBLIC_KEY_MAP_SLOT
|
|
914
|
+
const PSM_PUBLIC_KEY_MAP_SLOT=word("openzeppelin::psm::public_key")
|
|
911
915
|
|
|
912
916
|
# Selector flag values
|
|
913
|
-
const PSM_ON
|
|
914
|
-
const PSM_OFF
|
|
917
|
+
const PSM_ON=[1, 0, 0, 0]
|
|
918
|
+
const PSM_OFF=[0, 0, 0, 0]
|
|
915
919
|
|
|
916
920
|
# The event emitted when a signature is not found for a required signer.
|
|
917
|
-
const AUTH_UNAUTHORIZED_EVENT
|
|
921
|
+
const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
|
|
918
922
|
|
|
919
923
|
# PSM PROCEDURES
|
|
920
924
|
# =================================================================================================
|
|
@@ -927,12 +931,12 @@ const AUTH_UNAUTHORIZED_EVENT = event("miden::auth::unauthorized")
|
|
|
927
931
|
#! Notes:
|
|
928
932
|
#! - Sets PSM_SELECTOR_SLOT to PSM_ON (1)
|
|
929
933
|
#! - After this, transactions will require PSM signature verification
|
|
930
|
-
proc
|
|
934
|
+
proc enable_psm
|
|
931
935
|
push.PSM_ON
|
|
932
936
|
# => [PSM_ON]
|
|
933
937
|
|
|
934
|
-
push.PSM_SELECTOR_SLOT
|
|
935
|
-
# => [
|
|
938
|
+
push.PSM_SELECTOR_SLOT[0..2]
|
|
939
|
+
# => [selector_slot_prefix, selector_slot_suffix, PSM_ON]
|
|
936
940
|
|
|
937
941
|
exec.native_account::set_item
|
|
938
942
|
# => [OLD_ROOT]
|
|
@@ -949,12 +953,12 @@ end
|
|
|
949
953
|
#! Notes:
|
|
950
954
|
#! - Sets PSM_SELECTOR_SLOT to PSM_OFF (0)
|
|
951
955
|
#! - After this, transactions will NOT require PSM signature verification
|
|
952
|
-
proc
|
|
956
|
+
proc disable_psm
|
|
953
957
|
push.PSM_OFF
|
|
954
958
|
# => [PSM_OFF]
|
|
955
959
|
|
|
956
|
-
push.PSM_SELECTOR_SLOT
|
|
957
|
-
# => [
|
|
960
|
+
push.PSM_SELECTOR_SLOT[0..2]
|
|
961
|
+
# => [selector_slot_prefix, selector_slot_suffix, PSM_OFF]
|
|
958
962
|
|
|
959
963
|
exec.native_account::set_item
|
|
960
964
|
# => [OLD_ROOT]
|
|
@@ -984,13 +988,13 @@ pub proc update_psm_public_key
|
|
|
984
988
|
# => [MAP_KEY, PUB_KEY]
|
|
985
989
|
# Note that MAP_KEY is [0, 0, 0, 0] for a single PSM_KEY
|
|
986
990
|
|
|
987
|
-
push.PSM_PUBLIC_KEY_MAP_SLOT
|
|
988
|
-
# => [
|
|
991
|
+
push.PSM_PUBLIC_KEY_MAP_SLOT[0..2]
|
|
992
|
+
# => [pub_key_slot_prefix, pub_key_slot_suffix, MAP_KEY, PUB_KEY]
|
|
989
993
|
|
|
990
994
|
exec.native_account::set_map_item
|
|
991
|
-
# => [
|
|
995
|
+
# => [OLD_MAP_VALUE]
|
|
992
996
|
|
|
993
|
-
dropw
|
|
997
|
+
dropw
|
|
994
998
|
# => []
|
|
995
999
|
end
|
|
996
1000
|
|
|
@@ -1007,8 +1011,8 @@ end
|
|
|
1007
1011
|
#! - MSG is TX_SUMMARY_COMMITMENT provided by auth procedure
|
|
1008
1012
|
#! - If selector is OFF (0), PSM verification is skipped
|
|
1009
1013
|
#! - Selector value is read from initial storage state
|
|
1010
|
-
pub proc verify_psm_signature(msg: BeWord)
|
|
1011
|
-
push.PSM_SELECTOR_SLOT
|
|
1014
|
+
pub proc verify_psm_signature(msg: BeWord) -> BeWord
|
|
1015
|
+
push.PSM_SELECTOR_SLOT[0..2]
|
|
1012
1016
|
exec.active_account::get_item
|
|
1013
1017
|
drop drop drop
|
|
1014
1018
|
# => [selector, MSG]
|
|
@@ -1016,8 +1020,8 @@ pub proc verify_psm_signature(msg: BeWord)
|
|
|
1016
1020
|
push.1 eq
|
|
1017
1021
|
if.true
|
|
1018
1022
|
push.1
|
|
1019
|
-
push.PSM_PUBLIC_KEY_MAP_SLOT
|
|
1020
|
-
exec.::miden::auth::
|
|
1023
|
+
push.PSM_PUBLIC_KEY_MAP_SLOT[0..2]
|
|
1024
|
+
exec.::miden::standards::auth::falcon512_rpo::verify_signatures
|
|
1021
1025
|
push.1 neq
|
|
1022
1026
|
if.true
|
|
1023
1027
|
emit.AUTH_UNAUTHORIZED_EVENT
|
|
@@ -1032,6 +1036,6 @@ end
|
|
|
1032
1036
|
export const PSM_ECDSA_MASM = PSM_MASM
|
|
1033
1037
|
.replaceAll('RPO Falcon 512', 'ECDSA secp256k1')
|
|
1034
1038
|
.replace(
|
|
1035
|
-
'exec.::miden::auth::
|
|
1036
|
-
'exec.::miden::auth::ecdsa_k256_keccak::verify_signatures',
|
|
1039
|
+
'exec.::miden::standards::auth::falcon512_rpo::verify_signatures',
|
|
1040
|
+
'exec.::miden::standards::auth::ecdsa_k256_keccak::verify_signatures',
|
|
1037
1041
|
);
|
package/src/account/storage.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { MultisigConfig } from '../types.js';
|
|
2
|
-
import { StorageSlot, StorageMap, Word } from '@
|
|
2
|
+
import { StorageSlot, StorageMap, Word } from '@miden-sdk/miden-sdk';
|
|
3
3
|
import { normalizeHexWord } from '../utils/encoding.js';
|
|
4
4
|
import { getProcedureRoot } from '../procedures.js';
|
|
5
5
|
|
|
6
|
+
const MULTISIG_SLOT_NAMES = {
|
|
7
|
+
THRESHOLD_CONFIG: 'openzeppelin::multisig::threshold_config',
|
|
8
|
+
SIGNER_PUBLIC_KEYS: 'openzeppelin::multisig::signer_public_keys',
|
|
9
|
+
EXECUTED_TRANSACTIONS: 'openzeppelin::multisig::executed_transactions',
|
|
10
|
+
PROCEDURE_THRESHOLDS: 'openzeppelin::multisig::procedure_thresholds',
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
const PSM_SLOT_NAMES = {
|
|
14
|
+
SELECTOR: 'openzeppelin::psm::selector',
|
|
15
|
+
PUBLIC_KEY: 'openzeppelin::psm::public_key',
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
6
18
|
export class StorageLayoutBuilder {
|
|
7
19
|
buildMultisigSlots(config: MultisigConfig): StorageSlot[] {
|
|
8
20
|
const numSigners = config.signerCommitments.length;
|
|
@@ -14,7 +26,7 @@ export class StorageLayoutBuilder {
|
|
|
14
26
|
0n,
|
|
15
27
|
])
|
|
16
28
|
);
|
|
17
|
-
const slot0 = StorageSlot.fromValue(slot0Word);
|
|
29
|
+
const slot0 = StorageSlot.fromValue(MULTISIG_SLOT_NAMES.THRESHOLD_CONFIG, slot0Word);
|
|
18
30
|
|
|
19
31
|
const signersMap = new StorageMap();
|
|
20
32
|
config.signerCommitments.forEach((commitment, index) => {
|
|
@@ -22,9 +34,9 @@ export class StorageLayoutBuilder {
|
|
|
22
34
|
const value = Word.fromHex(normalizeHexWord(commitment));
|
|
23
35
|
signersMap.insert(key, value);
|
|
24
36
|
});
|
|
25
|
-
const slot1 = StorageSlot.map(signersMap);
|
|
37
|
+
const slot1 = StorageSlot.map(MULTISIG_SLOT_NAMES.SIGNER_PUBLIC_KEYS, signersMap);
|
|
26
38
|
|
|
27
|
-
const slot2 = StorageSlot.map(new StorageMap());
|
|
39
|
+
const slot2 = StorageSlot.map(MULTISIG_SLOT_NAMES.EXECUTED_TRANSACTIONS, new StorageMap());
|
|
28
40
|
|
|
29
41
|
const procThresholdMap = new StorageMap();
|
|
30
42
|
if (config.procedureThresholds) {
|
|
@@ -36,7 +48,7 @@ export class StorageLayoutBuilder {
|
|
|
36
48
|
procThresholdMap.insert(key, value);
|
|
37
49
|
}
|
|
38
50
|
}
|
|
39
|
-
const slot3 = StorageSlot.map(procThresholdMap);
|
|
51
|
+
const slot3 = StorageSlot.map(MULTISIG_SLOT_NAMES.PROCEDURE_THRESHOLDS, procThresholdMap);
|
|
40
52
|
|
|
41
53
|
return [slot0, slot1, slot2, slot3];
|
|
42
54
|
}
|
|
@@ -44,13 +56,13 @@ export class StorageLayoutBuilder {
|
|
|
44
56
|
buildPsmSlots(config: MultisigConfig): StorageSlot[] {
|
|
45
57
|
const selector = config.psmEnabled !== false ? 1n : 0n;
|
|
46
58
|
const selectorWord = new Word(new BigUint64Array([selector, 0n, 0n, 0n]));
|
|
47
|
-
const slot0 = StorageSlot.fromValue(selectorWord);
|
|
59
|
+
const slot0 = StorageSlot.fromValue(PSM_SLOT_NAMES.SELECTOR, selectorWord);
|
|
48
60
|
|
|
49
61
|
const psmKeyMap = new StorageMap();
|
|
50
62
|
const zeroKey = new Word(new BigUint64Array([0n, 0n, 0n, 0n]));
|
|
51
63
|
const psmKey = Word.fromHex(normalizeHexWord(config.psmCommitment));
|
|
52
64
|
psmKeyMap.insert(zeroKey, psmKey);
|
|
53
|
-
const slot1 = StorageSlot.map(psmKeyMap);
|
|
65
|
+
const slot1 = StorageSlot.map(PSM_SLOT_NAMES.PUBLIC_KEY, psmKeyMap);
|
|
54
66
|
|
|
55
67
|
return [slot0, slot1];
|
|
56
68
|
}
|
package/src/client.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { MultisigClient } from './client.js';
|
|
|
3
3
|
import type { Signer } from './types.js';
|
|
4
4
|
|
|
5
5
|
// Mock the Miden SDK
|
|
6
|
-
vi.mock('@
|
|
6
|
+
vi.mock('@miden-sdk/miden-sdk', () => ({
|
|
7
7
|
AccountId: {
|
|
8
8
|
fromHex: vi.fn((hex: string) => ({ toString: () => hex })),
|
|
9
9
|
},
|
|
@@ -76,8 +76,8 @@ describe('MultisigClient', () => {
|
|
|
76
76
|
scheme: 'falcon',
|
|
77
77
|
commitment: '0x' + '1'.repeat(64),
|
|
78
78
|
publicKey: '0x' + '2'.repeat(64),
|
|
79
|
-
signAccountIdWithTimestamp: vi.fn().
|
|
80
|
-
signCommitment: vi.fn().
|
|
79
|
+
signAccountIdWithTimestamp: vi.fn().mockResolvedValue('0x' + 'a'.repeat(128)),
|
|
80
|
+
signCommitment: vi.fn().mockResolvedValue('0x' + 'b'.repeat(128)),
|
|
81
81
|
};
|
|
82
82
|
});
|
|
83
83
|
|
|
@@ -157,7 +157,7 @@ describe('MultisigClient', () => {
|
|
|
157
157
|
expect(multisig.threshold).toBe(2);
|
|
158
158
|
expect(multisig.signerCommitments).toEqual(['0x' + 'a'.repeat(64), '0x' + 'b'.repeat(64)]);
|
|
159
159
|
expect(multisig.psmCommitment).toBe('0x' + 'c'.repeat(64));
|
|
160
|
-
expect(multisig.account).toBeNull();
|
|
160
|
+
expect(multisig.account).not.toBeNull();
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
it('should throw if account not found on PSM', async () => {
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type WebClient, Account, AccountId } from '@
|
|
1
|
+
import { type WebClient, Account, AccountId } from '@miden-sdk/miden-sdk';
|
|
2
2
|
import { PsmHttpClient, type SignatureScheme } from '@openzeppelin/psm-client';
|
|
3
3
|
import { Multisig } from './multisig.js';
|
|
4
4
|
import { createMultisigAccount } from './account/index.js';
|
|
@@ -72,9 +72,9 @@ export class MultisigClient {
|
|
|
72
72
|
|
|
73
73
|
const existingAccount = await this.webClient.getAccount(AccountId.fromHex(accountId));
|
|
74
74
|
if (!existingAccount) {
|
|
75
|
-
|
|
75
|
+
await this.webClient.newAccount(account, true);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
return new Multisig(
|
|
78
|
+
return new Multisig(account, config, this._psmClient, signer, this.webClient, accountId);
|
|
79
79
|
}
|
|
80
80
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,14 @@ export {
|
|
|
11
11
|
|
|
12
12
|
export { PsmHttpClient, PsmHttpError } from '@openzeppelin/psm-client';
|
|
13
13
|
|
|
14
|
-
export { FalconSigner, EcdsaSigner } from './
|
|
14
|
+
export { FalconSigner, EcdsaSigner, ParaSigner, MidenWalletSigner } from './signers/index.js';
|
|
15
|
+
export type { ParaSigningContext } from './signers/para.js';
|
|
16
|
+
export type { WalletSigningContext } from './signers/miden-wallet.js';
|
|
17
|
+
export { AuthDigest } from './utils/digest.js';
|
|
18
|
+
export { EcdsaFormat } from './utils/ecdsa.js';
|
|
19
|
+
export { PublicKeyFormat } from './utils/key.js';
|
|
20
|
+
export { wordToBytes } from './utils/word.js';
|
|
21
|
+
export { tryComputeEcdsaCommitmentHex, tryComputeCommitmentHex } from './utils/signature.js';
|
|
15
22
|
|
|
16
23
|
export {
|
|
17
24
|
createMultisigAccount,
|