@openzeppelin/miden-multisig-client 0.12.6 → 0.12.7

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.
Files changed (89) hide show
  1. package/README.md +70 -75
  2. package/dist/account/builder.d.ts +0 -18
  3. package/dist/account/builder.d.ts.map +1 -1
  4. package/dist/account/builder.js +16 -24
  5. package/dist/account/builder.js.map +1 -1
  6. package/dist/account/masm.d.ts +2 -0
  7. package/dist/account/masm.d.ts.map +1 -1
  8. package/dist/account/masm.js +428 -1
  9. package/dist/account/masm.js.map +1 -1
  10. package/dist/account/storage.d.ts.map +1 -1
  11. package/dist/account/storage.js +5 -6
  12. package/dist/account/storage.js.map +1 -1
  13. package/dist/client.d.ts +5 -57
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +7 -53
  16. package/dist/client.js.map +1 -1
  17. package/dist/client.test.js +28 -0
  18. package/dist/client.test.js.map +1 -1
  19. package/dist/index.d.ts +3 -46
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +2 -45
  22. package/dist/index.js.map +1 -1
  23. package/dist/inspector.d.ts +4 -30
  24. package/dist/inspector.d.ts.map +1 -1
  25. package/dist/inspector.js +13 -43
  26. package/dist/inspector.js.map +1 -1
  27. package/dist/multisig/helpers.d.ts.map +1 -1
  28. package/dist/multisig/helpers.js.map +1 -1
  29. package/dist/multisig.d.ts +39 -161
  30. package/dist/multisig.d.ts.map +1 -1
  31. package/dist/multisig.js +190 -241
  32. package/dist/multisig.js.map +1 -1
  33. package/dist/multisig.test.js +41 -31
  34. package/dist/multisig.test.js.map +1 -1
  35. package/dist/procedures.d.ts +20 -47
  36. package/dist/procedures.d.ts.map +1 -1
  37. package/dist/procedures.js +17 -50
  38. package/dist/procedures.js.map +1 -1
  39. package/dist/signer.d.ts +11 -26
  40. package/dist/signer.d.ts.map +1 -1
  41. package/dist/signer.js +41 -26
  42. package/dist/signer.js.map +1 -1
  43. package/dist/transaction/options.d.ts +2 -0
  44. package/dist/transaction/options.d.ts.map +1 -1
  45. package/dist/transaction/updatePsm.d.ts.map +1 -1
  46. package/dist/transaction/updatePsm.js +21 -3
  47. package/dist/transaction/updatePsm.js.map +1 -1
  48. package/dist/transaction/updateSigners.d.ts.map +1 -1
  49. package/dist/transaction/updateSigners.js +21 -3
  50. package/dist/transaction/updateSigners.js.map +1 -1
  51. package/dist/transaction.d.ts.map +1 -1
  52. package/dist/transaction.js +0 -2
  53. package/dist/transaction.js.map +1 -1
  54. package/dist/transaction.test.js +5 -0
  55. package/dist/transaction.test.js.map +1 -1
  56. package/dist/types/proposal.d.ts +16 -8
  57. package/dist/types/proposal.d.ts.map +1 -1
  58. package/dist/types.d.ts +18 -14
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/utils/signature.d.ts +10 -2
  61. package/dist/utils/signature.d.ts.map +1 -1
  62. package/dist/utils/signature.js +77 -5
  63. package/dist/utils/signature.js.map +1 -1
  64. package/dist/utils/signature.test.js +16 -1
  65. package/dist/utils/signature.test.js.map +1 -1
  66. package/masm/multisig_ecdsa.masm +424 -0
  67. package/masm/psm_ecdsa.masm +179 -0
  68. package/package.json +2 -2
  69. package/src/account/builder.ts +18 -25
  70. package/src/account/masm.ts +433 -2
  71. package/src/account/storage.ts +5 -6
  72. package/src/client.test.ts +36 -0
  73. package/src/client.ts +10 -59
  74. package/src/index.ts +13 -62
  75. package/src/inspector.ts +15 -44
  76. package/src/multisig/helpers.ts +1 -2
  77. package/src/multisig.test.ts +45 -34
  78. package/src/multisig.ts +246 -273
  79. package/src/procedures.ts +21 -56
  80. package/src/signer.ts +48 -28
  81. package/src/transaction/options.ts +2 -0
  82. package/src/transaction/updatePsm.ts +24 -3
  83. package/src/transaction/updateSigners.ts +25 -3
  84. package/src/transaction.test.ts +6 -0
  85. package/src/transaction.ts +0 -2
  86. package/src/types/proposal.ts +15 -8
  87. package/src/types.ts +26 -16
  88. package/src/utils/signature.test.ts +24 -1
  89. package/src/utils/signature.ts +86 -4
@@ -0,0 +1,424 @@
1
+ # Multi-Signature ECDSA secp256k1 Authentication Component
2
+ #
3
+ # This component provides multi-signature authentication for accounts using
4
+ # ECDSA secp256k1 (k256/keccak) signatures instead of RPO Falcon 512.
5
+ # It integrates with the PSM component for optional PSM signature verification.
6
+
7
+ use miden::active_account
8
+ use miden::native_account
9
+ use miden::auth
10
+ use openzeppelin::psm_ecdsa
11
+
12
+ # Type definitions for v0.12 syntax
13
+ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
14
+
15
+ # CONSTANTS
16
+ # =================================================================================================
17
+
18
+ # Auth Request Constants
19
+
20
+ # The event emitted when a signature is not found for a required signer.
21
+ const AUTH_UNAUTHORIZED_EVENT = event("miden::auth::unauthorized")
22
+
23
+ # Storage Layout Constants
24
+ #
25
+ # +-------------------------------+----------+--------------+-------------------+
26
+ # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | EXECUTED TXS | PROC THRESHOLDS |
27
+ # | (slot) | (map) | (map) | (map) |
28
+ # +-------------------------------+----------+--------------+-------------------+
29
+ # | 0 | 1 | 2 | 3 |
30
+ # +-------------------------------+----------+--------------+-------------------+
31
+
32
+ # The slot in this component's storage layout where the default signature threshold and
33
+ # number of approvers are stored as:
34
+ # [default_threshold, num_approvers, 0, 0].
35
+ # The threshold is guaranteed to be less than or equal to num_approvers.
36
+ const THRESHOLD_CONFIG_SLOT = 0
37
+
38
+ # The slot in this component's storage layout where the public keys map is stored.
39
+ # Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
40
+ const PUBLIC_KEYS_MAP_SLOT = 1
41
+
42
+ # The slot in this component's storage layout where executed transactions are stored.
43
+ # Map entries: transaction_message => [is_executed, 0, 0, 0]
44
+ const EXECUTED_TXS_SLOT = 2
45
+
46
+ # The slot in this component's storage layout where procedure thresholds are stored.
47
+ # Map entries: PROC_ROOT => [proc_threshold, 0, 0, 0]
48
+ const PROC_THRESHOLD_ROOTS_SLOT = 3
49
+
50
+ # Executed Transaction Flag Constant
51
+ const IS_EXECUTED_FLAG = [1, 0, 0, 0]
52
+
53
+ # ERRORS
54
+ const ERR_TX_ALREADY_EXECUTED = "failed to approve multisig transaction as it was already executed"
55
+
56
+ const ERR_MALFORMED_MULTISIG_CONFIG = "number of approvers must be equal to or greater than threshold"
57
+
58
+ const ERR_ZERO_IN_MULTISIG_CONFIG = "number of approvers or threshold must not be zero"
59
+
60
+ # MULTISIG PROCEDURES
61
+ # =================================================================================================
62
+
63
+ #! Check if transaction has already been executed and add it to executed transactions for replay protection.
64
+ #!
65
+ #! Inputs: [MSG]
66
+ #! Outputs: []
67
+ #!
68
+ #! Panics if:
69
+ #! - the same transaction has already been executed
70
+ proc assert_new_tx(msg: BeWord)
71
+ push.IS_EXECUTED_FLAG
72
+ # => [[0, 0, 0, is_executed], MSG]
73
+
74
+ swapw
75
+ # => [MSG, IS_EXECUTED_FLAG]
76
+
77
+ push.EXECUTED_TXS_SLOT
78
+ # => [index, MSG, IS_EXECUTED_FLAG]
79
+
80
+ # Set the key value pair in the map to mark transaction as executed
81
+ exec.native_account::set_map_item
82
+ # => [OLD_MAP_ROOT, [0, 0, 0, is_executed]]
83
+
84
+ dropw drop drop drop
85
+ # => [is_executed]
86
+
87
+ assertz.err=ERR_TX_ALREADY_EXECUTED
88
+ # => []
89
+ end
90
+
91
+ #! Remove old approver public keys from the approver public key mapping.
92
+ #!
93
+ #! This procedure cleans up the storage by removing public keys of approvers that are no longer
94
+ #! part of the multisig configuration. This procedure assumes that init_num_of_approvers and
95
+ #! new_num_of_approvers are u32 values.
96
+ #!
97
+ #! Inputs: [init_num_of_approvers, new_num_of_approvers]
98
+ #! Outputs: []
99
+ #!
100
+ #! Where:
101
+ #! - init_num_of_approvers is the original number of approvers before the update
102
+ #! - new_num_of_approvers is the new number of approvers after the update
103
+ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u32)
104
+ dup.1 dup.1
105
+ u32assert2 u32lt
106
+ # => [should_loop, i = init_num_of_approvers, new_num_of_approvers]
107
+
108
+ while.true
109
+ # => [i, new_num_of_approvers]
110
+
111
+ sub.1
112
+ # => [i-1, new_num_of_approvers]
113
+
114
+ dup
115
+ # => [i-1, i-1, new_num_of_approvers]
116
+
117
+ push.0.0.0
118
+ # => [[0, 0, 0, i-1], i-1, new_num_of_approvers]
119
+
120
+ padw swapw
121
+ # => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
122
+
123
+ push.PUBLIC_KEYS_MAP_SLOT
124
+ # => [pub_key_slot_idx, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
125
+
126
+ exec.native_account::set_map_item
127
+ # => [OLD_MAP_ROOT, OLD_MAP_VALUE, i-1, new_num_of_approvers]
128
+
129
+ dropw dropw
130
+ # => [i-1, new_num_of_approvers]
131
+
132
+ dup.1 dup.1
133
+ u32lt
134
+ # => [should_loop, i-1, new_num_of_approvers]
135
+ end
136
+
137
+ drop drop
138
+ # => []
139
+ end
140
+
141
+ #! Update threshold config and add / remove approvers
142
+ #!
143
+ #! Inputs:
144
+ #! Operand stack: [MULTISIG_CONFIG_HASH, pad(12)]
145
+ #! Advice map: {
146
+ #! MULTISIG_CONFIG_HASH => [CONFIG, PUB_KEY_N, PUB_KEY_N-1, ..., PUB_KEY_0]
147
+ #! }
148
+ #! Outputs:
149
+ #! Operand stack: []
150
+ #!
151
+ #! Where:
152
+ #! - MULTISIG_CONFIG_HASH is the hash of the threshold and new public key vector
153
+ #! - MULTISIG_CONFIG is [threshold, num_approvers, 0, 0]
154
+ #! - PUB_KEY_i is the public key of the i-th signer
155
+ #!
156
+ #! Locals:
157
+ #! 0: new_num_of_approvers
158
+ #! 1: init_num_of_approvers
159
+ pub proc update_signers_and_threshold.2(multisig_config_hash: BeWord)
160
+ adv.push_mapval
161
+ # => [MULTISIG_CONFIG_HASH, pad(12)]
162
+
163
+ adv_loadw
164
+ # => [MULTISIG_CONFIG, pad(12)]
165
+
166
+ # store new_num_of_approvers for later
167
+ dup.2 loc_store.0
168
+ # => [MULTISIG_CONFIG, pad(12)]
169
+
170
+ dup.3 dup.3
171
+ # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
172
+
173
+ # make sure that the threshold is smaller than the number of approvers
174
+ u32assert2.err=ERR_MALFORMED_MULTISIG_CONFIG
175
+ u32gt assertz.err=ERR_MALFORMED_MULTISIG_CONFIG
176
+ # => [MULTISIG_CONFIG, pad(12)]
177
+
178
+ dup.3 dup.3
179
+ # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
180
+
181
+ # make sure that threshold or num_approvers are not zero
182
+ eq.0 assertz.err=ERR_ZERO_IN_MULTISIG_CONFIG
183
+ eq.0 assertz.err=ERR_ZERO_IN_MULTISIG_CONFIG
184
+ # => [MULTISIG_CONFIG, pad(12)]
185
+
186
+ push.THRESHOLD_CONFIG_SLOT
187
+ # => [slot, MULTISIG_CONFIG, pad(12)]
188
+
189
+ exec.native_account::set_item
190
+ # => [OLD_THRESHOLD_CONFIG, pad(12)]
191
+
192
+ # store init_num_of_approvers for later
193
+ drop drop loc_store.1 drop
194
+ # => [pad(12)]
195
+
196
+ loc_load.0
197
+ # => [num_approvers]
198
+
199
+ dup neq.0
200
+ while.true
201
+ sub.1
202
+ # => [i-1, pad(12)]
203
+
204
+ dup push.0.0.0
205
+ # => [[0, 0, 0, i-1], i-1, pad(12)]
206
+
207
+ padw adv_loadw
208
+ # => [PUB_KEY, [0, 0, 0, i-1], i-1, pad(12)]
209
+
210
+ swapw
211
+ # => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
212
+
213
+ push.PUBLIC_KEYS_MAP_SLOT
214
+ # => [pub_key_slot_idx, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
215
+
216
+ exec.native_account::set_map_item
217
+ # => [OLD_MAP_ROOT, OLD_MAP_VALUE, i-1, pad(12)]
218
+
219
+ dropw dropw
220
+ # => [i-1, pad(12)]
221
+
222
+ dup neq.0
223
+ # => [is_non_zero, i-1, pad(12)]
224
+ end
225
+ # => [pad(13)]
226
+
227
+ drop
228
+ # => [pad(12)]
229
+
230
+ # compare initial vs current multisig config
231
+
232
+ # load init_num_of_approvers & new_num_of_approvers
233
+ loc_load.0 loc_load.1
234
+ # => [init_num_of_approvers, new_num_of_approvers, pad(12)]
235
+
236
+ exec.cleanup_pubkey_mapping
237
+ # => [pad(12)]
238
+ end
239
+
240
+ # Computes the effective transaction threshold based on called procedures and per-procedure
241
+ # overrides stored in PROC_THRESHOLD_ROOTS_SLOT. Falls back to default_threshold if no
242
+ # overrides apply.
243
+ #
244
+ #! Inputs: [default_threshold]
245
+ #! Outputs: [transaction_threshold]
246
+ proc compute_transaction_threshold.1(default_threshold: u32) -> u32
247
+ # 1. initialize transaction_threshold = 0
248
+ # 2. iterate through all account procedures
249
+ # a. check if the procedure was called during the transaction
250
+ # b. if called, get the override threshold of that procedure from the config map
251
+ # c. if proc_threshold > transaction_threshold, set transaction_threshold = proc_threshold
252
+ # 3. if transaction_threshold == 0 at the end, revert to using default_threshold
253
+
254
+ # store default_threshold for later
255
+ loc_store.0
256
+ # => []
257
+
258
+ # 1. initialize transaction_threshold = 0
259
+ push.0
260
+ # => [transaction_threshold]
261
+
262
+ # get the number of account procedures
263
+ exec.active_account::get_num_procedures
264
+ # => [num_procedures, transaction_threshold]
265
+
266
+ # 2. iterate through all account procedures
267
+ dup neq.0
268
+ # => [should_continue, num_procedures, transaction_threshold]
269
+ while.true
270
+ sub.1 dup
271
+ # => [num_procedures-1, num_procedures-1, transaction_threshold]
272
+
273
+ # get procedure root of the procedure with index i
274
+ exec.active_account::get_procedure_root dupw
275
+ # => [PROC_ROOT, PROC_ROOT, num_procedures-1, transaction_threshold]
276
+
277
+ # 2a. check if this procedure has been called in the transaction
278
+ exec.native_account::was_procedure_called
279
+ # => [was_called, PROC_ROOT, num_procedures-1, transaction_threshold]
280
+
281
+ # if it has been called, get the override threshold of that procedure
282
+ if.true
283
+ # => [PROC_ROOT, num_procedures-1, transaction_threshold]
284
+
285
+ push.PROC_THRESHOLD_ROOTS_SLOT
286
+ # => [PROC_THRESHOLD_ROOTS_SLOT, PROC_ROOT, num_procedures-1, transaction_threshold]
287
+
288
+ # 2b. get the override proc_threshold of that procedure
289
+ # if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
290
+ exec.active_account::get_initial_map_item
291
+ # => [[0, 0, 0, proc_threshold], num_procedures-1, transaction_threshold]
292
+
293
+ drop drop drop dup dup.3
294
+ # => [transaction_threshold, proc_threshold, proc_threshold, num_procedures-1, transaction_threshold]
295
+
296
+ u32assert2.err="transaction threshold or procedure threshold are not u32"
297
+ u32gt
298
+ # => [is_gt, proc_threshold, num_procedures-1, transaction_threshold]
299
+ # 2c. if proc_threshold > transaction_threshold, update transaction_threshold
300
+ movup.2 movdn.3
301
+ # => [is_gt, proc_threshold, transaction_threshold, num_procedures-1]
302
+ cdrop
303
+ # => [updated_transaction_threshold, num_procedures-1]
304
+ swap
305
+ # => [num_procedures-1, updated_transaction_threshold]
306
+ # if it has not been called during this transaction, nothing to do, move to the next procedure
307
+ else
308
+ dropw
309
+ # => [num_procedures-1, transaction_threshold]
310
+ end
311
+
312
+ dup neq.0
313
+ # => [should_continue, num_procedures-1, transaction_threshold]
314
+ end
315
+
316
+ drop
317
+ # => [transaction_threshold]
318
+
319
+ loc_load.0
320
+ # => [default_threshold, transaction_threshold]
321
+
322
+ # 3. if transaction_threshold == 0 at the end, revert to using default_threshold
323
+ dup.1 eq.0
324
+ # => [is_zero, default_threshold, transaction_threshold]
325
+
326
+ cdrop
327
+ # => [effective_transaction_threshold]
328
+ end
329
+
330
+ #! Authenticate a transaction using ECDSA secp256k1 with multi-signature support.
331
+ #!
332
+ #! This procedure implements multi-signature authentication by:
333
+ #! 1. Computing the transaction summary message that needs to be signed
334
+ #! 2. Verifying ECDSA signatures from multiple required signers against their public keys
335
+ #! 3. Ensuring the minimum threshold of valid signatures is met
336
+ #! 4. Implementing replay protection by tracking executed transactions
337
+ #! 5. Verifying PSM signature if PSM selector is enabled (via PSM component)
338
+ #!
339
+ #! Inputs:
340
+ #! Operand stack: [SALT]
341
+ #! Advice map: {
342
+ #! h(PUB_KEY_0, MSG): SIG_0,
343
+ #! h(PUB_KEY_1, MSG): SIG_1,
344
+ #! h(PUB_KEY_n, MSG): SIG_n
345
+ #! }
346
+ #! Outputs:
347
+ #! Operand stack: []
348
+ #!
349
+ #! Where:
350
+ #! - SALT is a cryptographically random nonce that enables multiple concurrent
351
+ #! multisig transactions while maintaining replay protection. Each transaction
352
+ #! must use a unique SALT value to ensure transaction uniqueness.
353
+ #! - SIG_i is the ECDSA signature from the i-th signer.
354
+ #! - MSG is the transaction message being signed.
355
+ #! - h(PUB_KEY_i, MSG) is the hash of the public key and message used as the advice map key.
356
+ #!
357
+ #! Panics if:
358
+ #! - insufficient number of valid signatures (below threshold).
359
+ #! - the same transaction has already been executed (replay protection).
360
+ #! - PSM signature verification fails (if PSM is enabled).
361
+ #!
362
+ #! Invocation: call
363
+ pub proc auth_tx_ecdsa_multisig.1(salt: BeWord)
364
+ exec.native_account::incr_nonce drop
365
+ # => [SALT]
366
+
367
+ # ------ Computing transaction summary ------
368
+
369
+ exec.auth::create_tx_summary
370
+ # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
371
+
372
+ # to build a tx_summary in the host, we need these four words in the advice provider
373
+ exec.auth::adv_insert_hqword
374
+ # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
375
+
376
+ # the commitment to the tx summary is the message that is signed
377
+ exec.auth::hash_tx_summary
378
+ # => [TX_SUMMARY_COMMITMENT]
379
+
380
+ # ------ Verifying approver signatures ------
381
+
382
+ push.THRESHOLD_CONFIG_SLOT
383
+ # => [index, TX_SUMMARY_COMMITMENT]
384
+
385
+ exec.active_account::get_initial_item
386
+ # => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
387
+
388
+ drop drop
389
+ # => [num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
390
+
391
+ swap movdn.5
392
+ # => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
393
+
394
+ push.PUBLIC_KEYS_MAP_SLOT
395
+ # => [pub_key_slot_idx, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
396
+
397
+ exec.::miden::auth::ecdsa_k256_keccak::verify_signatures
398
+ # => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
399
+
400
+ # ------ Checking threshold is >= num_verified_signatures ------
401
+
402
+ movup.5
403
+ # => [default_threshold, num_verified_signatures, TX_SUMMARY_COMMITMENT]
404
+
405
+ exec.compute_transaction_threshold
406
+ # => [transaction_threshold, num_verified_signatures, TX_SUMMARY_COMMITMENT]
407
+
408
+ u32assert2 u32lt
409
+ # => [is_unauthorized, TX_SUMMARY_COMMITMENT]
410
+
411
+ # If signatures are non-existent the tx will fail here.
412
+ if.true
413
+ emit.AUTH_UNAUTHORIZED_EVENT
414
+ push.0 assert.err="insufficient number of signatures"
415
+ end
416
+
417
+ # ------ Verifying PSM Signature ------
418
+ # => [TX_SUMMARY_COMMITMENT]
419
+ call.psm_ecdsa::verify_psm_signature
420
+
421
+ # ------ Writing executed transaction MSG to map ------
422
+ # => [TX_SUMMARY_COMMITMENT]
423
+ exec.assert_new_tx
424
+ end
@@ -0,0 +1,179 @@
1
+ # Private State Manager (PSM) Authentication Component (ECDSA)
2
+ #
3
+ # This component provides PSM signature verification for accounts using
4
+ # ECDSA secp256k1 (k256/keccak) signatures.
5
+ # It can be used standalone or in conjunction with other auth components like multisig.
6
+
7
+ use miden::active_account
8
+ use miden::native_account
9
+
10
+ # Type definitions for v0.12 syntax
11
+ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
12
+
13
+ # IMPORTANT SECURITY NOTES
14
+ # --------------------------------------------------------------------------------
15
+ # - The selector in `PSM_SELECTOR_SLOT` controls whether the extra PSM signature
16
+ # is enforced:
17
+ # * PSM_ON => exactly one valid PSM signature is required.
18
+ # * PSM_OFF => PSM signature is skipped for that call.
19
+ #
20
+ # - `verify_psm_signature` reads the selector from initial storage state.
21
+ # This means changes made during the same transaction won't affect the check.
22
+ #
23
+ # - `enable_psm` / `disable_psm` procedures allow explicit control over PSM state.
24
+ #
25
+ # - `update_psm_public_key`:
26
+ # * Installs a new PSM public key in the map at `PSM_PUBLIC_KEY_MAP_SLOT`.
27
+ # * Does not itself perform any signature checks.
28
+ # * To update the key without requiring PSM signature, ensure selector is OFF.
29
+ #
30
+ # Storage Layout
31
+ # --------------------------------------------------------------------------------
32
+ #
33
+ # +---------------------+---------------+
34
+ # | DESCRIPTION | SLOT |
35
+ # +---------------------+---------------+
36
+ # | PSM SELECTOR (word) | 0 |
37
+ # | PSM PUBLIC KEY MAP | 1 |
38
+ # +---------------------+---------------+
39
+ #
40
+ # - PSM_SELECTOR_SLOT (0):
41
+ # * Stores a word that is compared against [1, 0, 0, 0] (PSM_ON).
42
+ # * Any value != PSM_ON is treated as PSM_OFF.
43
+ #
44
+ # - PSM_PUBLIC_KEY_MAP_SLOT (1):
45
+ # * A map from a fixed key [0, 0, 0, 0] to the single PSM public key:
46
+ # [0, 0, 0, 0] => PSM_PUBLIC_KEY
47
+ # * PSM_PUBLIC_KEY is an ECDSA secp256k1 public key represented as a word.
48
+
49
+ # CONSTANTS
50
+ # =================================================================================================
51
+
52
+ # Slot where the PSM selector flag is stored:
53
+ # - PSM_ON => PSM signature required
54
+ # - PSM_OFF => PSM signature skipped
55
+ const PSM_SELECTOR_SLOT = 0
56
+
57
+ # Map slot for PSM public key
58
+ # Uses exactly one PSM public key at index [0, 0, 0, 0]
59
+ # [0, 0, 0, 0] => PSM_PUBLIC_KEY
60
+ const PSM_PUBLIC_KEY_MAP_SLOT = 1
61
+
62
+ # Selector flag values
63
+ const PSM_ON = [1, 0, 0, 0]
64
+ const PSM_OFF = [0, 0, 0, 0]
65
+
66
+ # The event emitted when a signature is not found for a required signer.
67
+ const AUTH_UNAUTHORIZED_EVENT = event("miden::auth::unauthorized")
68
+
69
+ # PSM PROCEDURES
70
+ # =================================================================================================
71
+
72
+ #! Enable PSM verification by setting the selector to ON.
73
+ #!
74
+ #! Operand stack inputs: []
75
+ #! Outputs: []
76
+ #!
77
+ #! Notes:
78
+ #! - Sets PSM_SELECTOR_SLOT to PSM_ON (1)
79
+ #! - After this, transactions will require PSM signature verification
80
+ proc.enable_psm
81
+ push.PSM_ON
82
+ # => [PSM_ON]
83
+
84
+ push.PSM_SELECTOR_SLOT
85
+ # => [PSM_SELECTOR_SLOT, PSM_ON]
86
+
87
+ exec.native_account::set_item
88
+ # => [OLD_ROOT]
89
+
90
+ dropw
91
+ # => []
92
+ end
93
+
94
+ #! Disable PSM verification by setting the selector to OFF.
95
+ #!
96
+ #! Operand stack inputs: []
97
+ #! Outputs: []
98
+ #!
99
+ #! Notes:
100
+ #! - Sets PSM_SELECTOR_SLOT to PSM_OFF (0)
101
+ #! - After this, transactions will NOT require PSM signature verification
102
+ proc.disable_psm
103
+ push.PSM_OFF
104
+ # => [PSM_OFF]
105
+
106
+ push.PSM_SELECTOR_SLOT
107
+ # => [PSM_SELECTOR_SLOT, PSM_OFF]
108
+
109
+ exec.native_account::set_item
110
+ # => [OLD_ROOT]
111
+
112
+ dropw
113
+ # => []
114
+ end
115
+
116
+ #! Update the PSM public key.
117
+ #!
118
+ #! Operand stack inputs: []
119
+ #! Advice stack inputs: [PUB_KEY]
120
+ #! - PUB_KEY is the new PSM ECDSA secp256k1 public key
121
+ #!
122
+ #! Notes:
123
+ #! - Stores PUB_KEY into PSM_PUBLIC_KEY_MAP_SLOT:
124
+ #! [0, 0, 0, 0] => PSM_PUBLIC_KEY
125
+ #! - To update the key without requiring PSM signature, ensure
126
+ #! PSM_SELECTOR_SLOT = 0 (OFF) before calling this.
127
+ pub proc update_psm_public_key
128
+ exec.disable_psm
129
+ # ------ Update the PSM public key ------
130
+ adv_loadw
131
+ # => [PUB_KEY]
132
+
133
+ push.0.0.0.0
134
+ # => [MAP_KEY, PUB_KEY]
135
+ # Note that MAP_KEY is [0, 0, 0, 0] for a single PSM_KEY
136
+
137
+ push.PSM_PUBLIC_KEY_MAP_SLOT
138
+ # => [index, MAP_KEY, PUB_KEY]
139
+
140
+ exec.native_account::set_map_item
141
+ # => [OLD_MAP_ROOT, OLD_MAP_VALUE]
142
+
143
+ dropw dropw
144
+ # => []
145
+ end
146
+
147
+ #! Conditionally verify a "PSM" signature against a stored public key hash.
148
+ #! The condition is controlled by the selector at PSM_SELECTOR_SLOT.
149
+ #!
150
+ #! Inputs: [MSG]
151
+ #! Outputs: [MSG]
152
+ #!
153
+ #! Panics if:
154
+ #! - Selector is ON but the provided PSM signature is invalid or missing.
155
+ #!
156
+ #! Notes:
157
+ #! - MSG is TX_SUMMARY_COMMITMENT provided by auth procedure
158
+ #! - If selector is OFF (0), PSM verification is skipped
159
+ #! - Selector value is read from initial storage state
160
+ pub proc verify_psm_signature(msg: BeWord)
161
+ push.PSM_SELECTOR_SLOT
162
+ exec.active_account::get_item
163
+ drop drop drop
164
+ # => [selector, MSG]
165
+
166
+ push.1 eq
167
+ if.true
168
+ push.1
169
+ push.PSM_PUBLIC_KEY_MAP_SLOT
170
+ exec.::miden::auth::ecdsa_k256_keccak::verify_signatures
171
+ push.1 neq
172
+ if.true
173
+ emit.AUTH_UNAUTHORIZED_EVENT
174
+ push.0 assert.err="invalid PSM signature"
175
+ end
176
+ end
177
+ # => [MSG]
178
+ exec.enable_psm
179
+ end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openzeppelin/miden-multisig-client",
3
- "version": "0.12.6",
3
+ "version": "0.12.7",
4
4
  "description": "TypeScript SDK for Miden multisig accounts with PSM integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "test:watch": "vitest"
27
27
  },
28
28
  "dependencies": {
29
- "@openzeppelin/psm-client": "^0.12.6"
29
+ "@openzeppelin/psm-client": "file:../psm-client"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@demox-labs/miden-sdk": "^0.12.5"