@aztec-labs/stdlib 7.0.0-nightly.20261116 → 7.0.0-nightly.20261118
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/dest/abi/buffer.d.ts +11 -1
- package/dest/abi/buffer.d.ts.map +1 -1
- package/dest/abi/buffer.js +18 -6
- package/dest/keys/derivation.d.ts +12 -1
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +30 -1
- package/dest/keys/index.d.ts +2 -1
- package/dest/keys/index.d.ts.map +1 -1
- package/dest/keys/index.js +1 -0
- package/dest/keys/post_quantum_public_key.d.ts +39 -0
- package/dest/keys/post_quantum_public_key.d.ts.map +1 -0
- package/dest/keys/post_quantum_public_key.js +57 -0
- package/dest/logs/messaging_secret.d.ts +10 -17
- package/dest/logs/messaging_secret.d.ts.map +1 -1
- package/dest/logs/messaging_secret.js +10 -17
- package/package.json +6 -5
- package/src/abi/buffer.ts +22 -9
- package/src/keys/derivation.ts +31 -1
- package/src/keys/index.ts +1 -0
- package/src/keys/post_quantum_public_key.ts +75 -0
- package/src/logs/messaging_secret.ts +10 -16
package/dest/abi/buffer.d.ts
CHANGED
|
@@ -28,4 +28,14 @@ export declare function bufferAsFields(input: Buffer, targetLength: number): Fr[
|
|
|
28
28
|
* @returns A buffer of exactly `byteLength` bytes.
|
|
29
29
|
*/
|
|
30
30
|
export declare function bufferFromFields(fields: Fr[], maxByteLength?: number): Buffer;
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Splits a buffer into 31-byte chunks and stores each in a field, omitting the field's first byte so that it fits. The
|
|
33
|
+
* last chunk holds the remaining bytes, followed by zeros.
|
|
34
|
+
*/
|
|
35
|
+
export declare function bufferToFieldChunks(input: Buffer): Fr[];
|
|
36
|
+
/**
|
|
37
|
+
* Concatenates the 31-byte chunks {@link bufferToFieldChunks} stores in fields, ignoring each field's first byte. The
|
|
38
|
+
* result is 31 bytes per field, so it ends with the zeros that pad the last chunk.
|
|
39
|
+
*/
|
|
40
|
+
export declare function bufferFromFieldChunks(fields: Fr[]): Buffer;
|
|
41
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVmZmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYWJpL2J1ZmZlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDekQsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLFFBQVEsQ0FBQztBQUdoQzs7Ozs7O0dBTUc7QUFDSCx3QkFBZ0IsY0FBYyxDQUFDLEtBQUssRUFBRSxNQUFNLEVBQUUsWUFBWSxFQUFFLE1BQU0sR0FBRyxFQUFFLEVBQUUsQ0FPeEU7QUFFRDs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBa0JHO0FBQ0gsd0JBQWdCLGdCQUFnQixDQUFDLE1BQU0sRUFBRSxFQUFFLEVBQUUsRUFBRSxhQUFhLENBQUMsRUFBRSxNQUFNLEdBQUcsTUFBTSxDQXNCN0U7QUFFRDs7O0dBR0c7QUFDSCx3QkFBZ0IsbUJBQW1CLENBQUMsS0FBSyxFQUFFLE1BQU0sR0FBRyxFQUFFLEVBQUUsQ0FNdkQ7QUFFRDs7O0dBR0c7QUFDSCx3QkFBZ0IscUJBQXFCLENBQUMsTUFBTSxFQUFFLEVBQUUsRUFBRSxHQUFHLE1BQU0sQ0FFMUQifQ==
|
package/dest/abi/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/abi/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/abi/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,EAAE,EAAE,CAOxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAsB7E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,CAMvD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,CAE1D"}
|
package/dest/abi/buffer.js
CHANGED
|
@@ -10,11 +10,7 @@ import chunk from 'lodash.chunk';
|
|
|
10
10
|
*/ export function bufferAsFields(input, targetLength) {
|
|
11
11
|
const encoded = [
|
|
12
12
|
new Fr(input.length),
|
|
13
|
-
...
|
|
14
|
-
const fieldBytes = Buffer.alloc(Fr.SIZE_IN_BYTES);
|
|
15
|
-
Buffer.from(c).copy(fieldBytes, 1);
|
|
16
|
-
return Fr.fromBuffer(fieldBytes);
|
|
17
|
-
})
|
|
13
|
+
...bufferToFieldChunks(input)
|
|
18
14
|
];
|
|
19
15
|
if (encoded.length > targetLength) {
|
|
20
16
|
throw new Error(`Input buffer exceeds maximum size: got ${encoded.length} but max is ${targetLength}`);
|
|
@@ -54,7 +50,7 @@ import chunk from 'lodash.chunk';
|
|
|
54
50
|
if (maxByteLength !== undefined && byteLength > maxByteLength) {
|
|
55
51
|
throw new Error(`Declared byte length ${byteLength} exceeds maximum ${maxByteLength}`);
|
|
56
52
|
}
|
|
57
|
-
const raw =
|
|
53
|
+
const raw = bufferFromFieldChunks(payload);
|
|
58
54
|
if (raw.length >= byteLength) {
|
|
59
55
|
return raw.subarray(0, byteLength);
|
|
60
56
|
}
|
|
@@ -66,3 +62,19 @@ import chunk from 'lodash.chunk';
|
|
|
66
62
|
raw.copy(result);
|
|
67
63
|
return result;
|
|
68
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Splits a buffer into 31-byte chunks and stores each in a field, omitting the field's first byte so that it fits. The
|
|
67
|
+
* last chunk holds the remaining bytes, followed by zeros.
|
|
68
|
+
*/ export function bufferToFieldChunks(input) {
|
|
69
|
+
return chunk(input, Fr.SIZE_IN_BYTES - 1).map((c)=>{
|
|
70
|
+
const fieldBytes = Buffer.alloc(Fr.SIZE_IN_BYTES);
|
|
71
|
+
Buffer.from(c).copy(fieldBytes, 1);
|
|
72
|
+
return Fr.fromBuffer(fieldBytes);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Concatenates the 31-byte chunks {@link bufferToFieldChunks} stores in fields, ignoring each field's first byte. The
|
|
77
|
+
* result is 31 bytes per field, so it ends with the zeros that pad the last chunk.
|
|
78
|
+
*/ export function bufferFromFieldChunks(fields) {
|
|
79
|
+
return Buffer.concat(fields.map((f)=>f.toBuffer().subarray(1)));
|
|
80
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Fq, Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
2
|
import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
3
4
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
4
5
|
import type { KeyPrefix } from './key_types.js';
|
|
6
|
+
import { PostQuantumPublicKey } from './post_quantum_public_key.js';
|
|
5
7
|
import { PublicKey } from './public_key.js';
|
|
6
8
|
import { PublicKeys } from './public_keys.js';
|
|
7
9
|
export declare function computeAppNullifierHidingKey(masterNullifierHidingSecretKey: GrumpkinScalar, app: AztecAddress): Promise<Fr>;
|
|
@@ -14,6 +16,15 @@ export declare function deriveMasterIncomingViewingSecretKey(secretKey: Fr): Gru
|
|
|
14
16
|
export declare function deriveMasterOutgoingViewingSecretKey(secretKey: Fr): GrumpkinScalar;
|
|
15
17
|
export declare function deriveMasterMessageSigningSecretKey(secretKey: Fr): GrumpkinScalar;
|
|
16
18
|
export declare function deriveMasterFallbackSecretKey(secretKey: Fr): GrumpkinScalar;
|
|
19
|
+
/**
|
|
20
|
+
* Derives an account's post-quantum key pair, an ML-KEM-768 one, from its master tagging secret key.
|
|
21
|
+
*
|
|
22
|
+
* The pair is deterministic, so it needs no backup: anyone holding the account's privacy keys derives the same pair.
|
|
23
|
+
*/
|
|
24
|
+
export declare function derivePostQuantumKeyPair(masterTaggingSecretKey: GrumpkinScalar): {
|
|
25
|
+
publicKey: PostQuantumPublicKey;
|
|
26
|
+
secretKey: Buffer;
|
|
27
|
+
};
|
|
17
28
|
export declare function computePreaddress(publicKeysHash: Fr, partialAddress: Fr): Promise<Fr>;
|
|
18
29
|
export declare function computeAddress(publicKeys: PublicKeys, partialAddress: Fr): Promise<AztecAddress>;
|
|
19
30
|
export declare function computeAddressSecret(preaddress: Fr, ivsk: Fq): Promise<Fq>;
|
|
@@ -67,4 +78,4 @@ export declare function deriveKeysFromMasterSecretKeys(secretKeys: MasterSecretK
|
|
|
67
78
|
masterFallbackPublicKey: import("@aztec-labs/foundation/curves/grumpkin").Point;
|
|
68
79
|
publicKeys: PublicKeys;
|
|
69
80
|
}>;
|
|
70
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
81
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVyaXZhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3J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ztJQUMvQyw4QkFBOEIsRUFBRSxjQUFjLENBQUM7SUFDL0MsOEJBQThCLEVBQUUsY0FBYyxDQUFDO0lBQy9DLHNCQUFzQixFQUFFLGNBQWMsQ0FBQztJQUN2Qyw2QkFBNkIsRUFBRSxjQUFjLENBQUM7SUFDOUMsdUJBQXVCLEVBQUUsY0FBYyxDQUFDO0NBQ3pDLENBQUM7QUFFRjs7OztHQUlHO0FBQ0gsd0JBQWdCLFVBQVUsQ0FBQyxTQUFTLEVBQUUsRUFBRTs7Ozs7Ozs7Ozs7OztHQVd2QztBQUVEOzs7O0dBSUc7QUFDSCx3QkFBc0IsOEJBQThCLENBQUMsVUFBVSxFQUFFLGdCQUFnQjs7Ozs7Ozs7Ozs7OztHQTRDaEYifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../src/keys/derivation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../src/keys/derivation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAGxE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAS9C,wBAAgB,4BAA4B,CAC1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,SAAS,CAAC,CAO9E;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,8BAA8B,EAAE,cAAc,CAAC;IAC/C,8BAA8B,EAAE,cAAc,CAAC;IAC/C,8BAA8B,EAAE,cAAc,CAAC;IAC/C,sBAAsB,EAAE,cAAc,CAAC;IACvC,6BAA6B,EAAE,cAAc,CAAC;IAC9C,uBAAuB,EAAE,cAAc,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,EAAE;;;;;;;;;;;;;GAWvC;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAAC,UAAU,EAAE,gBAAgB;;;;;;;;;;;;;GA4ChF"}
|
package/dest/keys/derivation.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { DomainSeparator } from '@aztec-labs/constants';
|
|
2
2
|
import { Grumpkin } from '@aztec-labs/foundation/crypto/grumpkin';
|
|
3
3
|
import { poseidon2HashWithSeparator } from '@aztec-labs/foundation/crypto/poseidon';
|
|
4
|
-
import { sha512ToGrumpkinScalar } from '@aztec-labs/foundation/crypto/sha512';
|
|
4
|
+
import { sha512, sha512ToGrumpkinScalar } from '@aztec-labs/foundation/crypto/sha512';
|
|
5
5
|
import { Fq, Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
6
6
|
import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
|
|
7
|
+
import { serializeToBuffer } from '@aztec-labs/foundation/serialize';
|
|
8
|
+
import { ml_kem768 as mlKem768 } from '@noble/post-quantum/ml-kem.js';
|
|
9
|
+
import { Buffer } from 'buffer';
|
|
7
10
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
11
|
+
import { PostQuantumPublicKey } from './post_quantum_public_key.js';
|
|
8
12
|
import { PublicKey, hashPublicKey } from './public_key.js';
|
|
9
13
|
import { PublicKeys } from './public_keys.js';
|
|
10
14
|
import { getKeyGenerator } from './utils.js';
|
|
15
|
+
/**
|
|
16
|
+
* Domain separator for the seed of an account's post-quantum key pair, derived from its name like every domain
|
|
17
|
+
* separator.
|
|
18
|
+
*/ const DOM_SEP__POST_QUANTUM_KEY_PAIR_SEED = 3053071212;
|
|
11
19
|
export function computeAppNullifierHidingKey(masterNullifierHidingSecretKey, app) {
|
|
12
20
|
return computeAppSecretKey(masterNullifierHidingSecretKey, app, 'n'); // 'n' is the key prefix for nullifier hiding key
|
|
13
21
|
}
|
|
@@ -58,6 +66,27 @@ export function deriveMasterFallbackSecretKey(secretKey) {
|
|
|
58
66
|
DomainSeparator.FBSK_M
|
|
59
67
|
]);
|
|
60
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Derives an account's post-quantum key pair, an ML-KEM-768 one, from its master tagging secret key.
|
|
71
|
+
*
|
|
72
|
+
* The pair is deterministic, so it needs no backup: anyone holding the account's privacy keys derives the same pair.
|
|
73
|
+
*/ export function derivePostQuantumKeyPair(masterTaggingSecretKey) {
|
|
74
|
+
// TODO(F-961): handle this pair like the other master keys: with wallets deriving it as they see fit (e.g. from the
|
|
75
|
+
// account's secret key) and then handing it to PXE's key store. It is derived from `tsk_m` for now because PXE
|
|
76
|
+
// already holds every account's `tsk_m`, so it can derive any account's pair itself, including accounts in stores
|
|
77
|
+
// written by earlier PXE versions (before this key existed), with no store migration. The derivation is safe, since
|
|
78
|
+
// `tpk_m` is only ever shared as a hash and so a post-quantum attacker cannot recover `tsk_m`, but less flexible,
|
|
79
|
+
// since wallets cannot choose how the pair is derived.
|
|
80
|
+
const seed = sha512(serializeToBuffer([
|
|
81
|
+
masterTaggingSecretKey,
|
|
82
|
+
DOM_SEP__POST_QUANTUM_KEY_PAIR_SEED
|
|
83
|
+
]));
|
|
84
|
+
const { publicKey, secretKey } = mlKem768.keygen(seed);
|
|
85
|
+
return {
|
|
86
|
+
publicKey: PostQuantumPublicKey.fromBuffer(Buffer.from(publicKey)),
|
|
87
|
+
secretKey: Buffer.from(secretKey)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
61
90
|
export function computePreaddress(publicKeysHash, partialAddress) {
|
|
62
91
|
return poseidon2HashWithSeparator([
|
|
63
92
|
publicKeysHash,
|
package/dest/keys/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './derivation.js';
|
|
2
|
+
export * from './post_quantum_public_key.js';
|
|
2
3
|
export * from './key_types.js';
|
|
3
4
|
export * from './utils.js';
|
|
4
5
|
export * from './public_key.js';
|
|
5
6
|
export * from './public_keys.js';
|
|
6
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9rZXlzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyw4QkFBOEIsQ0FBQztBQUM3QyxjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsWUFBWSxDQUFDO0FBQzNCLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyxrQkFBa0IsQ0FBQyJ9
|
package/dest/keys/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
package/dest/keys/index.js
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
/**
|
|
4
|
+
* An account's post-quantum public key.
|
|
5
|
+
*
|
|
6
|
+
* It is an ML-KEM-768 public key, which senders encapsulate to in order to establish a post-quantum shared secret with
|
|
7
|
+
* the account. Unlike their elliptic curve key, which is their address point, accounts have no native post-quantum
|
|
8
|
+
* public key, so they register theirs in the post-quantum public key registry for senders to learn it.
|
|
9
|
+
*
|
|
10
|
+
* TypeScript counterpart of aztec-nr's `PostQuantumPublicKey`, whose fields are this key's
|
|
11
|
+
* {@link PostQuantumPublicKey.toFields} encoding.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PostQuantumPublicKey {
|
|
14
|
+
private readonly key;
|
|
15
|
+
/** Byte length of an ML-KEM-768 public key. */
|
|
16
|
+
static readonly SIZE_IN_BYTES: number;
|
|
17
|
+
/** Length of the {@link PostQuantumPublicKey.toFields} encoding: one field per 31-byte chunk of the key. */
|
|
18
|
+
static readonly SIZE_IN_FIELDS: number;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Wraps the raw bytes of an ML-KEM-768 public key.
|
|
22
|
+
*
|
|
23
|
+
* @throws If `buffer` is not {@link PostQuantumPublicKey.SIZE_IN_BYTES} bytes long.
|
|
24
|
+
*/
|
|
25
|
+
static fromBuffer(buffer: Buffer): PostQuantumPublicKey;
|
|
26
|
+
/**
|
|
27
|
+
* Decodes a key from its {@link PostQuantumPublicKey.toFields} encoding.
|
|
28
|
+
*
|
|
29
|
+
* @throws If `fields` is not the {@link PostQuantumPublicKey.toFields} encoding of a key.
|
|
30
|
+
*/
|
|
31
|
+
static fromFields(fields: Fr[]): PostQuantumPublicKey;
|
|
32
|
+
toBuffer(): Buffer;
|
|
33
|
+
/**
|
|
34
|
+
* Encodes the key as {@link PostQuantumPublicKey.SIZE_IN_FIELDS} fields, the layout aztec-nr's `PostQuantumPublicKey`
|
|
35
|
+
* holds.
|
|
36
|
+
*/
|
|
37
|
+
toFields(): Fr[];
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicG9zdF9xdWFudHVtX3B1YmxpY19rZXkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9rZXlzL3Bvc3RfcXVhbnR1bV9wdWJsaWNfa2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxxQ0FBcUMsQ0FBQztBQUV6RCxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sUUFBUSxDQUFDO0FBSWhDOzs7Ozs7Ozs7R0FTRztBQUNILHFCQUFhLG9CQUFvQjtJQU1YLE9BQU8sQ0FBQyxRQUFRLENBQUMsR0FBRztJQUx4QywrQ0FBK0M7SUFDL0MsTUFBTSxDQUFDLFFBQVEsQ0FBQyxhQUFhLFNBQStCO0lBQzVELDRHQUE0RztJQUM1RyxNQUFNLENBQUMsUUFBUSxDQUFDLGNBQWMsU0FBMEU7SUFFeEcsT0FBTyxlQUE2QztJQUVwRDs7OztPQUlHO0lBQ0gsTUFBTSxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUUsTUFBTSxHQUFHLG9CQUFvQixDQU90RDtJQUVEOzs7O09BSUc7SUFDSCxNQUFNLENBQUMsVUFBVSxDQUFDLE1BQU0sRUFBRSxFQUFFLEVBQUUsR0FBRyxvQkFBb0IsQ0FrQnBEO0lBRUQsUUFBUSxJQUFJLE1BQU0sQ0FFakI7SUFFRDs7O09BR0c7SUFDSCxRQUFRLElBQUksRUFBRSxFQUFFLENBRWY7Q0FDRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post_quantum_public_key.d.ts","sourceRoot":"","sources":["../../src/keys/post_quantum_public_key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAMX,OAAO,CAAC,QAAQ,CAAC,GAAG;IALxC,+CAA+C;IAC/C,MAAM,CAAC,QAAQ,CAAC,aAAa,SAA+B;IAC5D,4GAA4G;IAC5G,MAAM,CAAC,QAAQ,CAAC,cAAc,SAA0E;IAExG,OAAO,eAA6C;IAEpD;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAOtD;IAED;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,oBAAoB,CAkBpD;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,QAAQ,IAAI,EAAE,EAAE,CAEf;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { ml_kem768 as mlKem768 } from '@noble/post-quantum/ml-kem.js';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { bufferFromFieldChunks, bufferToFieldChunks } from '../abi/buffer.js';
|
|
5
|
+
/**
|
|
6
|
+
* An account's post-quantum public key.
|
|
7
|
+
*
|
|
8
|
+
* It is an ML-KEM-768 public key, which senders encapsulate to in order to establish a post-quantum shared secret with
|
|
9
|
+
* the account. Unlike their elliptic curve key, which is their address point, accounts have no native post-quantum
|
|
10
|
+
* public key, so they register theirs in the post-quantum public key registry for senders to learn it.
|
|
11
|
+
*
|
|
12
|
+
* TypeScript counterpart of aztec-nr's `PostQuantumPublicKey`, whose fields are this key's
|
|
13
|
+
* {@link PostQuantumPublicKey.toFields} encoding.
|
|
14
|
+
*/ export class PostQuantumPublicKey {
|
|
15
|
+
key;
|
|
16
|
+
/** Byte length of an ML-KEM-768 public key. */ static SIZE_IN_BYTES = mlKem768.lengths.publicKey;
|
|
17
|
+
/** Length of the {@link PostQuantumPublicKey.toFields} encoding: one field per 31-byte chunk of the key. */ static SIZE_IN_FIELDS = Math.ceil(PostQuantumPublicKey.SIZE_IN_BYTES / (Fr.SIZE_IN_BYTES - 1));
|
|
18
|
+
constructor(key){
|
|
19
|
+
this.key = key;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Wraps the raw bytes of an ML-KEM-768 public key.
|
|
23
|
+
*
|
|
24
|
+
* @throws If `buffer` is not {@link PostQuantumPublicKey.SIZE_IN_BYTES} bytes long.
|
|
25
|
+
*/ static fromBuffer(buffer) {
|
|
26
|
+
if (buffer.length !== PostQuantumPublicKey.SIZE_IN_BYTES) {
|
|
27
|
+
throw new Error(`A post-quantum public key is ${PostQuantumPublicKey.SIZE_IN_BYTES} bytes long, got ${buffer.length} bytes`);
|
|
28
|
+
}
|
|
29
|
+
return new PostQuantumPublicKey(Buffer.from(buffer));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decodes a key from its {@link PostQuantumPublicKey.toFields} encoding.
|
|
33
|
+
*
|
|
34
|
+
* @throws If `fields` is not the {@link PostQuantumPublicKey.toFields} encoding of a key.
|
|
35
|
+
*/ static fromFields(fields) {
|
|
36
|
+
if (fields.length !== PostQuantumPublicKey.SIZE_IN_FIELDS) {
|
|
37
|
+
throw new Error(`A post-quantum public key is encoded in ${PostQuantumPublicKey.SIZE_IN_FIELDS} fields, got ${fields.length}`);
|
|
38
|
+
}
|
|
39
|
+
const key = PostQuantumPublicKey.fromBuffer(bufferFromFieldChunks(fields).subarray(0, PostQuantumPublicKey.SIZE_IN_BYTES));
|
|
40
|
+
// Decoding ignores each field's top byte, and the last field's bytes past the end of the key, so a field with bits
|
|
41
|
+
// set there decodes to the same key as a well-formed encoding. Re-encoding the key and comparing catches it.
|
|
42
|
+
const index = key.toFields().findIndex((field, i)=>!field.equals(fields[i]));
|
|
43
|
+
if (index !== -1) {
|
|
44
|
+
throw new Error(`Field ${index} of a post-quantum public key encoding holds bits outside the key: ${fields[index]}`);
|
|
45
|
+
}
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
toBuffer() {
|
|
49
|
+
return Buffer.from(this.key);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Encodes the key as {@link PostQuantumPublicKey.SIZE_IN_FIELDS} fields, the layout aztec-nr's `PostQuantumPublicKey`
|
|
53
|
+
* holds.
|
|
54
|
+
*/ toFields() {
|
|
55
|
+
return bufferToFieldChunks(this.key);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -27,11 +27,9 @@ import { OnchainDeliveryMode } from './onchain_delivery_mode.js';
|
|
|
27
27
|
* - **Arbitrary secret** ({@link computeFromArbitrarySecret}): the raw secret is a point the two parties agreed on
|
|
28
28
|
* themselves. It is app-siloed and directed to `recipient`. It only backs unconstrained delivery.
|
|
29
29
|
* - **Handshake** ({@link computeFromHandshakeSecret}): the raw secret is the point the handshake registry stores for
|
|
30
|
-
* the pair. It is app-siloed, and backs both delivery modes.
|
|
31
|
-
* secret from the point for the calling contract.
|
|
30
|
+
* the pair. It is app-siloed, and backs both delivery modes.
|
|
32
31
|
* - **Recipient tsk** ({@link computeFromRecipientTsk}): the raw secret is the recipient's master tagging secret key
|
|
33
|
-
* `tsk_m`. It is app-siloed into `tsk_app` and
|
|
34
|
-
* kernel can validate `tsk_app`, by recomputing it from `tsk_m` for the calling contract.
|
|
32
|
+
* `tsk_m`. It is app-siloed into `tsk_app` and hashed with `recipient`'s address, and backs both delivery modes.
|
|
35
33
|
*
|
|
36
34
|
* ## From messaging secret to tag
|
|
37
35
|
*
|
|
@@ -46,8 +44,9 @@ import { OnchainDeliveryMode } from './onchain_delivery_mode.js';
|
|
|
46
44
|
*
|
|
47
45
|
* The first two are computed by the contract and the last one by the kernel, and `siloedTag` is what appears onchain.
|
|
48
46
|
*
|
|
49
|
-
* The separator depends on the delivery mode because a handshake secret backs both, each with its own
|
|
50
|
-
* Mechanisms need no separators of their own at this step, as different derivations already yield
|
|
47
|
+
* The separator depends on the delivery mode because a handshake or recipient tsk secret backs both, each with its own
|
|
48
|
+
* index sequence. Mechanisms need no separators of their own at this step, as different derivations already yield
|
|
49
|
+
* different secrets.
|
|
51
50
|
*/
|
|
52
51
|
export declare class MessagingSecret {
|
|
53
52
|
#private;
|
|
@@ -58,9 +57,6 @@ export declare class MessagingSecret {
|
|
|
58
57
|
/**
|
|
59
58
|
* Derives the messaging secret for an arbitrary shared secret point.
|
|
60
59
|
*
|
|
61
|
-
* The secret is app-siloed and directed to `recipient`, for unconstrained delivery. The sender and the recipient
|
|
62
|
-
* agree on the point themselves.
|
|
63
|
-
*
|
|
64
60
|
* @param sharedSecretPoint - The shared secret point
|
|
65
61
|
* @param app - Contract address to silo the secret to
|
|
66
62
|
* @param recipient - Recipient of the log. Defines the "direction of the secret".
|
|
@@ -77,8 +73,7 @@ export declare class MessagingSecret {
|
|
|
77
73
|
/**
|
|
78
74
|
* Derives the messaging secret two addresses share through ECDH.
|
|
79
75
|
*
|
|
80
|
-
*
|
|
81
|
-
* secret using its own keys as the local side of the exchange.
|
|
76
|
+
* Each party derives the same secret using its own keys as the local side of the exchange.
|
|
82
77
|
*
|
|
83
78
|
* @returns The secret, or undefined if `externalAddress` is not a valid address.
|
|
84
79
|
*/
|
|
@@ -97,12 +92,10 @@ export declare class MessagingSecret {
|
|
|
97
92
|
/**
|
|
98
93
|
* Derives the messaging secret from the recipient's tagging secret key.
|
|
99
94
|
*
|
|
100
|
-
* The secret is the recipient's app-siloed tagging key hashed with their address,
|
|
101
|
-
* in the address gives accounts that share a tagging key separate tag streams.
|
|
102
|
-
* recipient alone, so whoever sends the log has to know `recipientTsk`, and the recipient finds the log without
|
|
103
|
-
* knowing who sent it.
|
|
95
|
+
* The secret is the recipient's app-siloed tagging key hashed with their address, under the given delivery mode.
|
|
96
|
+
* Hashing in the address gives accounts that share a tagging key separate tag streams.
|
|
104
97
|
*/
|
|
105
|
-
static computeFromRecipientTsk(recipientTsk: Fq, app: AztecAddress, recipient: AztecAddress): Promise<MessagingSecret>;
|
|
98
|
+
static computeFromRecipientTsk(recipientTsk: Fq, app: AztecAddress, recipient: AztecAddress, deliveryMode: OnchainDeliveryMode): Promise<MessagingSecret>;
|
|
106
99
|
toString(): string;
|
|
107
100
|
static fromString(str: string): MessagingSecret;
|
|
108
101
|
}
|
|
@@ -144,4 +137,4 @@ export declare const AppTaggingSecretSchema: z.ZodPipe<z.ZodObject<{
|
|
|
144
137
|
export declare function computeAddressDerivedSharedSecretPoint(localAddress: CompleteAddress, localIvsk: Fq, externalAddress: AztecAddress): Promise<Point | undefined>;
|
|
145
138
|
/** @deprecated Use {@link computeAddressDerivedSharedSecretPoint}. */
|
|
146
139
|
export declare const computeSharedTaggingSecret: typeof computeAddressDerivedSharedSecretPoint;
|
|
147
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
140
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnaW5nX3NlY3JldC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2xvZ3MvbWVzc2FnaW5nX3NlY3JldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsS0FBSyxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDbEUsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sd0NBQXdDLENBQUM7QUFDcEUsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4QixPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDekQsT0FBTyxLQUFLLE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E9BQU8sQ0FBQyxLQUFLLEdBQUcsU0FBUyxDQUFDLENBZTVCO0FBRUQsc0VBQXNFO0FBQ3RFLGVBQU8sTUFBTSwwQkFBMEIsK0NBQXlDLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging_secret.d.ts","sourceRoot":"","sources":["../../src/logs/messaging_secret.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAWjE
|
|
1
|
+
{"version":3,"file":"messaging_secret.d.ts","sourceRoot":"","sources":["../../src/logs/messaging_secret.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAWjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,eAAe;;aAER,MAAM,EAAE,EAAE;aACV,GAAG,EAAE,YAAY;aACjB,YAAY,EAAE,mBAAmB;IAHnD,YACkB,MAAM,EAAE,EAAE,EACV,GAAG,EAAE,YAAY,EACjB,Y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,kCAA4B,CAAC;AAEpE,eAAO,MAAM,qBAAqB;;;;;;;;GAM6D,CAAC;AAEhG,qDAAqD;AACrD,eAAO,MAAM,sBAAsB;;;;;;;;GAAwB,CAAC;AAa5D;;;;;GAKG;AACH,wBAAsB,sCAAsC,CAC1D,YAAY,EAAE,eAAe,EAC7B,SAAS,EAAE,EAAE,EACb,eAAe,EAAE,YAAY,GAC5B,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAe5B;AAED,sEAAsE;AACtE,eAAO,MAAM,0BAA0B,+CAAyC,CAAC"}
|
|
@@ -34,11 +34,9 @@ const OnchainDeliveryModeSchema = z.union([
|
|
|
34
34
|
* - **Arbitrary secret** ({@link computeFromArbitrarySecret}): the raw secret is a point the two parties agreed on
|
|
35
35
|
* themselves. It is app-siloed and directed to `recipient`. It only backs unconstrained delivery.
|
|
36
36
|
* - **Handshake** ({@link computeFromHandshakeSecret}): the raw secret is the point the handshake registry stores for
|
|
37
|
-
* the pair. It is app-siloed, and backs both delivery modes.
|
|
38
|
-
* secret from the point for the calling contract.
|
|
37
|
+
* the pair. It is app-siloed, and backs both delivery modes.
|
|
39
38
|
* - **Recipient tsk** ({@link computeFromRecipientTsk}): the raw secret is the recipient's master tagging secret key
|
|
40
|
-
* `tsk_m`. It is app-siloed into `tsk_app` and
|
|
41
|
-
* kernel can validate `tsk_app`, by recomputing it from `tsk_m` for the calling contract.
|
|
39
|
+
* `tsk_m`. It is app-siloed into `tsk_app` and hashed with `recipient`'s address, and backs both delivery modes.
|
|
42
40
|
*
|
|
43
41
|
* ## From messaging secret to tag
|
|
44
42
|
*
|
|
@@ -53,8 +51,9 @@ const OnchainDeliveryModeSchema = z.union([
|
|
|
53
51
|
*
|
|
54
52
|
* The first two are computed by the contract and the last one by the kernel, and `siloedTag` is what appears onchain.
|
|
55
53
|
*
|
|
56
|
-
* The separator depends on the delivery mode because a handshake secret backs both, each with its own
|
|
57
|
-
* Mechanisms need no separators of their own at this step, as different derivations already yield
|
|
54
|
+
* The separator depends on the delivery mode because a handshake or recipient tsk secret backs both, each with its own
|
|
55
|
+
* index sequence. Mechanisms need no separators of their own at this step, as different derivations already yield
|
|
56
|
+
* different secrets.
|
|
58
57
|
*/ export class MessagingSecret {
|
|
59
58
|
secret;
|
|
60
59
|
app;
|
|
@@ -67,9 +66,6 @@ const OnchainDeliveryModeSchema = z.union([
|
|
|
67
66
|
/**
|
|
68
67
|
* Derives the messaging secret for an arbitrary shared secret point.
|
|
69
68
|
*
|
|
70
|
-
* The secret is app-siloed and directed to `recipient`, for unconstrained delivery. The sender and the recipient
|
|
71
|
-
* agree on the point themselves.
|
|
72
|
-
*
|
|
73
69
|
* @param sharedSecretPoint - The shared secret point
|
|
74
70
|
* @param app - Contract address to silo the secret to
|
|
75
71
|
* @param recipient - Recipient of the log. Defines the "direction of the secret".
|
|
@@ -88,8 +84,7 @@ const OnchainDeliveryModeSchema = z.union([
|
|
|
88
84
|
/**
|
|
89
85
|
* Derives the messaging secret two addresses share through ECDH.
|
|
90
86
|
*
|
|
91
|
-
*
|
|
92
|
-
* secret using its own keys as the local side of the exchange.
|
|
87
|
+
* Each party derives the same secret using its own keys as the local side of the exchange.
|
|
93
88
|
*
|
|
94
89
|
* @returns The secret, or undefined if `externalAddress` is not a valid address.
|
|
95
90
|
*/ static async computeAddressDerived({ localAddress, localIvsk, externalAddress, app, recipient }) {
|
|
@@ -102,17 +97,15 @@ const OnchainDeliveryModeSchema = z.union([
|
|
|
102
97
|
/**
|
|
103
98
|
* Derives the messaging secret from the recipient's tagging secret key.
|
|
104
99
|
*
|
|
105
|
-
* The secret is the recipient's app-siloed tagging key hashed with their address,
|
|
106
|
-
* in the address gives accounts that share a tagging key separate tag streams.
|
|
107
|
-
|
|
108
|
-
* knowing who sent it.
|
|
109
|
-
*/ static async computeFromRecipientTsk(recipientTsk, app, recipient) {
|
|
100
|
+
* The secret is the recipient's app-siloed tagging key hashed with their address, under the given delivery mode.
|
|
101
|
+
* Hashing in the address gives accounts that share a tagging key separate tag streams.
|
|
102
|
+
*/ static async computeFromRecipientTsk(recipientTsk, app, recipient, deliveryMode) {
|
|
110
103
|
const tskApp = await computeAppTaggingSecretKey(recipientTsk, app);
|
|
111
104
|
const secret = await poseidon2HashWithSeparator([
|
|
112
105
|
tskApp,
|
|
113
106
|
recipient
|
|
114
107
|
], DOM_SEP__RECIPIENT_TSK_SECRET);
|
|
115
|
-
return new MessagingSecret(secret, app,
|
|
108
|
+
return new MessagingSecret(secret, app, deliveryMode);
|
|
116
109
|
}
|
|
117
110
|
toString() {
|
|
118
111
|
return `${this.deliveryMode}:${this.secret.toString()}:${this.app.toString()}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec-labs/stdlib",
|
|
3
|
-
"version": "7.0.0-nightly.
|
|
3
|
+
"version": "7.0.0-nightly.20261118",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -94,11 +94,12 @@
|
|
|
94
94
|
"@aws-sdk/client-s3": "^3.892.0",
|
|
95
95
|
"@aztec-foundation/bb.js": "7.0.0-nightly.20261110",
|
|
96
96
|
"@aztec-foundation/noir-noirc_abi": "7.0.0-nightly.20261110",
|
|
97
|
-
"@aztec-labs/blob-lib": "7.0.0-nightly.
|
|
98
|
-
"@aztec-labs/constants": "7.0.0-nightly.
|
|
99
|
-
"@aztec-labs/ethereum": "7.0.0-nightly.
|
|
100
|
-
"@aztec-labs/foundation": "7.0.0-nightly.
|
|
97
|
+
"@aztec-labs/blob-lib": "7.0.0-nightly.20261118",
|
|
98
|
+
"@aztec-labs/constants": "7.0.0-nightly.20261118",
|
|
99
|
+
"@aztec-labs/ethereum": "7.0.0-nightly.20261118",
|
|
100
|
+
"@aztec-labs/foundation": "7.0.0-nightly.20261118",
|
|
101
101
|
"@google-cloud/storage": "^7.15.0",
|
|
102
|
+
"@noble/post-quantum": "0.7.1",
|
|
102
103
|
"axios": "^1.15.1",
|
|
103
104
|
"buffer": "^6.0.3",
|
|
104
105
|
"json-stringify-deterministic": "1.0.12",
|
package/src/abi/buffer.ts
CHANGED
|
@@ -10,14 +10,7 @@ import chunk from 'lodash.chunk';
|
|
|
10
10
|
* @returns A field with the total length in bytes, followed by an array of fields such that their concatenation is equal to the input buffer, followed by enough zeroes to reach targetLength.
|
|
11
11
|
*/
|
|
12
12
|
export function bufferAsFields(input: Buffer, targetLength: number): Fr[] {
|
|
13
|
-
const encoded = [
|
|
14
|
-
new Fr(input.length),
|
|
15
|
-
...chunk(input, Fr.SIZE_IN_BYTES - 1).map(c => {
|
|
16
|
-
const fieldBytes = Buffer.alloc(Fr.SIZE_IN_BYTES);
|
|
17
|
-
Buffer.from(c).copy(fieldBytes, 1);
|
|
18
|
-
return Fr.fromBuffer(fieldBytes);
|
|
19
|
-
}),
|
|
20
|
-
];
|
|
13
|
+
const encoded = [new Fr(input.length), ...bufferToFieldChunks(input)];
|
|
21
14
|
if (encoded.length > targetLength) {
|
|
22
15
|
throw new Error(`Input buffer exceeds maximum size: got ${encoded.length} but max is ${targetLength}`);
|
|
23
16
|
}
|
|
@@ -55,7 +48,7 @@ export function bufferFromFields(fields: Fr[], maxByteLength?: number): Buffer {
|
|
|
55
48
|
if (maxByteLength !== undefined && byteLength > maxByteLength) {
|
|
56
49
|
throw new Error(`Declared byte length ${byteLength} exceeds maximum ${maxByteLength}`);
|
|
57
50
|
}
|
|
58
|
-
const raw =
|
|
51
|
+
const raw = bufferFromFieldChunks(payload);
|
|
59
52
|
if (raw.length >= byteLength) {
|
|
60
53
|
return raw.subarray(0, byteLength);
|
|
61
54
|
}
|
|
@@ -67,3 +60,23 @@ export function bufferFromFields(fields: Fr[], maxByteLength?: number): Buffer {
|
|
|
67
60
|
raw.copy(result);
|
|
68
61
|
return result;
|
|
69
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Splits a buffer into 31-byte chunks and stores each in a field, omitting the field's first byte so that it fits. The
|
|
66
|
+
* last chunk holds the remaining bytes, followed by zeros.
|
|
67
|
+
*/
|
|
68
|
+
export function bufferToFieldChunks(input: Buffer): Fr[] {
|
|
69
|
+
return chunk(input, Fr.SIZE_IN_BYTES - 1).map(c => {
|
|
70
|
+
const fieldBytes = Buffer.alloc(Fr.SIZE_IN_BYTES);
|
|
71
|
+
Buffer.from(c).copy(fieldBytes, 1);
|
|
72
|
+
return Fr.fromBuffer(fieldBytes);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Concatenates the 31-byte chunks {@link bufferToFieldChunks} stores in fields, ignoring each field's first byte. The
|
|
78
|
+
* result is 31 bytes per field, so it ends with the zeros that pad the last chunk.
|
|
79
|
+
*/
|
|
80
|
+
export function bufferFromFieldChunks(fields: Fr[]): Buffer {
|
|
81
|
+
return Buffer.concat(fields.map(f => f.toBuffer().subarray(1)));
|
|
82
|
+
}
|
package/src/keys/derivation.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { DomainSeparator } from '@aztec-labs/constants';
|
|
2
2
|
import { Grumpkin } from '@aztec-labs/foundation/crypto/grumpkin';
|
|
3
3
|
import { poseidon2HashWithSeparator } from '@aztec-labs/foundation/crypto/poseidon';
|
|
4
|
-
import { sha512ToGrumpkinScalar } from '@aztec-labs/foundation/crypto/sha512';
|
|
4
|
+
import { sha512, sha512ToGrumpkinScalar } from '@aztec-labs/foundation/crypto/sha512';
|
|
5
5
|
import { Fq, Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
6
6
|
import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
|
|
7
|
+
import { serializeToBuffer } from '@aztec-labs/foundation/serialize';
|
|
8
|
+
import { ml_kem768 as mlKem768 } from '@noble/post-quantum/ml-kem.js';
|
|
9
|
+
import { Buffer } from 'buffer';
|
|
7
10
|
|
|
8
11
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
9
12
|
import type { KeyPrefix } from './key_types.js';
|
|
13
|
+
import { PostQuantumPublicKey } from './post_quantum_public_key.js';
|
|
10
14
|
import { PublicKey, hashPublicKey } from './public_key.js';
|
|
11
15
|
import { PublicKeys } from './public_keys.js';
|
|
12
16
|
import { getKeyGenerator } from './utils.js';
|
|
13
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Domain separator for the seed of an account's post-quantum key pair, derived from its name like every domain
|
|
20
|
+
* separator.
|
|
21
|
+
*/
|
|
22
|
+
const DOM_SEP__POST_QUANTUM_KEY_PAIR_SEED = 3053071212;
|
|
23
|
+
|
|
14
24
|
export function computeAppNullifierHidingKey(
|
|
15
25
|
masterNullifierHidingSecretKey: GrumpkinScalar,
|
|
16
26
|
app: AztecAddress,
|
|
@@ -55,6 +65,26 @@ export function deriveMasterFallbackSecretKey(secretKey: Fr): GrumpkinScalar {
|
|
|
55
65
|
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.FBSK_M]);
|
|
56
66
|
}
|
|
57
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Derives an account's post-quantum key pair, an ML-KEM-768 one, from its master tagging secret key.
|
|
70
|
+
*
|
|
71
|
+
* The pair is deterministic, so it needs no backup: anyone holding the account's privacy keys derives the same pair.
|
|
72
|
+
*/
|
|
73
|
+
export function derivePostQuantumKeyPair(masterTaggingSecretKey: GrumpkinScalar): {
|
|
74
|
+
publicKey: PostQuantumPublicKey;
|
|
75
|
+
secretKey: Buffer;
|
|
76
|
+
} {
|
|
77
|
+
// TODO(F-961): handle this pair like the other master keys: with wallets deriving it as they see fit (e.g. from the
|
|
78
|
+
// account's secret key) and then handing it to PXE's key store. It is derived from `tsk_m` for now because PXE
|
|
79
|
+
// already holds every account's `tsk_m`, so it can derive any account's pair itself, including accounts in stores
|
|
80
|
+
// written by earlier PXE versions (before this key existed), with no store migration. The derivation is safe, since
|
|
81
|
+
// `tpk_m` is only ever shared as a hash and so a post-quantum attacker cannot recover `tsk_m`, but less flexible,
|
|
82
|
+
// since wallets cannot choose how the pair is derived.
|
|
83
|
+
const seed = sha512(serializeToBuffer([masterTaggingSecretKey, DOM_SEP__POST_QUANTUM_KEY_PAIR_SEED]));
|
|
84
|
+
const { publicKey, secretKey } = mlKem768.keygen(seed);
|
|
85
|
+
return { publicKey: PostQuantumPublicKey.fromBuffer(Buffer.from(publicKey)), secretKey: Buffer.from(secretKey) };
|
|
86
|
+
}
|
|
87
|
+
|
|
58
88
|
export function computePreaddress(publicKeysHash: Fr, partialAddress: Fr) {
|
|
59
89
|
return poseidon2HashWithSeparator([publicKeysHash, partialAddress], DomainSeparator.CONTRACT_ADDRESS_V3);
|
|
60
90
|
}
|
package/src/keys/index.ts
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { ml_kem768 as mlKem768 } from '@noble/post-quantum/ml-kem.js';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
|
|
5
|
+
import { bufferFromFieldChunks, bufferToFieldChunks } from '../abi/buffer.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An account's post-quantum public key.
|
|
9
|
+
*
|
|
10
|
+
* It is an ML-KEM-768 public key, which senders encapsulate to in order to establish a post-quantum shared secret with
|
|
11
|
+
* the account. Unlike their elliptic curve key, which is their address point, accounts have no native post-quantum
|
|
12
|
+
* public key, so they register theirs in the post-quantum public key registry for senders to learn it.
|
|
13
|
+
*
|
|
14
|
+
* TypeScript counterpart of aztec-nr's `PostQuantumPublicKey`, whose fields are this key's
|
|
15
|
+
* {@link PostQuantumPublicKey.toFields} encoding.
|
|
16
|
+
*/
|
|
17
|
+
export class PostQuantumPublicKey {
|
|
18
|
+
/** Byte length of an ML-KEM-768 public key. */
|
|
19
|
+
static readonly SIZE_IN_BYTES = mlKem768.lengths.publicKey!;
|
|
20
|
+
/** Length of the {@link PostQuantumPublicKey.toFields} encoding: one field per 31-byte chunk of the key. */
|
|
21
|
+
static readonly SIZE_IN_FIELDS = Math.ceil(PostQuantumPublicKey.SIZE_IN_BYTES / (Fr.SIZE_IN_BYTES - 1));
|
|
22
|
+
|
|
23
|
+
private constructor(private readonly key: Buffer) {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Wraps the raw bytes of an ML-KEM-768 public key.
|
|
27
|
+
*
|
|
28
|
+
* @throws If `buffer` is not {@link PostQuantumPublicKey.SIZE_IN_BYTES} bytes long.
|
|
29
|
+
*/
|
|
30
|
+
static fromBuffer(buffer: Buffer): PostQuantumPublicKey {
|
|
31
|
+
if (buffer.length !== PostQuantumPublicKey.SIZE_IN_BYTES) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`A post-quantum public key is ${PostQuantumPublicKey.SIZE_IN_BYTES} bytes long, got ${buffer.length} bytes`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return new PostQuantumPublicKey(Buffer.from(buffer));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Decodes a key from its {@link PostQuantumPublicKey.toFields} encoding.
|
|
41
|
+
*
|
|
42
|
+
* @throws If `fields` is not the {@link PostQuantumPublicKey.toFields} encoding of a key.
|
|
43
|
+
*/
|
|
44
|
+
static fromFields(fields: Fr[]): PostQuantumPublicKey {
|
|
45
|
+
if (fields.length !== PostQuantumPublicKey.SIZE_IN_FIELDS) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`A post-quantum public key is encoded in ${PostQuantumPublicKey.SIZE_IN_FIELDS} fields, got ${fields.length}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const key = PostQuantumPublicKey.fromBuffer(
|
|
51
|
+
bufferFromFieldChunks(fields).subarray(0, PostQuantumPublicKey.SIZE_IN_BYTES),
|
|
52
|
+
);
|
|
53
|
+
// Decoding ignores each field's top byte, and the last field's bytes past the end of the key, so a field with bits
|
|
54
|
+
// set there decodes to the same key as a well-formed encoding. Re-encoding the key and comparing catches it.
|
|
55
|
+
const index = key.toFields().findIndex((field, i) => !field.equals(fields[i]));
|
|
56
|
+
if (index !== -1) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Field ${index} of a post-quantum public key encoding holds bits outside the key: ${fields[index]}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return key;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toBuffer(): Buffer {
|
|
65
|
+
return Buffer.from(this.key);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Encodes the key as {@link PostQuantumPublicKey.SIZE_IN_FIELDS} fields, the layout aztec-nr's `PostQuantumPublicKey`
|
|
70
|
+
* holds.
|
|
71
|
+
*/
|
|
72
|
+
toFields(): Fr[] {
|
|
73
|
+
return bufferToFieldChunks(this.key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -41,11 +41,9 @@ const DOM_SEP__RECIPIENT_TSK_SECRET = 1256167324;
|
|
|
41
41
|
* - **Arbitrary secret** ({@link computeFromArbitrarySecret}): the raw secret is a point the two parties agreed on
|
|
42
42
|
* themselves. It is app-siloed and directed to `recipient`. It only backs unconstrained delivery.
|
|
43
43
|
* - **Handshake** ({@link computeFromHandshakeSecret}): the raw secret is the point the handshake registry stores for
|
|
44
|
-
* the pair. It is app-siloed, and backs both delivery modes.
|
|
45
|
-
* secret from the point for the calling contract.
|
|
44
|
+
* the pair. It is app-siloed, and backs both delivery modes.
|
|
46
45
|
* - **Recipient tsk** ({@link computeFromRecipientTsk}): the raw secret is the recipient's master tagging secret key
|
|
47
|
-
* `tsk_m`. It is app-siloed into `tsk_app` and
|
|
48
|
-
* kernel can validate `tsk_app`, by recomputing it from `tsk_m` for the calling contract.
|
|
46
|
+
* `tsk_m`. It is app-siloed into `tsk_app` and hashed with `recipient`'s address, and backs both delivery modes.
|
|
49
47
|
*
|
|
50
48
|
* ## From messaging secret to tag
|
|
51
49
|
*
|
|
@@ -60,8 +58,9 @@ const DOM_SEP__RECIPIENT_TSK_SECRET = 1256167324;
|
|
|
60
58
|
*
|
|
61
59
|
* The first two are computed by the contract and the last one by the kernel, and `siloedTag` is what appears onchain.
|
|
62
60
|
*
|
|
63
|
-
* The separator depends on the delivery mode because a handshake secret backs both, each with its own
|
|
64
|
-
* Mechanisms need no separators of their own at this step, as different derivations already yield
|
|
61
|
+
* The separator depends on the delivery mode because a handshake or recipient tsk secret backs both, each with its own
|
|
62
|
+
* index sequence. Mechanisms need no separators of their own at this step, as different derivations already yield
|
|
63
|
+
* different secrets.
|
|
65
64
|
*/
|
|
66
65
|
export class MessagingSecret {
|
|
67
66
|
constructor(
|
|
@@ -73,9 +72,6 @@ export class MessagingSecret {
|
|
|
73
72
|
/**
|
|
74
73
|
* Derives the messaging secret for an arbitrary shared secret point.
|
|
75
74
|
*
|
|
76
|
-
* The secret is app-siloed and directed to `recipient`, for unconstrained delivery. The sender and the recipient
|
|
77
|
-
* agree on the point themselves.
|
|
78
|
-
*
|
|
79
75
|
* @param sharedSecretPoint - The shared secret point
|
|
80
76
|
* @param app - Contract address to silo the secret to
|
|
81
77
|
* @param recipient - Recipient of the log. Defines the "direction of the secret".
|
|
@@ -106,8 +102,7 @@ export class MessagingSecret {
|
|
|
106
102
|
/**
|
|
107
103
|
* Derives the messaging secret two addresses share through ECDH.
|
|
108
104
|
*
|
|
109
|
-
*
|
|
110
|
-
* secret using its own keys as the local side of the exchange.
|
|
105
|
+
* Each party derives the same secret using its own keys as the local side of the exchange.
|
|
111
106
|
*
|
|
112
107
|
* @returns The secret, or undefined if `externalAddress` is not a valid address.
|
|
113
108
|
*/
|
|
@@ -140,20 +135,19 @@ export class MessagingSecret {
|
|
|
140
135
|
/**
|
|
141
136
|
* Derives the messaging secret from the recipient's tagging secret key.
|
|
142
137
|
*
|
|
143
|
-
* The secret is the recipient's app-siloed tagging key hashed with their address,
|
|
144
|
-
* in the address gives accounts that share a tagging key separate tag streams.
|
|
145
|
-
* recipient alone, so whoever sends the log has to know `recipientTsk`, and the recipient finds the log without
|
|
146
|
-
* knowing who sent it.
|
|
138
|
+
* The secret is the recipient's app-siloed tagging key hashed with their address, under the given delivery mode.
|
|
139
|
+
* Hashing in the address gives accounts that share a tagging key separate tag streams.
|
|
147
140
|
*/
|
|
148
141
|
static async computeFromRecipientTsk(
|
|
149
142
|
recipientTsk: Fq,
|
|
150
143
|
app: AztecAddress,
|
|
151
144
|
recipient: AztecAddress,
|
|
145
|
+
deliveryMode: OnchainDeliveryMode,
|
|
152
146
|
): Promise<MessagingSecret> {
|
|
153
147
|
const tskApp = await computeAppTaggingSecretKey(recipientTsk, app);
|
|
154
148
|
const secret = await poseidon2HashWithSeparator([tskApp, recipient], DOM_SEP__RECIPIENT_TSK_SECRET);
|
|
155
149
|
|
|
156
|
-
return new MessagingSecret(secret, app,
|
|
150
|
+
return new MessagingSecret(secret, app, deliveryMode);
|
|
157
151
|
}
|
|
158
152
|
|
|
159
153
|
toString(): string {
|