starknet 11.7.1 → 11.8.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [11.8.0](https://github.com/starknet-io/starknet.js/compare/v11.7.2...v11.8.0) (2026-11-23)
2
+
3
+ ### Features
4
+
5
+ - **falcon:** sign and verify for the OpenZeppelin Falcon-512 accounts ([f8034a2](https://github.com/starknet-io/starknet.js/commit/f8034a261e80f1e52e56dd88e3b712d7b7230a7d))
6
+
7
+ ## [11.7.2](https://github.com/starknet-io/starknet.js/compare/v11.7.1...v11.7.2) (2026-11-17)
8
+
9
+ ### Bug Fixes
10
+
11
+ - units() refuses malformed amounts and handles negative amounts ([4b7d396](https://github.com/starknet-io/starknet.js/commit/4b7d39644ca19402087b6926f200503e3f639157))
12
+
1
13
  ## [11.7.1](https://github.com/starknet-io/starknet.js/compare/v11.7.0...v11.7.1) (2026-11-17)
2
14
 
3
15
  ### Bug Fixes
@@ -1,11 +1,41 @@
1
1
  import * as starknet from 'starknet';
2
2
 
3
3
  /**
4
- * Signer for the S2morrow Falcon-512 account (post-quantum signature), in pure TypeScript.
4
+ * The Falcon-512 accounts that `starknet/falcon` signs for. Each one has its own signature layout:
5
+ * the signer must use the type of the account class, or the account rejects the signatures.
6
+ *
7
+ * - `'s2morrow'`: the S2morrow account (https://github.com/feltroidprime/s2morrow), class
8
+ * `0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5`. Signatures of 61 felts,
9
+ * hashed with Poseidon. The default.
10
+ * - `'oz-hint'`: `Falcon512ShakeAccountUpgradeable` of OpenZeppelin Contracts for Cairo
11
+ * (v4.1.0-rc.0), class `0x014660ce3739fbde6e33d994cebd6a9fb20e800516b2e1b6c253d4d09baa9ae0`
12
+ * (compiled with Cairo 2.21.0). Signatures of 60 felts, with the product s1·h (the hint), which
13
+ * makes the on-chain check cheaper.
14
+ * - `'oz-direct'`: `Falcon512ShakeDirectAccountUpgradeable` of OpenZeppelin Contracts for Cairo
15
+ * (v4.1.0-rc.0), class `0x016111958d61eedfa5a950b608997abb4981b548f1862d620cc9247461ddeeb1`
16
+ * (compiled with Cairo 2.21.0). Signatures of 31 felts, without the hint.
17
+ *
18
+ * The two OpenZeppelin accounts store the same key and have the same ABI. A class upgrade from one
19
+ * to the other keeps the address and the key, but changes the signature layout.
20
+ */
21
+ type Falcon512AccountType = 's2morrow' | 'oz-hint' | 'oz-direct';
22
+ /** Options of `Falcon512Signer`, `falcon512.verify` and `falcon512.verifyMessage`. */
23
+ type Falcon512Options = {
24
+ /** The type of the account that checks the signatures. Default: `'s2morrow'`. */
25
+ accountType?: Falcon512AccountType;
26
+ };
27
+
28
+ /**
29
+ * Signer for the Falcon-512 accounts (post-quantum signature), in pure TypeScript.
5
30
  *
6
31
  * Falcon-512 is a signature scheme built on lattices, designed to resist attacks by quantum
7
- * computers. The S2morrow account (https://github.com/feltroidprime/s2morrow) verifies it on-chain,
8
- * on a Poseidon hash of the transaction. A signature is 61 felts.
32
+ * computers. Three account contracts verify it on-chain, each with its own signature layout: the
33
+ * `accountType` option of the constructor selects it (see `Falcon512AccountType`).
34
+ * - `'s2morrow'` (default): the S2morrow account (https://github.com/feltroidprime/s2morrow), which
35
+ * hashes the transaction with Poseidon. A signature is 61 felts.
36
+ * - `'oz-hint'` and `'oz-direct'`: the two Falcon-512 accounts of OpenZeppelin Contracts for Cairo
37
+ * (pre-release v4.1.0-rc.0), which hash it with SHAKE-256. A signature is 60 felts with the hint
38
+ * s1·h, which makes the on-chain check cheaper, or 31 felts without it.
9
39
  *
10
40
  * Fees: the on-chain verification costs much more L2 gas than an ECDSA one. By default, the fee
11
41
  * estimates of `Account` skip the validation of the signature (`skipValidate: true`), so they leave
@@ -27,26 +57,31 @@ declare class Falcon512Signer implements starknet.SignerInterface {
27
57
  * signer keeps its own copy, in a private field.
28
58
  * @param {Uint8Array | string} secretKey NIST Falcon-512 secret key (1281 bytes), Uint8Array or
29
59
  * hex string. Prefer a Uint8Array: a string cannot be wiped from memory.
30
- * @throws {Error} when the secret key is invalid
60
+ * @param {Falcon512Options} [options] `accountType`: the type of the account that checks the
61
+ * signatures, `'s2morrow'` (default), `'oz-hint'` or `'oz-direct'`
62
+ * @throws {Error} when the secret key or an option is invalid
31
63
  * @example
32
64
  * ```typescript
33
65
  * const { secretKey } = falcon512.generateKeyPair();
34
- * const mySigner = new Falcon512Signer(secretKey);
66
+ * const mySigner = new Falcon512Signer(secretKey); // for an S2morrow account
67
+ * const myOzSigner = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });
35
68
  * new Falcon512Signer(new Uint8Array(1281));
36
69
  * // throws Error("Falcon512: invalid secret key header")
37
70
  * ```
38
71
  */
39
- constructor(secretKey: Uint8Array | string);
72
+ constructor(secretKey: Uint8Array | string, options?: Falcon512Options);
40
73
  /**
41
74
  * Builds a signer from a falcon-rs secret key (3584 bytes), converted to the NIST format.
42
75
  *
43
76
  * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so
44
77
  * the signatures it produced may leak information about the secret key. Use this for continuity
45
78
  * only; for real funds, generate a new key with `falcon512.generateKeyPair`. The S2morrow account
46
- * cannot change its key: a new key means a new account.
79
+ * cannot change its key: a new key means a new account. An OpenZeppelin account can change its
80
+ * key (see `signOwnershipAcceptance`).
47
81
  * @param {Uint8Array | string} secretKey the falcon-rs secret key (3584 bytes), or its hex string
82
+ * @param {Falcon512Options} [options] `accountType`, as for the constructor
48
83
  * @returns {Falcon512Signer} a signer that holds the same key, in the NIST format
49
- * @throws {Error} when the falcon-rs secret key is invalid
84
+ * @throws {Error} when the falcon-rs secret key or an option is invalid
50
85
  * @example
51
86
  * ```typescript
52
87
  * const mySigner = Falcon512Signer.fromFalconRs(falconRsSecretKey); // 3584 bytes, from falcon-rs
@@ -54,7 +89,7 @@ declare class Falcon512Signer implements starknet.SignerInterface {
54
89
  * // result = ['0xb2cf4f8b3c6f60cc662f438970ad34017e260c52d7911297a42811ce3cea2b', …] (29 felts)
55
90
  * ```
56
91
  */
57
- static fromFalconRs(secretKey: Uint8Array | string): Falcon512Signer;
92
+ static fromFalconRs(secretKey: Uint8Array | string, options?: Falcon512Options): Falcon512Signer;
58
93
  /**
59
94
  * NIST Falcon-512 public key (897 bytes), as a hex string.
60
95
  * @returns {Promise<string>} the public key: 0x, then 1794 hex digits
@@ -68,7 +103,9 @@ declare class Falcon512Signer implements starknet.SignerInterface {
68
103
  */
69
104
  getPubKey(): Promise<string>;
70
105
  /**
71
- * The 29 felts of the account constructor argument `pk_packed`.
106
+ * The 29 felts of the public key, in the form the accounts store it: the constructor argument
107
+ * `pk_packed` of S2morrow, or the `public_key` array of an OpenZeppelin account (whose
108
+ * constructor calldata is `29`, then these 29 felts). The same for the three account types.
72
109
  * @returns {string[]} the 29 felts, as hex strings (a new array at each call)
73
110
  * @example
74
111
  * ```typescript
@@ -83,11 +120,12 @@ declare class Falcon512Signer implements starknet.SignerInterface {
83
120
  * Signs a SNIP-12 message (TypedData) for off-chain use.
84
121
  * @param {TypedData} typedData the message to sign
85
122
  * @param {string} accountAddress address of the account that signs the message
86
- * @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
123
+ * @returns {Promise<Signature>} the signature, as hex strings: 61 felts (S2morrow), 60
124
+ * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)
87
125
  * @example
88
126
  * ```typescript
89
127
  * const result = await mySigner.signMessage(myTypedData, accountAddress);
90
- * // result = ['0x…', …] (61 felts, random salt); result[29] = '0x2' (salt length)
128
+ * // result = ['0x…', …] (S2morrow: 61 felts, random salt); result[29] = '0x2' (salt length)
91
129
  * ```
92
130
  */
93
131
  signMessage(typedData: starknet.TypedData, accountAddress: string): Promise<starknet.Signature>;
@@ -95,7 +133,8 @@ declare class Falcon512Signer implements starknet.SignerInterface {
95
133
  * Signs an INVOKE transaction (V3 only).
96
134
  * @param {Call[]} transactions the calls of the transaction
97
135
  * @param {InvocationsSignerDetails} details the details needed to hash the transaction
98
- * @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
136
+ * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to
137
+ * the account type
99
138
  * @throws {Error} when the transaction is not V3
100
139
  * @example
101
140
  * ```typescript
@@ -124,14 +163,15 @@ declare class Falcon512Signer implements starknet.SignerInterface {
124
163
  * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
125
164
  * };
126
165
  * const result = await mySigner.signTransaction(calls, details);
127
- * // result = ['0x…', …] (61 felts)
166
+ * // result = ['0x…', …] (S2morrow: 61 felts)
128
167
  * ```
129
168
  */
130
169
  signTransaction(transactions: starknet.Call[], details: starknet.InvocationsSignerDetails): Promise<starknet.Signature>;
131
170
  /**
132
171
  * Signs the DEPLOY_ACCOUNT transaction of a Falcon-512 account (V3 only).
133
172
  * @param {DeployAccountSignerDetails} details the details needed to hash the transaction
134
- * @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
173
+ * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to
174
+ * the account type
135
175
  * @throws {Error} when the transaction is not V3
136
176
  * @example
137
177
  * ```typescript
@@ -158,14 +198,15 @@ declare class Falcon512Signer implements starknet.SignerInterface {
158
198
  * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
159
199
  * };
160
200
  * const result = await mySigner.signDeployAccountTransaction(details);
161
- * // result = ['0x…', …] (61 felts)
201
+ * // result = ['0x…', …] (S2morrow: 61 felts)
162
202
  * ```
163
203
  */
164
204
  signDeployAccountTransaction(details: starknet.DeployAccountSignerDetails): Promise<starknet.Signature>;
165
205
  /**
166
206
  * Signs a DECLARE transaction (V3 only).
167
207
  * @param {DeclareSignerDetails} details the details needed to hash the transaction
168
- * @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
208
+ * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to
209
+ * the account type
169
210
  * @throws {Error} when the transaction is not V3
170
211
  * @example
171
212
  * ```typescript
@@ -188,15 +229,57 @@ declare class Falcon512Signer implements starknet.SignerInterface {
188
229
  * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
189
230
  * };
190
231
  * const result = await mySigner.signDeclareTransaction(details);
191
- * // result = ['0x…', …] (61 felts)
232
+ * // result = ['0x…', …] (S2morrow: 61 felts)
192
233
  * ```
193
234
  */
194
235
  signDeclareTransaction(details: starknet.DeclareSignerDetails): Promise<starknet.Signature>;
195
236
  /**
196
- * Signs a hash: the last step of all the methods above. It stays protected, so that no public
197
- * method signs an arbitrary hash. A subclass can override it, as for every starknet.js signer.
237
+ * Signs the acceptance of a key change of an OpenZeppelin Falcon-512 account.
238
+ *
239
+ * The account changes its key when it calls its own `set_public_key(new_public_key, signature)`:
240
+ * the current key signs that transaction, as any other, and the new key must sign an acceptance.
241
+ * Call this method on the signer of the new key, with the key that the account holds now. The
242
+ * signed hash is Poseidon('StarkNet Message', 'accept_ownership', account address,
243
+ * Poseidon(current key)). It holds no chain id, nonce or expiry: an acceptance is not single-use,
244
+ * and the current key must still sign each key change.
245
+ * @param {BigNumberish} accountAddress the address of the account
246
+ * @param {BigNumberish[]} currentPublicKey the 29 felts of the key that the account holds now
247
+ * (`getPackedPublicKey()` of its current signer, or its `get_public_key`)
248
+ * @returns {Promise<string[]>} the acceptance, as hex strings, in the layout of this signer: 60
249
+ * felts (`'oz-hint'`) or 31 (`'oz-direct'`)
250
+ * @throws {Error} for an S2morrow signer (that account cannot change its key), or when the
251
+ * current key has neither 29 felts nor none, or a value is not a felt252. Also when a subclass
252
+ * makes `signRaw` return something else than an array of felts
253
+ * @example
254
+ * ```typescript
255
+ * const newSigner = new Falcon512Signer(newSecretKey, { accountType: 'oz-hint' });
256
+ * const acceptance = await newSigner.signOwnershipAcceptance(
257
+ * falconAccount.address,
258
+ * currentSigner.getPackedPublicKey()
259
+ * );
260
+ * const { transaction_hash } = await falconAccount.execute(
261
+ * {
262
+ * contractAddress: falconAccount.address,
263
+ * entrypoint: 'set_public_key',
264
+ * calldata: CallData.compile({
265
+ * new_public_key: newSigner.getPackedPublicKey(),
266
+ * signature: acceptance,
267
+ * }),
268
+ * },
269
+ * { skipValidate: false }
270
+ * );
271
+ * await myProvider.waitForTransaction(transaction_hash);
272
+ * // From now on, the account checks the signatures of newSigner.
273
+ * ```
274
+ */
275
+ signOwnershipAcceptance(accountAddress: starknet.BigNumberish, currentPublicKey: readonly starknet.BigNumberish[]): Promise<string[]>;
276
+ /**
277
+ * Signs a hash: the last step of all the methods above, in the layout of the account type. It
278
+ * stays protected, so that no public method signs an arbitrary hash. A subclass can override it,
279
+ * as for every starknet.js signer.
198
280
  * @param {string} msgHash the hash to sign, a felt252
199
- * @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
281
+ * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to
282
+ * the account type
200
283
  * @example
201
284
  * ```typescript
202
285
  * class LoggedFalconSigner extends Falcon512Signer {
@@ -214,14 +297,18 @@ declare class Falcon512Signer implements starknet.SignerInterface {
214
297
 
215
298
  /**
216
299
  * Low-level verification, same shape as `ec.starkCurve.verify(signature, msgHash, fullPublicKey)`.
217
- * @param {Signature} signature the 61 felts of a Falcon-512 signature
300
+ * @param {Signature} signature the felts of a Falcon-512 signature: 61 (S2morrow), 60
301
+ * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)
218
302
  * @param {BigNumberish} msgHash the signed hash (a transaction hash, or the hash of a SNIP-12
219
303
  * message)
220
- * @param {Uint8Array | string} fullPublicKey NIST Falcon-512 public key (897 bytes), as returned by
221
- * `getPubKey()`
222
- * @returns {boolean} true for a valid signature of msgHash; false for an invalid or malformed
223
- * signature, or a malformed hash
224
- * @throws {Error} when the public key is invalid
304
+ * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the public key: the NIST Falcon-512
305
+ * key (897 bytes, as returned by `getPubKey()`), or the 29 felts of the packed key (as returned by
306
+ * `getPackedPublicKey()`, or by `get_public_key` of an OpenZeppelin account)
307
+ * @param {Falcon512Options} [options] `accountType`: the signature layout to check, `'s2morrow'`
308
+ * (default), `'oz-hint'` or `'oz-direct'`
309
+ * @returns {boolean} true for a valid signature of msgHash in this layout; false for an invalid or
310
+ * malformed signature, a signature in another layout, or a malformed hash
311
+ * @throws {Error} when the public key or an option is invalid
225
312
  * @example
226
313
  * ```typescript
227
314
  * const { secretKey, publicKey } = falcon512.generateKeyPair();
@@ -232,23 +319,31 @@ declare class Falcon512Signer implements starknet.SignerInterface {
232
319
  * // result = true
233
320
  * const result2 = falcon512.verify(signature, '0x1234', publicKey);
234
321
  * // result2 = false
322
+ * const myOzSigner = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });
323
+ * const ozSignature = await myOzSigner.signMessage(myTypedData, accountAddress);
324
+ * const result3 = falcon512.verify(ozSignature, msgHash, myOzSigner.getPackedPublicKey(), {
325
+ * accountType: 'oz-hint',
326
+ * });
327
+ * // result3 = true
235
328
  * falcon512.verify(signature, msgHash, '0x1234');
236
329
  * // throws Error("Falcon512: public key must have 1794 hex digits, got 4")
237
330
  * ```
238
331
  */
239
- declare function verify(signature: starknet.Signature, msgHash: starknet.BigNumberish, fullPublicKey: Uint8Array | string): boolean;
332
+ declare function verify(signature: starknet.Signature, msgHash: starknet.BigNumberish, fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[], options?: Falcon512Options): boolean;
240
333
  /**
241
334
  * Checks a SNIP-12 message signed by a Falcon-512 account. Same shapes as
242
- * `typedData.verifyMessage`.
335
+ * `typedData.verifyMessage`, with the options of `falcon512.verify` at the end.
243
336
  * @param {BigNumberish | TypedData} message a TypedData message, or its hash (SNIP-12)
244
- * @param {Signature} signature the 61 felts of a Falcon-512 signature
245
- * @param {Uint8Array | string} fullPublicKey NIST Falcon-512 public key (897 bytes), as returned by
246
- * `getPubKey()`
247
- * @param {BigNumberish} [accountAddress] address of the account that signed the message. Needed
248
- * only when `message` is a TypedData
337
+ * @param {Signature} signature the felts of a Falcon-512 signature: 61 (S2morrow), 60
338
+ * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)
339
+ * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the NIST Falcon-512 key (897 bytes,
340
+ * as returned by `getPubKey()`), or the 29 felts of the packed key
341
+ * @param {BigNumberish} accountAddress address of the account that signed the message, required
342
+ * when `message` is a TypedData. With a hash, there is no address: the options come in its place
343
+ * @param {Falcon512Options} [options] `accountType`, as for `falcon512.verify`
249
344
  * @returns {boolean} true if the message is verified
250
- * @throws {Error} when `message` is a TypedData and accountAddress is missing, or when the public
251
- * key is invalid
345
+ * @throws {Error} when `message` is a TypedData and the account address is missing, or when the
346
+ * public key or an option is invalid
252
347
  * @example
253
348
  * ```typescript
254
349
  * const signature = await mySigner.signMessage(myTypedData, accountAddress);
@@ -256,10 +351,15 @@ declare function verify(signature: starknet.Signature, msgHash: starknet.BigNumb
256
351
  * const result1 = falcon512.verifyMessage(myTypedData, signature, publicKey, accountAddress);
257
352
  * const result2 = falcon512.verifyMessage(msgHash, signature, publicKey);
258
353
  * // result1 = result2 = true
354
+ * const ozSignature = await myOzSigner.signMessage(myTypedData, accountAddress);
355
+ * const options = { accountType: 'oz-direct' } as const;
356
+ * const result3 = falcon512.verifyMessage(myTypedData, ozSignature, publicKey, accountAddress, options);
357
+ * const result4 = falcon512.verifyMessage(msgHash, ozSignature, publicKey, options);
358
+ * // result3 = result4 = true (myOzSigner built with { accountType: 'oz-direct' })
259
359
  * ```
260
360
  */
261
- declare function verifyMessage(message: starknet.TypedData, signature: starknet.Signature, fullPublicKey: Uint8Array | string, accountAddress: starknet.BigNumberish): boolean;
262
- declare function verifyMessage(message: starknet.BigNumberish, signature: starknet.Signature, fullPublicKey: Uint8Array | string): boolean;
361
+ declare function verifyMessage(message: starknet.TypedData, signature: starknet.Signature, fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[], accountAddress: starknet.BigNumberish, options?: Falcon512Options): boolean;
362
+ declare function verifyMessage(message: starknet.BigNumberish, signature: starknet.Signature, fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[], options?: Falcon512Options): boolean;
263
363
 
264
364
  type Falcon512KeyPair = {
265
365
  secretKey: Uint8Array;
@@ -358,4 +458,4 @@ declare namespace falcon512 {
358
458
  }
359
459
 
360
460
  export { Falcon512Signer, falcon512 };
361
- export type { Falcon512KeyPair };
461
+ export type { Falcon512AccountType, Falcon512KeyPair, Falcon512Options };