@mysten/sui 2.35.0 → 2.36.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 +13 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/bcs.mjs +4 -2
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/index.d.mts +12 -3
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +1 -0
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature-scheme.d.mts +4 -1
- package/dist/cryptography/signature-scheme.d.mts.map +1 -1
- package/dist/cryptography/signature-scheme.mjs +6 -3
- package/dist/cryptography/signature-scheme.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/cryptography/signature.mjs +2 -1
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
- package/dist/keypairs/mldsa65/index.d.mts +3 -0
- package/dist/keypairs/mldsa65/index.mjs +4 -0
- package/dist/keypairs/mldsa65/keypair.d.mts +67 -0
- package/dist/keypairs/mldsa65/keypair.d.mts.map +1 -0
- package/dist/keypairs/mldsa65/keypair.mjs +91 -0
- package/dist/keypairs/mldsa65/keypair.mjs.map +1 -0
- package/dist/keypairs/mldsa65/publickey.d.mts +37 -0
- package/dist/keypairs/mldsa65/publickey.d.mts.map +1 -0
- package/dist/keypairs/mldsa65/publickey.mjs +64 -0
- package/dist/keypairs/mldsa65/publickey.mjs.map +1 -0
- package/dist/multisig/publickey.d.mts +4 -0
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +7 -6
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +6 -6
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/verify/verify.mjs +4 -0
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/address-seed.d.mts +6 -0
- package/dist/zklogin/address-seed.d.mts.map +1 -0
- package/dist/zklogin/address-seed.mjs +51 -0
- package/dist/zklogin/address-seed.mjs.map +1 -0
- package/dist/zklogin/address.d.mts.map +1 -1
- package/dist/zklogin/address.mjs +2 -1
- package/dist/zklogin/address.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/index.d.mts +2 -1
- package/dist/zklogin/index.mjs +3 -2
- package/dist/zklogin/nonce.mjs +1 -1
- package/dist/zklogin/utils.d.mts +1 -3
- package/dist/zklogin/utils.d.mts.map +1 -1
- package/dist/zklogin/utils.mjs +1 -46
- package/dist/zklogin/utils.mjs.map +1 -1
- package/docs/cryptography/index.md +7 -6
- package/docs/cryptography/keypairs.md +13 -1
- package/docs/llms-index.md +1 -1
- package/package.json +7 -1
- package/src/bcs/bcs.ts +4 -0
- package/src/cryptography/publickey.ts +1 -0
- package/src/cryptography/signature-scheme.ts +4 -1
- package/src/cryptography/signature.ts +1 -0
- package/src/keypairs/mldsa65/index.ts +5 -0
- package/src/keypairs/mldsa65/keypair.ts +128 -0
- package/src/keypairs/mldsa65/publickey.ts +95 -0
- package/src/multisig/publickey.ts +13 -9
- package/src/verify/verify.ts +4 -0
- package/src/version.ts +1 -1
- package/src/zklogin/address-seed.ts +86 -0
- package/src/zklogin/address.ts +2 -6
- package/src/zklogin/index.ts +1 -2
- package/src/zklogin/utils.ts +0 -83
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE } from "./publickey.mjs";
|
|
2
|
+
import { MLDSA65Keypair, MLDSA65KeypairData } from "./keypair.mjs";
|
|
3
|
+
export { MLDSA65Keypair, type MLDSA65KeypairData, MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { SignatureScheme } from "../../cryptography/signature-scheme.mjs";
|
|
2
|
+
import { Keypair } from "../../cryptography/keypair.mjs";
|
|
3
|
+
import { MLDSA65PublicKey } from "./publickey.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/keypairs/mldsa65/keypair.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* ML-DSA-65 Keypair data. `seed` is the 32-byte FIPS 204 seed, the only form
|
|
8
|
+
* that is ever exported or stored (`suiprivkey`, keystore). `secretKey` is the
|
|
9
|
+
* 4032-byte signing key expanded from it, kept so signing does not re-expand.
|
|
10
|
+
*/
|
|
11
|
+
interface MLDSA65KeypairData {
|
|
12
|
+
seed: Uint8Array;
|
|
13
|
+
secretKey: Uint8Array;
|
|
14
|
+
publicKey: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An ML-DSA-65 (FIPS 204) Keypair used for signing transactions.
|
|
18
|
+
*/
|
|
19
|
+
declare class MLDSA65Keypair extends Keypair {
|
|
20
|
+
private keypair;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new ML-DSA-65 keypair instance.
|
|
23
|
+
* Generate random keypair if no {@link MLDSA65Keypair} is provided.
|
|
24
|
+
*
|
|
25
|
+
* @param keypair ML-DSA-65 keypair
|
|
26
|
+
*/
|
|
27
|
+
constructor(keypair?: MLDSA65KeypairData);
|
|
28
|
+
/**
|
|
29
|
+
* Get the key scheme of the keypair MLDSA65
|
|
30
|
+
*/
|
|
31
|
+
getKeyScheme(): SignatureScheme;
|
|
32
|
+
/**
|
|
33
|
+
* Generate a new random ML-DSA-65 keypair
|
|
34
|
+
*/
|
|
35
|
+
static generate(): MLDSA65Keypair;
|
|
36
|
+
/**
|
|
37
|
+
* Create an ML-DSA-65 keypair from its 32-byte seed.
|
|
38
|
+
*
|
|
39
|
+
* @param secretKey the 32-byte seed as a byte array or Bech32 secret key string
|
|
40
|
+
*/
|
|
41
|
+
static fromSecretKey(secretKey: Uint8Array | string): MLDSA65Keypair;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a keypair from a 32 byte seed. Same as {@link fromSecretKey}:
|
|
44
|
+
* for ML-DSA-65 the seed is the secret key.
|
|
45
|
+
*
|
|
46
|
+
* @param seed seed byte array
|
|
47
|
+
*/
|
|
48
|
+
static fromSeed(seed: Uint8Array): MLDSA65Keypair;
|
|
49
|
+
/**
|
|
50
|
+
* The public key for this ML-DSA-65 keypair
|
|
51
|
+
*/
|
|
52
|
+
getPublicKey(): MLDSA65PublicKey;
|
|
53
|
+
/**
|
|
54
|
+
* The Bech32 secret key string for this ML-DSA-65 keypair, encoding the 32-byte seed.
|
|
55
|
+
*/
|
|
56
|
+
getSecretKey(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Return the signature for the provided data using ML-DSA-65.
|
|
59
|
+
*
|
|
60
|
+
* Hedged signing: 32 fresh random bytes go into every signature, so signing the
|
|
61
|
+
* same data twice gives two different valid signatures.
|
|
62
|
+
*/
|
|
63
|
+
sign(data: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { MLDSA65Keypair, MLDSA65KeypairData };
|
|
67
|
+
//# sourceMappingURL=keypair.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/mldsa65/keypair.ts"],"mappings":";;;;;;;AAoBA;;;UAAiB,kBAAA;EAChB,IAAA,EAAM,UAAA;EACN,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,cAAA,SAAuB,OAAA;EAAA,QAC3B,OAAA;EAPG;;;AAMZ;;;cASa,OAAA,GAAU,kBAAA;EAYN;;;EAAhB,YAAA,CAAA,GAAgB,eAAA;EA0CM;;;EAAA,OAnCf,QAAA,CAAA,GAAY,cAAA;EA2DQ;;;;;EAAA,OAlDpB,aAAA,CAAc,SAAA,EAAW,UAAA,YAAsB,cAAA;EArCnB;;;;;;EAAA,OA+D5B,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,cAAA;EAnC5B;;;EA0CP,YAAA,CAAA,GAAgB,gBAAA;EAjCK;;;EAwCrB,YAAA,CAAA;EAdgB;;;;;;EAwBV,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;AAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Keypair, PRIVATE_KEY_SIZE, decodeSuiPrivateKey, encodeSuiPrivateKey } from "../../cryptography/keypair.mjs";
|
|
2
|
+
import { MLDSA65PublicKey } from "./publickey.mjs";
|
|
3
|
+
import { randomBytes } from "@noble/hashes/utils.js";
|
|
4
|
+
import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
|
|
5
|
+
|
|
6
|
+
//#region src/keypairs/mldsa65/keypair.ts
|
|
7
|
+
/**
|
|
8
|
+
* An ML-DSA-65 (FIPS 204) Keypair used for signing transactions.
|
|
9
|
+
*/
|
|
10
|
+
var MLDSA65Keypair = class MLDSA65Keypair extends Keypair {
|
|
11
|
+
/**
|
|
12
|
+
* Create a new ML-DSA-65 keypair instance.
|
|
13
|
+
* Generate random keypair if no {@link MLDSA65Keypair} is provided.
|
|
14
|
+
*
|
|
15
|
+
* @param keypair ML-DSA-65 keypair
|
|
16
|
+
*/
|
|
17
|
+
constructor(keypair) {
|
|
18
|
+
super();
|
|
19
|
+
if (keypair) this.keypair = keypair;
|
|
20
|
+
else this.keypair = expand(randomBytes(PRIVATE_KEY_SIZE));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the key scheme of the keypair MLDSA65
|
|
24
|
+
*/
|
|
25
|
+
getKeyScheme() {
|
|
26
|
+
return "MLDSA65";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate a new random ML-DSA-65 keypair
|
|
30
|
+
*/
|
|
31
|
+
static generate() {
|
|
32
|
+
return new MLDSA65Keypair();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create an ML-DSA-65 keypair from its 32-byte seed.
|
|
36
|
+
*
|
|
37
|
+
* @param secretKey the 32-byte seed as a byte array or Bech32 secret key string
|
|
38
|
+
*/
|
|
39
|
+
static fromSecretKey(secretKey) {
|
|
40
|
+
if (typeof secretKey === "string") {
|
|
41
|
+
const decoded = decodeSuiPrivateKey(secretKey);
|
|
42
|
+
if (decoded.scheme !== "MLDSA65") throw new Error(`Expected a MLDSA65 keypair, got ${decoded.scheme}`);
|
|
43
|
+
return this.fromSecretKey(decoded.secretKey);
|
|
44
|
+
}
|
|
45
|
+
if (secretKey.length !== PRIVATE_KEY_SIZE) throw new Error(`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKey.length}.`);
|
|
46
|
+
return new MLDSA65Keypair(expand(secretKey));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate a keypair from a 32 byte seed. Same as {@link fromSecretKey}:
|
|
50
|
+
* for ML-DSA-65 the seed is the secret key.
|
|
51
|
+
*
|
|
52
|
+
* @param seed seed byte array
|
|
53
|
+
*/
|
|
54
|
+
static fromSeed(seed) {
|
|
55
|
+
return MLDSA65Keypair.fromSecretKey(seed);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The public key for this ML-DSA-65 keypair
|
|
59
|
+
*/
|
|
60
|
+
getPublicKey() {
|
|
61
|
+
return new MLDSA65PublicKey(this.keypair.publicKey);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The Bech32 secret key string for this ML-DSA-65 keypair, encoding the 32-byte seed.
|
|
65
|
+
*/
|
|
66
|
+
getSecretKey() {
|
|
67
|
+
return encodeSuiPrivateKey(this.keypair.seed, this.getKeyScheme());
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return the signature for the provided data using ML-DSA-65.
|
|
71
|
+
*
|
|
72
|
+
* Hedged signing: 32 fresh random bytes go into every signature, so signing the
|
|
73
|
+
* same data twice gives two different valid signatures.
|
|
74
|
+
*/
|
|
75
|
+
async sign(data) {
|
|
76
|
+
return ml_dsa65.sign(data, this.keypair.secretKey);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
function expand(input) {
|
|
80
|
+
const seed = Uint8Array.from(input);
|
|
81
|
+
const { publicKey, secretKey } = ml_dsa65.keygen(seed);
|
|
82
|
+
return {
|
|
83
|
+
seed,
|
|
84
|
+
secretKey,
|
|
85
|
+
publicKey
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { MLDSA65Keypair };
|
|
91
|
+
//# sourceMappingURL=keypair.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/mldsa65/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { randomBytes } from '@noble/hashes/utils.js';\nimport { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';\n\nimport {\n\tdecodeSuiPrivateKey,\n\tencodeSuiPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { MLDSA65PublicKey } from './publickey.js';\n\n/**\n * ML-DSA-65 Keypair data. `seed` is the 32-byte FIPS 204 seed, the only form\n * that is ever exported or stored (`suiprivkey`, keystore). `secretKey` is the\n * 4032-byte signing key expanded from it, kept so signing does not re-expand.\n */\nexport interface MLDSA65KeypairData {\n\tseed: Uint8Array;\n\tsecretKey: Uint8Array;\n\tpublicKey: Uint8Array;\n}\n\n/**\n * An ML-DSA-65 (FIPS 204) Keypair used for signing transactions.\n */\nexport class MLDSA65Keypair extends Keypair {\n\tprivate keypair: MLDSA65KeypairData;\n\n\t/**\n\t * Create a new ML-DSA-65 keypair instance.\n\t * Generate random keypair if no {@link MLDSA65Keypair} is provided.\n\t *\n\t * @param keypair ML-DSA-65 keypair\n\t */\n\tconstructor(keypair?: MLDSA65KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tthis.keypair = expand(randomBytes(PRIVATE_KEY_SIZE));\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair MLDSA65\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'MLDSA65';\n\t}\n\n\t/**\n\t * Generate a new random ML-DSA-65 keypair\n\t */\n\tstatic generate(): MLDSA65Keypair {\n\t\treturn new MLDSA65Keypair();\n\t}\n\n\t/**\n\t * Create an ML-DSA-65 keypair from its 32-byte seed.\n\t *\n\t * @param secretKey the 32-byte seed as a byte array or Bech32 secret key string\n\t */\n\tstatic fromSecretKey(secretKey: Uint8Array | string): MLDSA65Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'MLDSA65') {\n\t\t\t\tthrow new Error(`Expected a MLDSA65 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey);\n\t\t}\n\n\t\tif (secretKey.length !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKey.length}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn new MLDSA65Keypair(expand(secretKey));\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed. Same as {@link fromSecretKey}:\n\t * for ML-DSA-65 the seed is the secret key.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): MLDSA65Keypair {\n\t\treturn MLDSA65Keypair.fromSecretKey(seed);\n\t}\n\n\t/**\n\t * The public key for this ML-DSA-65 keypair\n\t */\n\tgetPublicKey(): MLDSA65PublicKey {\n\t\treturn new MLDSA65PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this ML-DSA-65 keypair, encoding the 32-byte seed.\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.seed, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data using ML-DSA-65.\n\t *\n\t * Hedged signing: 32 fresh random bytes go into every signature, so signing the\n\t * same data twice gives two different valid signatures.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn ml_dsa65.sign(data, this.keypair.secretKey) as Uint8Array<ArrayBuffer>;\n\t}\n}\n\nfunction expand(input: Uint8Array): MLDSA65KeypairData {\n\t// Own the seed: the caller may wipe or reuse its buffer, and the exported\n\t// secret key must keep matching the signing key.\n\tconst seed = Uint8Array.from(input);\n\tconst { publicKey, secretKey } = ml_dsa65.keygen(seed);\n\treturn { seed, secretKey, publicKey };\n}\n"],"mappings":";;;;;;;;;AA6BA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;;;;CAS3C,YAAY,SAA8B;AACzC,SAAO;AACP,MAAI,QACH,MAAK,UAAU;MAEf,MAAK,UAAU,OAAO,YAAY,iBAAiB,CAAC;;;;;CAOtD,eAAgC;AAC/B,SAAO;;;;;CAMR,OAAO,WAA2B;AACjC,SAAO,IAAI,gBAAgB;;;;;;;CAQ5B,OAAO,cAAc,WAAgD;AACpE,MAAI,OAAO,cAAc,UAAU;GAClC,MAAM,UAAU,oBAAoB,UAAU;AAE9C,OAAI,QAAQ,WAAW,UACtB,OAAM,IAAI,MAAM,mCAAmC,QAAQ,SAAS;AAGrE,UAAO,KAAK,cAAc,QAAQ,UAAU;;AAG7C,MAAI,UAAU,WAAW,iBACxB,OAAM,IAAI,MACT,kCAAkC,iBAAiB,cAAc,UAAU,OAAO,GAClF;AAGF,SAAO,IAAI,eAAe,OAAO,UAAU,CAAC;;;;;;;;CAS7C,OAAO,SAAS,MAAkC;AACjD,SAAO,eAAe,cAAc,KAAK;;;;;CAM1C,eAAiC;AAChC,SAAO,IAAI,iBAAiB,KAAK,QAAQ,UAAU;;;;;CAMpD,eAAuB;AACtB,SAAO,oBAAoB,KAAK,QAAQ,MAAM,KAAK,cAAc,CAAC;;;;;;;;CASnE,MAAM,KAAK,MAAkB;AAC5B,SAAO,SAAS,KAAK,MAAM,KAAK,QAAQ,UAAU;;;AAIpD,SAAS,OAAO,OAAuC;CAGtD,MAAM,OAAO,WAAW,KAAK,MAAM;CACnC,MAAM,EAAE,WAAW,cAAc,SAAS,OAAO,KAAK;AACtD,QAAO;EAAE;EAAM;EAAW;EAAW"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PublicKey, PublicKeyInitData } from "../../cryptography/publickey.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/keypairs/mldsa65/publickey.d.ts
|
|
4
|
+
declare const MLDSA65_PUBLIC_KEY_SIZE = 1952;
|
|
5
|
+
declare const MLDSA65_SIGNATURE_SIZE = 3309;
|
|
6
|
+
/**
|
|
7
|
+
* An ML-DSA-65 (FIPS 204) public key
|
|
8
|
+
*/
|
|
9
|
+
declare class MLDSA65PublicKey extends PublicKey {
|
|
10
|
+
static SIZE: number;
|
|
11
|
+
private data;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new MLDSA65PublicKey object
|
|
14
|
+
* @param value ML-DSA-65 public key as buffer or base-64 encoded string
|
|
15
|
+
*/
|
|
16
|
+
constructor(value: PublicKeyInitData);
|
|
17
|
+
/**
|
|
18
|
+
* Checks if two ML-DSA-65 public keys are equal
|
|
19
|
+
*/
|
|
20
|
+
equals(publicKey: MLDSA65PublicKey): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Return the byte array representation of the ML-DSA-65 public key
|
|
23
|
+
*/
|
|
24
|
+
toRawBytes(): Uint8Array<ArrayBuffer>;
|
|
25
|
+
/**
|
|
26
|
+
* Return the signature scheme flag of the ML-DSA-65 public key
|
|
27
|
+
*/
|
|
28
|
+
flag(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Verifies that the signature is valid for for the provided message.
|
|
31
|
+
* Pure ML-DSA-65 with an empty context string.
|
|
32
|
+
*/
|
|
33
|
+
verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE };
|
|
37
|
+
//# sourceMappingURL=publickey.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/mldsa65/publickey.ts"],"mappings":";;;cAca,uBAAA;AAAA,cACA,sBAAA;;;;cAKA,gBAAA,SAAyB,SAAA;EAAA,OAC9B,IAAA;EAAA,QACC,IAAA;;;;AAFT;cAQa,KAAA,EAAO,iBAAA;;;;EAqBV,MAAA,CAAO,SAAA,EAAW,gBAAA;EAOb;;;EAAd,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;EApCY;;;EA2CrC,IAAA,CAAA;EA1CO;;;;EAkDD,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;AAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SIGNATURE_SCHEME_TO_FLAG } from "../../cryptography/signature-scheme.mjs";
|
|
2
|
+
import { PublicKey, bytesEqual, parseSerializedKeypairSignature } from "../../cryptography/publickey.mjs";
|
|
3
|
+
import { fromBase64 } from "@mysten/bcs";
|
|
4
|
+
import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
|
|
5
|
+
|
|
6
|
+
//#region src/keypairs/mldsa65/publickey.ts
|
|
7
|
+
const MLDSA65_PUBLIC_KEY_SIZE = 1952;
|
|
8
|
+
const MLDSA65_SIGNATURE_SIZE = 3309;
|
|
9
|
+
/**
|
|
10
|
+
* An ML-DSA-65 (FIPS 204) public key
|
|
11
|
+
*/
|
|
12
|
+
var MLDSA65PublicKey = class extends PublicKey {
|
|
13
|
+
static {
|
|
14
|
+
this.SIZE = MLDSA65_PUBLIC_KEY_SIZE;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a new MLDSA65PublicKey object
|
|
18
|
+
* @param value ML-DSA-65 public key as buffer or base-64 encoded string
|
|
19
|
+
*/
|
|
20
|
+
constructor(value) {
|
|
21
|
+
super();
|
|
22
|
+
if (typeof value === "string") this.data = fromBase64(value);
|
|
23
|
+
else if (value instanceof Uint8Array) this.data = value;
|
|
24
|
+
else this.data = Uint8Array.from(value);
|
|
25
|
+
if (this.data.length !== MLDSA65_PUBLIC_KEY_SIZE) throw new Error(`Invalid public key input. Expected ${MLDSA65_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks if two ML-DSA-65 public keys are equal
|
|
29
|
+
*/
|
|
30
|
+
equals(publicKey) {
|
|
31
|
+
return super.equals(publicKey);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return the byte array representation of the ML-DSA-65 public key
|
|
35
|
+
*/
|
|
36
|
+
toRawBytes() {
|
|
37
|
+
return this.data;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Return the signature scheme flag of the ML-DSA-65 public key
|
|
41
|
+
*/
|
|
42
|
+
flag() {
|
|
43
|
+
return SIGNATURE_SCHEME_TO_FLAG["MLDSA65"];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Verifies that the signature is valid for for the provided message.
|
|
47
|
+
* Pure ML-DSA-65 with an empty context string.
|
|
48
|
+
*/
|
|
49
|
+
async verify(message, signature) {
|
|
50
|
+
let bytes;
|
|
51
|
+
if (typeof signature === "string") {
|
|
52
|
+
const parsed = parseSerializedKeypairSignature(signature);
|
|
53
|
+
if (parsed.signatureScheme !== "MLDSA65") throw new Error("Invalid signature scheme");
|
|
54
|
+
if (!bytesEqual(this.toRawBytes(), parsed.publicKey)) throw new Error("Signature does not match public key");
|
|
55
|
+
bytes = parsed.signature;
|
|
56
|
+
} else bytes = signature;
|
|
57
|
+
if (bytes.length !== MLDSA65_SIGNATURE_SIZE) return false;
|
|
58
|
+
return ml_dsa65.verify(bytes, message, this.toRawBytes());
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE };
|
|
64
|
+
//# sourceMappingURL=publickey.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publickey.mjs","names":[],"sources":["../../../src/keypairs/mldsa65/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';\n\nimport {\n\tbytesEqual,\n\tparseSerializedKeypairSignature,\n\tPublicKey,\n} from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\n\nexport const MLDSA65_PUBLIC_KEY_SIZE = 1952;\nexport const MLDSA65_SIGNATURE_SIZE = 3309;\n\n/**\n * An ML-DSA-65 (FIPS 204) public key\n */\nexport class MLDSA65PublicKey extends PublicKey {\n\tstatic SIZE = MLDSA65_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array<ArrayBuffer>;\n\n\t/**\n\t * Create a new MLDSA65PublicKey object\n\t * @param value ML-DSA-65 public key as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.data = Uint8Array.from(value);\n\t\t}\n\n\t\tif (this.data.length !== MLDSA65_PUBLIC_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid public key input. Expected ${MLDSA65_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two ML-DSA-65 public keys are equal\n\t */\n\toverride equals(publicKey: MLDSA65PublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the ML-DSA-65 public key\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.data;\n\t}\n\n\t/**\n\t * Return the signature scheme flag of the ML-DSA-65 public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MLDSA65'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message.\n\t * Pure ML-DSA-65 with an empty context string.\n\t */\n\tasync verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tlet bytes;\n\t\tif (typeof signature === 'string') {\n\t\t\tconst parsed = parseSerializedKeypairSignature(signature);\n\t\t\tif (parsed.signatureScheme !== 'MLDSA65') {\n\t\t\t\tthrow new Error('Invalid signature scheme');\n\t\t\t}\n\n\t\t\tif (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {\n\t\t\t\tthrow new Error('Signature does not match public key');\n\t\t\t}\n\n\t\t\tbytes = parsed.signature;\n\t\t} else {\n\t\t\tbytes = signature;\n\t\t}\n\n\t\tif (bytes.length !== MLDSA65_SIGNATURE_SIZE) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn ml_dsa65.verify(bytes, message, this.toRawBytes());\n\t}\n}\n"],"mappings":";;;;;;AAcA,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;;;;AAKtC,IAAa,mBAAb,cAAsC,UAAU;;cACjC;;;;;;CAOd,YAAY,OAA0B;AACrC,SAAO;AAEP,MAAI,OAAO,UAAU,SACpB,MAAK,OAAO,WAAW,MAAM;WACnB,iBAAiB,WAC3B,MAAK,OAAO;MAEZ,MAAK,OAAO,WAAW,KAAK,MAAM;AAGnC,MAAI,KAAK,KAAK,WAAW,wBACxB,OAAM,IAAI,MACT,sCAAsC,wBAAwB,cAAc,KAAK,KAAK,SACtF;;;;;CAOH,AAAS,OAAO,WAAsC;AACrD,SAAO,MAAM,OAAO,UAAU;;;;;CAM/B,aAAsC;AACrC,SAAO,KAAK;;;;;CAMb,OAAe;AACd,SAAO,yBAAyB;;;;;;CAOjC,MAAM,OAAO,SAAqB,WAAkD;EACnF,IAAI;AACJ,MAAI,OAAO,cAAc,UAAU;GAClC,MAAM,SAAS,gCAAgC,UAAU;AACzD,OAAI,OAAO,oBAAoB,UAC9B,OAAM,IAAI,MAAM,2BAA2B;AAG5C,OAAI,CAAC,WAAW,KAAK,YAAY,EAAE,OAAO,UAAU,CACnD,OAAM,IAAI,MAAM,sCAAsC;AAGvD,WAAQ,OAAO;QAEf,SAAQ;AAGT,MAAI,MAAM,WAAW,uBACpB,QAAO;AAGR,SAAO,SAAS,OAAO,OAAO,SAAS,KAAK,YAAY,CAAC"}
|
|
@@ -15,6 +15,8 @@ type CompressedSignature = {
|
|
|
15
15
|
ZkLogin: Uint8Array;
|
|
16
16
|
} | {
|
|
17
17
|
Passkey: Uint8Array;
|
|
18
|
+
} | {
|
|
19
|
+
MLDSA65: Uint8Array;
|
|
18
20
|
};
|
|
19
21
|
type PublicKeyEnum = {
|
|
20
22
|
ED25519: Uint8Array;
|
|
@@ -26,6 +28,8 @@ type PublicKeyEnum = {
|
|
|
26
28
|
ZkLogin: Uint8Array;
|
|
27
29
|
} | {
|
|
28
30
|
Passkey: Uint8Array;
|
|
31
|
+
} | {
|
|
32
|
+
MLDSA65: Uint8Array;
|
|
29
33
|
};
|
|
30
34
|
type PubkeyEnumWeightPair = {
|
|
31
35
|
pubKey: PublicKeyEnum;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/multisig/publickey.ts"],"mappings":";;;;;;;KAsBK,mBAAA;EACA,OAAA,EAAS,UAAA;AAAA;EACT,SAAA,EAAW,UAAA;AAAA;EACX,SAAA,EAAW,UAAA;AAAA;EACX,OAAA,EAAS,UAAA;AAAA;EACT,OAAA,EAAS,UAAA;AAAA;AAAA,KAET,aAAA;EACA,OAAA,EAAS,UAAA;AAAA;EACT,SAAA,EAAW,UAAA;AAAA;EACX,SAAA,EAAW,UAAA;AAAA;EACX,OAAA,EAAS,UAAA;AAAA;EACT,OAAA,EAAS,UAAA;AAAA;AAAA,KAET,oBAAA;EACJ,MAAA,EAAQ,aAAA;EACR,MAAA;AAAA;AAAA,KAGI,uBAAA;EACJ,MAAA,EAAQ,oBAAA;EACR,SAAA;AAAA;AAAA,KAGW,cAAA;EACX,IAAA,EAAM,mBAAA;EACN,MAAA;EACA,WAAA,EAAa,uBAAA;AAAA;AAAA,KAGT,8BAAA;EACJ,eAAA,EAAiB,eAAA;EACjB,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,SAAA;EACX,MAAA;AAAA;;;;cAQY,iBAAA,SAA0B,SAAA;EAAA,QAC9B,QAAA;EAAA,QACA,iBAAA;EAAA,QACA,UAAA
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/multisig/publickey.ts"],"mappings":";;;;;;;KAsBK,mBAAA;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A/HlB;;;EAsIX,YAAA,CAAA;EAvIE;;;EA6JX,IAAA,CAAA;EA3JM;;AAQP;EA0JO,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,iBAAA,WAA4B,OAAA;;;;;EAoC9D,wBAAA,CAAyB,UAAA;AAAA;;;;iBA+DV,sBAAA,CACf,QAAA,EAAU,cAAA,EACV,OAAA;EAAW,MAAA,GAAS,iBAAA;AAAA,IAClB,8BAAA"}
|
|
@@ -89,18 +89,19 @@ var MultiSigPublicKey = class MultiSigPublicKey extends PublicKey {
|
|
|
89
89
|
* Return the Sui address associated with this MultiSig public key
|
|
90
90
|
*/
|
|
91
91
|
toSuiAddress() {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
92
|
+
const suiBytes = this.publicKeys.map(({ publicKey }) => publicKey.toSuiBytes());
|
|
93
|
+
const length = 3 + suiBytes.reduce((sum, bytes) => sum + bytes.length + 1, 0);
|
|
94
|
+
const tmp = new Uint8Array(length);
|
|
94
95
|
tmp.set([SIGNATURE_SCHEME_TO_FLAG["MultiSig"]]);
|
|
95
96
|
tmp.set(suiBcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);
|
|
96
97
|
let i = 3;
|
|
97
|
-
for (const {
|
|
98
|
-
const bytes =
|
|
98
|
+
for (const [j, { weight }] of this.publicKeys.entries()) {
|
|
99
|
+
const bytes = suiBytes[j];
|
|
99
100
|
tmp.set(bytes, i);
|
|
100
101
|
i += bytes.length;
|
|
101
102
|
tmp.set([weight], i++);
|
|
102
103
|
}
|
|
103
|
-
return normalizeSuiAddress(bytesToHex(blake2b(tmp
|
|
104
|
+
return normalizeSuiAddress(bytesToHex(blake2b(tmp, { dkLen: 32 })));
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
107
|
* Return the Sui address associated with this MultiSig public key
|
|
@@ -152,7 +153,7 @@ var MultiSigPublicKey = class MultiSigPublicKey extends PublicKey {
|
|
|
152
153
|
bitmap,
|
|
153
154
|
multisig_pk: this.multisigPublicKey
|
|
154
155
|
};
|
|
155
|
-
const bytes = suiBcs.MultiSig.serialize(multisig, { maxSize:
|
|
156
|
+
const bytes = suiBcs.MultiSig.serialize(multisig, { maxSize: 65536 }).toBytes();
|
|
156
157
|
const tmp = new Uint8Array(bytes.length + 1);
|
|
157
158
|
tmp.set([SIGNATURE_SCHEME_TO_FLAG["MultiSig"]]);
|
|
158
159
|
tmp.set(bytes, 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.mjs","names":["bcs"],"sources":["../../src/multisig/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { bcs } from '../bcs/index.js';\nimport type { Signer } from '../cryptography/keypair.js';\nimport { bytesEqual, PublicKey } from '../cryptography/publickey.js';\nimport {\n\tSIGNATURE_FLAG_TO_SCHEME,\n\tSIGNATURE_SCHEME_TO_FLAG,\n} from '../cryptography/signature-scheme.js';\nimport type { SignatureFlag, SignatureScheme } from '../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../cryptography/signature.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport { publicKeyFromRawBytes } from '../verify/index.js';\nimport { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport { MultiSigSigner } from './signer.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\ntype CompressedSignature =\n\t| { ED25519: Uint8Array }\n\t| { Secp256k1: Uint8Array }\n\t| { Secp256r1: Uint8Array }\n\t| { ZkLogin: Uint8Array }\n\t| { Passkey: Uint8Array };\n\ntype PublicKeyEnum =\n\t| { ED25519: Uint8Array }\n\t| { Secp256k1: Uint8Array }\n\t| { Secp256r1: Uint8Array }\n\t| { ZkLogin: Uint8Array }\n\t| { Passkey: Uint8Array };\n\ntype PubkeyEnumWeightPair = {\n\tpubKey: PublicKeyEnum;\n\tweight: number;\n};\n\ntype MultiSigPublicKeyStruct = {\n\tpk_map: PubkeyEnumWeightPair[];\n\tthreshold: number;\n};\n\nexport type MultiSigStruct = {\n\tsigs: CompressedSignature[];\n\tbitmap: number;\n\tmultisig_pk: MultiSigPublicKeyStruct;\n};\n\ntype ParsedPartialMultiSigSignature = {\n\tsignatureScheme: SignatureScheme;\n\tsignature: Uint8Array;\n\tpublicKey: PublicKey;\n\tweight: number;\n};\n\nexport const MAX_SIGNER_IN_MULTISIG = 10;\nexport const MIN_SIGNER_IN_MULTISIG = 1;\n/**\n * A MultiSig public key\n */\nexport class MultiSigPublicKey extends PublicKey {\n\tprivate rawBytes: Uint8Array<ArrayBuffer>;\n\tprivate multisigPublicKey: MultiSigPublicKeyStruct;\n\tprivate publicKeys: {\n\t\tweight: number;\n\t\tpublicKey: PublicKey;\n\t}[];\n\t/**\n\t * Create a new MultiSigPublicKey object\n\t */\n\tconstructor(\n\t\t/**\n\t\t * MultiSig public key as buffer or base-64 encoded string\n\t\t */\n\t\tvalue: string | Uint8Array | MultiSigPublicKeyStruct,\n\t\toptions: { client?: ClientWithCoreApi } = {},\n\t) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.rawBytes = fromBase64(value);\n\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.rawBytes = value as Uint8Array<ArrayBuffer>;\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else {\n\t\t\tthis.multisigPublicKey = value;\n\t\t\tthis.rawBytes = bcs.MultiSigPublicKey.serialize(value).toBytes();\n\t\t}\n\t\tif (this.multisigPublicKey.threshold < 1) {\n\t\t\tthrow new Error('Invalid threshold');\n\t\t}\n\n\t\tconst seenPublicKeys = new Set<string>();\n\n\t\tthis.publicKeys = this.multisigPublicKey.pk_map.map(({ pubKey, weight }) => {\n\t\t\tconst [scheme, bytes] = Object.entries(pubKey).filter(([name]) => name !== '$kind')[0] as [\n\t\t\t\tSignatureScheme,\n\t\t\t\tUint8Array,\n\t\t\t];\n\t\t\tconst publicKeyStr = Uint8Array.from(bytes).toString();\n\n\t\t\tif (seenPublicKeys.has(publicKeyStr)) {\n\t\t\t\tthrow new Error(`Multisig does not support duplicate public keys`);\n\t\t\t}\n\t\t\tseenPublicKeys.add(publicKeyStr);\n\n\t\t\tif (weight < 1) {\n\t\t\t\tthrow new Error(`Invalid weight`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpublicKey: publicKeyFromRawBytes(scheme, Uint8Array.from(bytes), options),\n\t\t\t\tweight,\n\t\t\t};\n\t\t});\n\n\t\tconst totalWeight = this.publicKeys.reduce((sum, { weight }) => sum + weight, 0);\n\n\t\tif (this.multisigPublicKey.threshold > totalWeight) {\n\t\t\tthrow new Error(`Unreachable threshold`);\n\t\t}\n\n\t\tif (this.publicKeys.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signers in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tif (this.publicKeys.length < MIN_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Min number of signers in a multisig is ${MIN_SIGNER_IN_MULTISIG}`);\n\t\t}\n\t}\n\t/**\n\t * \tA static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.\n\t */\n\n\tstatic fromPublicKeys({\n\t\tthreshold,\n\t\tpublicKeys,\n\t}: {\n\t\tthreshold: number;\n\t\tpublicKeys: { publicKey: PublicKey; weight: number }[];\n\t}) {\n\t\treturn new MultiSigPublicKey({\n\t\t\tpk_map: publicKeys.map(({ publicKey, weight }) => {\n\t\t\t\tconst scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];\n\n\t\t\t\treturn {\n\t\t\t\t\tpubKey: { [scheme]: publicKey.toRawBytes() } as PublicKeyEnum,\n\t\t\t\t\tweight,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthreshold,\n\t\t});\n\t}\n\n\t/**\n\t * Checks if two MultiSig public keys are equal\n\t */\n\toverride equals(publicKey: MultiSigPublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the MultiSig public key\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.rawBytes;\n\t}\n\n\tgetPublicKeys() {\n\t\treturn this.publicKeys;\n\t}\n\n\tgetThreshold() {\n\t\treturn this.multisigPublicKey.threshold;\n\t}\n\n\tgetSigner(...signers: [signer: Signer]) {\n\t\treturn new MultiSigSigner(this, signers);\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\toverride toSuiAddress(): string {\n\t\t// max length = 1 flag byte + (max pk size + max weight size (u8)) * max signer size + 2 threshold bytes (u16)\n\t\tconst maxLength = 1 + (64 + 1) * MAX_SIGNER_IN_MULTISIG + 2;\n\t\tconst tmp = new Uint8Array(maxLength);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\n\t\ttmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);\n\t\t// The initial value 3 ensures that following data will be after the flag byte and threshold bytes\n\t\tlet i = 3;\n\t\tfor (const { publicKey, weight } of this.publicKeys) {\n\t\t\tconst bytes = publicKey.toSuiBytes();\n\t\t\ttmp.set(bytes, i);\n\t\t\ti += bytes.length;\n\t\t\ttmp.set([weight], i++);\n\t\t}\n\t\treturn normalizeSuiAddress(bytesToHex(blake2b(tmp.slice(0, i), { dkLen: 32 })));\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MultiSig'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Multisig verification only supports serialized signature\n\t\tconst parsed = parseSerializedSignature(multisigSignature);\n\n\t\tif (parsed.signatureScheme !== 'MultiSig') {\n\t\t\tthrow new Error('Invalid signature scheme');\n\t\t}\n\n\t\tconst { multisig } = parsed;\n\n\t\tlet signatureWeight = 0;\n\n\t\tif (\n\t\t\t!bytesEqual(\n\t\t\t\tbcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),\n\t\t\t\tbcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),\n\t\t\t)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {\n\t\t\tif (!(await publicKey.verify(message, signature))) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tsignatureWeight += weight;\n\t\t}\n\n\t\treturn signatureWeight >= this.multisigPublicKey.threshold;\n\t}\n\n\t/**\n\t * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once\n\t * and that all the public keys involved are known and valid, and then serializes multisig into the standard format\n\t */\n\tcombinePartialSignatures(signatures: string[]): string {\n\t\tif (signatures.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tlet bitmap = 0;\n\t\tconst compressedSignatures: CompressedSignature[] = new Array(signatures.length);\n\n\t\tfor (let i = 0; i < signatures.length; i++) {\n\t\t\tconst parsed = parseSerializedSignature(signatures[i]);\n\t\t\tif (parsed.signatureScheme === 'MultiSig') {\n\t\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t\t}\n\n\t\t\tlet publicKey;\n\t\t\tif (parsed.signatureScheme === 'ZkLogin') {\n\t\t\t\tpublicKey = toZkLoginPublicIdentifier(parsed.zkLogin?.addressSeed, parsed.zkLogin?.iss, {\n\t\t\t\t\tlegacyAddress: false,\n\t\t\t\t}).toRawBytes();\n\t\t\t} else {\n\t\t\t\tpublicKey = parsed.publicKey;\n\t\t\t}\n\n\t\t\tcompressedSignatures[i] = {\n\t\t\t\t[parsed.signatureScheme]: parsed.signature,\n\t\t\t} as CompressedSignature;\n\n\t\t\tlet publicKeyIndex;\n\t\t\tfor (let j = 0; j < this.publicKeys.length; j++) {\n\t\t\t\tif (bytesEqual(publicKey, this.publicKeys[j].publicKey.toRawBytes())) {\n\t\t\t\t\tif (bitmap & (1 << j)) {\n\t\t\t\t\t\tthrow new Error('Received multiple signatures from the same public key');\n\t\t\t\t\t}\n\n\t\t\t\t\tpublicKeyIndex = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (publicKeyIndex === undefined) {\n\t\t\t\tthrow new Error('Received signature from unknown public key');\n\t\t\t}\n\n\t\t\tbitmap |= 1 << publicKeyIndex;\n\t\t}\n\n\t\tconst multisig: MultiSigStruct = {\n\t\t\tsigs: compressedSignatures,\n\t\t\tbitmap,\n\t\t\tmultisig_pk: this.multisigPublicKey,\n\t\t};\n\t\tconst bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();\n\t\tconst tmp = new Uint8Array(bytes.length + 1);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\t\ttmp.set(bytes, 1);\n\t\treturn toBase64(tmp);\n\t}\n}\n\n/**\n * Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.\n */\nexport function parsePartialSignatures(\n\tmultisig: MultiSigStruct,\n\toptions: { client?: ClientWithCoreApi } = {},\n): ParsedPartialMultiSigSignature[] {\n\tconst res: ParsedPartialMultiSigSignature[] = new Array(multisig.sigs.length);\n\tfor (let i = 0; i < multisig.sigs.length; i++) {\n\t\tconst [signatureScheme, signature] = Object.entries(multisig.sigs[i]).filter(\n\t\t\t([name]) => name !== '$kind',\n\t\t)[0] as [SignatureScheme, Uint8Array];\n\t\tconst pkIndex = asIndices(multisig.bitmap).at(i)!;\n\t\tconst pair = multisig.multisig_pk.pk_map[pkIndex];\n\t\tconst pkBytes = Uint8Array.from(Object.values(pair.pubKey)[0]);\n\n\t\tif (signatureScheme === 'MultiSig') {\n\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t}\n\n\t\tconst publicKey = publicKeyFromRawBytes(signatureScheme, pkBytes, options);\n\n\t\tres[i] = {\n\t\t\tsignatureScheme,\n\t\t\tsignature: Uint8Array.from(signature),\n\t\t\tpublicKey: publicKey,\n\t\t\tweight: pair.weight,\n\t\t};\n\t}\n\treturn res;\n}\n\nfunction asIndices(bitmap: number): Uint8Array {\n\tif (bitmap < 0 || bitmap > 1024) {\n\t\tthrow new Error('Invalid bitmap');\n\t}\n\tconst res: number[] = [];\n\tfor (let i = 0; i < 10; i++) {\n\t\tif ((bitmap & (1 << i)) !== 0) {\n\t\t\tres.push(i);\n\t\t}\n\t}\n\treturn Uint8Array.from(res);\n}\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;;;;AAItC,IAAa,oBAAb,MAAa,0BAA0B,UAAU;;;;CAUhD,YAIC,OACA,UAA0C,EAAE,EAC3C;AACD,SAAO;AAEP,MAAI,OAAO,UAAU,UAAU;AAC9B,QAAK,WAAW,WAAW,MAAM;AAEjC,QAAK,oBAAoBA,OAAI,kBAAkB,MAAM,KAAK,SAAS;aACzD,iBAAiB,YAAY;AACvC,QAAK,WAAW;AAChB,QAAK,oBAAoBA,OAAI,kBAAkB,MAAM,KAAK,SAAS;SAC7D;AACN,QAAK,oBAAoB;AACzB,QAAK,WAAWA,OAAI,kBAAkB,UAAU,MAAM,CAAC,SAAS;;AAEjE,MAAI,KAAK,kBAAkB,YAAY,EACtC,OAAM,IAAI,MAAM,oBAAoB;EAGrC,MAAM,iCAAiB,IAAI,KAAa;AAExC,OAAK,aAAa,KAAK,kBAAkB,OAAO,KAAK,EAAE,QAAQ,aAAa;GAC3E,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,OA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CAA4C;EAG7D,MAAM,YAAY,sBAAsB,iBAAiB,SAAS,QAAQ;AAE1E,MAAI,KAAK;GACR;GACA,WAAW,WAAW,KAAK,UAAU;GAC1B;GACX,QAAQ,KAAK;GACb;;AAEF,QAAO;;AAGR,SAAS,UAAU,QAA4B;AAC9C,KAAI,SAAS,KAAK,SAAS,KAC1B,OAAM,IAAI,MAAM,iBAAiB;CAElC,MAAM,MAAgB,EAAE;AACxB,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,IACvB,MAAK,SAAU,KAAK,OAAQ,EAC3B,KAAI,KAAK,EAAE;AAGb,QAAO,WAAW,KAAK,IAAI"}
|
|
1
|
+
{"version":3,"file":"publickey.mjs","names":["bcs"],"sources":["../../src/multisig/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { bcs } from '../bcs/index.js';\nimport type { Signer } from '../cryptography/keypair.js';\nimport { bytesEqual, PublicKey } from '../cryptography/publickey.js';\nimport {\n\tSIGNATURE_FLAG_TO_SCHEME,\n\tSIGNATURE_SCHEME_TO_FLAG,\n} from '../cryptography/signature-scheme.js';\nimport type { SignatureFlag, SignatureScheme } from '../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../cryptography/signature.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport { publicKeyFromRawBytes } from '../verify/index.js';\nimport { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport { MultiSigSigner } from './signer.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\ntype CompressedSignature =\n\t| { ED25519: Uint8Array }\n\t| { Secp256k1: Uint8Array }\n\t| { Secp256r1: Uint8Array }\n\t| { ZkLogin: Uint8Array }\n\t| { Passkey: Uint8Array }\n\t| { MLDSA65: Uint8Array };\n\ntype PublicKeyEnum =\n\t| { ED25519: Uint8Array }\n\t| { Secp256k1: Uint8Array }\n\t| { Secp256r1: Uint8Array }\n\t| { ZkLogin: Uint8Array }\n\t| { Passkey: Uint8Array }\n\t| { MLDSA65: Uint8Array };\n\ntype PubkeyEnumWeightPair = {\n\tpubKey: PublicKeyEnum;\n\tweight: number;\n};\n\ntype MultiSigPublicKeyStruct = {\n\tpk_map: PubkeyEnumWeightPair[];\n\tthreshold: number;\n};\n\nexport type MultiSigStruct = {\n\tsigs: CompressedSignature[];\n\tbitmap: number;\n\tmultisig_pk: MultiSigPublicKeyStruct;\n};\n\ntype ParsedPartialMultiSigSignature = {\n\tsignatureScheme: SignatureScheme;\n\tsignature: Uint8Array;\n\tpublicKey: PublicKey;\n\tweight: number;\n};\n\nexport const MAX_SIGNER_IN_MULTISIG = 10;\nexport const MIN_SIGNER_IN_MULTISIG = 1;\n/**\n * A MultiSig public key\n */\nexport class MultiSigPublicKey extends PublicKey {\n\tprivate rawBytes: Uint8Array<ArrayBuffer>;\n\tprivate multisigPublicKey: MultiSigPublicKeyStruct;\n\tprivate publicKeys: {\n\t\tweight: number;\n\t\tpublicKey: PublicKey;\n\t}[];\n\t/**\n\t * Create a new MultiSigPublicKey object\n\t */\n\tconstructor(\n\t\t/**\n\t\t * MultiSig public key as buffer or base-64 encoded string\n\t\t */\n\t\tvalue: string | Uint8Array | MultiSigPublicKeyStruct,\n\t\toptions: { client?: ClientWithCoreApi } = {},\n\t) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.rawBytes = fromBase64(value);\n\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.rawBytes = value as Uint8Array<ArrayBuffer>;\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else {\n\t\t\tthis.multisigPublicKey = value;\n\t\t\tthis.rawBytes = bcs.MultiSigPublicKey.serialize(value).toBytes();\n\t\t}\n\t\tif (this.multisigPublicKey.threshold < 1) {\n\t\t\tthrow new Error('Invalid threshold');\n\t\t}\n\n\t\tconst seenPublicKeys = new Set<string>();\n\n\t\tthis.publicKeys = this.multisigPublicKey.pk_map.map(({ pubKey, weight }) => {\n\t\t\tconst [scheme, bytes] = Object.entries(pubKey).filter(([name]) => name !== '$kind')[0] as [\n\t\t\t\tSignatureScheme,\n\t\t\t\tUint8Array,\n\t\t\t];\n\t\t\tconst publicKeyStr = Uint8Array.from(bytes).toString();\n\n\t\t\tif (seenPublicKeys.has(publicKeyStr)) {\n\t\t\t\tthrow new Error(`Multisig does not support duplicate public keys`);\n\t\t\t}\n\t\t\tseenPublicKeys.add(publicKeyStr);\n\n\t\t\tif (weight < 1) {\n\t\t\t\tthrow new Error(`Invalid weight`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpublicKey: publicKeyFromRawBytes(scheme, Uint8Array.from(bytes), options),\n\t\t\t\tweight,\n\t\t\t};\n\t\t});\n\n\t\tconst totalWeight = this.publicKeys.reduce((sum, { weight }) => sum + weight, 0);\n\n\t\tif (this.multisigPublicKey.threshold > totalWeight) {\n\t\t\tthrow new Error(`Unreachable threshold`);\n\t\t}\n\n\t\tif (this.publicKeys.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signers in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tif (this.publicKeys.length < MIN_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Min number of signers in a multisig is ${MIN_SIGNER_IN_MULTISIG}`);\n\t\t}\n\t}\n\t/**\n\t * \tA static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.\n\t */\n\n\tstatic fromPublicKeys({\n\t\tthreshold,\n\t\tpublicKeys,\n\t}: {\n\t\tthreshold: number;\n\t\tpublicKeys: { publicKey: PublicKey; weight: number }[];\n\t}) {\n\t\treturn new MultiSigPublicKey({\n\t\t\tpk_map: publicKeys.map(({ publicKey, weight }) => {\n\t\t\t\tconst scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];\n\n\t\t\t\treturn {\n\t\t\t\t\tpubKey: { [scheme]: publicKey.toRawBytes() } as PublicKeyEnum,\n\t\t\t\t\tweight,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthreshold,\n\t\t});\n\t}\n\n\t/**\n\t * Checks if two MultiSig public keys are equal\n\t */\n\toverride equals(publicKey: MultiSigPublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the MultiSig public key\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.rawBytes;\n\t}\n\n\tgetPublicKeys() {\n\t\treturn this.publicKeys;\n\t}\n\n\tgetThreshold() {\n\t\treturn this.multisigPublicKey.threshold;\n\t}\n\n\tgetSigner(...signers: [signer: Signer]) {\n\t\treturn new MultiSigSigner(this, signers);\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\toverride toSuiAddress(): string {\n\t\tconst suiBytes = this.publicKeys.map(({ publicKey }) => publicKey.toSuiBytes());\n\t\t// 1 flag byte + 2 threshold bytes (u16) + per member: flagged public key + 1 weight byte (u8)\n\t\tconst length = 3 + suiBytes.reduce((sum, bytes) => sum + bytes.length + 1, 0);\n\t\tconst tmp = new Uint8Array(length);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\n\t\ttmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);\n\t\t// The initial value 3 ensures that following data will be after the flag byte and threshold bytes\n\t\tlet i = 3;\n\t\tfor (const [j, { weight }] of this.publicKeys.entries()) {\n\t\t\tconst bytes = suiBytes[j];\n\t\t\ttmp.set(bytes, i);\n\t\t\ti += bytes.length;\n\t\t\ttmp.set([weight], i++);\n\t\t}\n\t\treturn normalizeSuiAddress(bytesToHex(blake2b(tmp, { dkLen: 32 })));\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MultiSig'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Multisig verification only supports serialized signature\n\t\tconst parsed = parseSerializedSignature(multisigSignature);\n\n\t\tif (parsed.signatureScheme !== 'MultiSig') {\n\t\t\tthrow new Error('Invalid signature scheme');\n\t\t}\n\n\t\tconst { multisig } = parsed;\n\n\t\tlet signatureWeight = 0;\n\n\t\tif (\n\t\t\t!bytesEqual(\n\t\t\t\tbcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),\n\t\t\t\tbcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),\n\t\t\t)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {\n\t\t\tif (!(await publicKey.verify(message, signature))) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tsignatureWeight += weight;\n\t\t}\n\n\t\treturn signatureWeight >= this.multisigPublicKey.threshold;\n\t}\n\n\t/**\n\t * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once\n\t * and that all the public keys involved are known and valid, and then serializes multisig into the standard format\n\t */\n\tcombinePartialSignatures(signatures: string[]): string {\n\t\tif (signatures.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tlet bitmap = 0;\n\t\tconst compressedSignatures: CompressedSignature[] = new Array(signatures.length);\n\n\t\tfor (let i = 0; i < signatures.length; i++) {\n\t\t\tconst parsed = parseSerializedSignature(signatures[i]);\n\t\t\tif (parsed.signatureScheme === 'MultiSig') {\n\t\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t\t}\n\n\t\t\tlet publicKey;\n\t\t\tif (parsed.signatureScheme === 'ZkLogin') {\n\t\t\t\tpublicKey = toZkLoginPublicIdentifier(parsed.zkLogin?.addressSeed, parsed.zkLogin?.iss, {\n\t\t\t\t\tlegacyAddress: false,\n\t\t\t\t}).toRawBytes();\n\t\t\t} else {\n\t\t\t\tpublicKey = parsed.publicKey;\n\t\t\t}\n\n\t\t\tcompressedSignatures[i] = {\n\t\t\t\t[parsed.signatureScheme]: parsed.signature,\n\t\t\t} as CompressedSignature;\n\n\t\t\tlet publicKeyIndex;\n\t\t\tfor (let j = 0; j < this.publicKeys.length; j++) {\n\t\t\t\tif (bytesEqual(publicKey, this.publicKeys[j].publicKey.toRawBytes())) {\n\t\t\t\t\tif (bitmap & (1 << j)) {\n\t\t\t\t\t\tthrow new Error('Received multiple signatures from the same public key');\n\t\t\t\t\t}\n\n\t\t\t\t\tpublicKeyIndex = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (publicKeyIndex === undefined) {\n\t\t\t\tthrow new Error('Received signature from unknown public key');\n\t\t\t}\n\n\t\t\tbitmap |= 1 << publicKeyIndex;\n\t\t}\n\n\t\tconst multisig: MultiSigStruct = {\n\t\t\tsigs: compressedSignatures,\n\t\t\tbitmap,\n\t\t\tmultisig_pk: this.multisigPublicKey,\n\t\t};\n\t\t// Ten ML-DSA-65 members are ~53 KB of signatures and public keys.\n\t\tconst bytes = bcs.MultiSig.serialize(multisig, { maxSize: 65536 }).toBytes();\n\t\tconst tmp = new Uint8Array(bytes.length + 1);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\t\ttmp.set(bytes, 1);\n\t\treturn toBase64(tmp);\n\t}\n}\n\n/**\n * Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.\n */\nexport function parsePartialSignatures(\n\tmultisig: MultiSigStruct,\n\toptions: { client?: ClientWithCoreApi } = {},\n): ParsedPartialMultiSigSignature[] {\n\tconst res: ParsedPartialMultiSigSignature[] = new Array(multisig.sigs.length);\n\tfor (let i = 0; i < multisig.sigs.length; i++) {\n\t\tconst [signatureScheme, signature] = Object.entries(multisig.sigs[i]).filter(\n\t\t\t([name]) => name !== '$kind',\n\t\t)[0] as [SignatureScheme, Uint8Array];\n\t\tconst pkIndex = asIndices(multisig.bitmap).at(i)!;\n\t\tconst pair = multisig.multisig_pk.pk_map[pkIndex];\n\t\tconst pkBytes = Uint8Array.from(Object.values(pair.pubKey)[0]);\n\n\t\tif (signatureScheme === 'MultiSig') {\n\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t}\n\n\t\tconst publicKey = publicKeyFromRawBytes(signatureScheme, pkBytes, options);\n\n\t\tres[i] = {\n\t\t\tsignatureScheme,\n\t\t\tsignature: Uint8Array.from(signature),\n\t\t\tpublicKey: publicKey,\n\t\t\tweight: pair.weight,\n\t\t};\n\t}\n\treturn res;\n}\n\nfunction asIndices(bitmap: number): Uint8Array {\n\tif (bitmap < 0 || bitmap > 1024) {\n\t\tthrow new Error('Invalid bitmap');\n\t}\n\tconst res: number[] = [];\n\tfor (let i = 0; i < 10; i++) {\n\t\tif ((bitmap & (1 << i)) !== 0) {\n\t\t\tres.push(i);\n\t\t}\n\t}\n\treturn Uint8Array.from(res);\n}\n"],"mappings":";;;;;;;;;;;;;AA6DA,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;;;;AAItC,IAAa,oBAAb,MAAa,0BAA0B,UAAU;;;;CAUhD,YAIC,OACA,UAA0C,EAAE,EAC3C;AACD,SAAO;AAEP,MAAI,OAAO,UAAU,UAAU;AAC9B,QAAK,WAAW,WAAW,MAAM;AAEjC,QAAK,oBAAoBA,OAAI,kBAAkB,MAAM,KAAK,SAAS;aACzD,iBAAiB,YAAY;AACvC,QAAK,WAAW;AAChB,QAAK,oBAAoBA,OAAI,kBAAkB,MAAM,KAAK,SAAS;SAC7D;AACN,QAAK,oBAAoB;AACzB,QAAK,WAAWA,O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I,GAAG,IAAI,SAAS,KAAK,QAAQ,KAAK;EAC9C,MAAM,CAAC,iBAAiB,aAAa,OAAO,QAAQ,SAAS,KAAK,GAAG,CAAC,QACpE,CAAC,UAAU,SAAS,QACrB,CAAC;EACF,MAAM,UAAU,UAAU,SAAS,OAAO,CAAC,GAAG,EAAE;EAChD,MAAM,OAAO,SAAS,YAAY,OAAO;EACzC,MAAM,UAAU,WAAW,KAAK,OAAO,OAAO,KAAK,OAAO,CAAC,GAAG;AAE9D,MAAI,oBAAoB,WACvB,OAAM,IAAI,MAAM,4CAA4C;EAG7D,MAAM,YAAY,sBAAsB,iBAAiB,SAAS,QAAQ;AAE1E,MAAI,KAAK;GACR;GACA,WAAW,WAAW,KAAK,UAAU;GAC1B;GACX,QAAQ,KAAK;GACb;;AAEF,QAAO;;AAGR,SAAS,UAAU,QAA4B;AAC9C,KAAI,SAAS,KAAK,SAAS,KAC1B,OAAM,IAAI,MAAM,iBAAiB;CAElC,MAAM,MAAgB,EAAE;AACxB,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,IACvB,MAAK,SAAU,KAAK,OAAQ,EAC3B,KAAI,KAAK,EAAE;AAGb,QAAO,WAAW,KAAK,IAAI"}
|
|
@@ -8,7 +8,7 @@ import { createPure } from "./pure.mjs";
|
|
|
8
8
|
import { BalanceOptions } from "./intents/BalanceOptions.mjs";
|
|
9
9
|
import { SignatureWithBytes, Signer } from "../cryptography/keypair.mjs";
|
|
10
10
|
import "../cryptography/index.mjs";
|
|
11
|
-
import * as
|
|
11
|
+
import * as _mysten_bcs1257 from "@mysten/bcs";
|
|
12
12
|
import { SerializedBcs } from "@mysten/bcs";
|
|
13
13
|
import { InferInput } from "valibot";
|
|
14
14
|
|
|
@@ -110,7 +110,7 @@ declare class Transaction {
|
|
|
110
110
|
getData(): {
|
|
111
111
|
version: 2;
|
|
112
112
|
sender?: string | null | undefined;
|
|
113
|
-
expiration?:
|
|
113
|
+
expiration?: _mysten_bcs1257.EnumOutputShapeWithKeys<{
|
|
114
114
|
None: true;
|
|
115
115
|
Epoch: string | number;
|
|
116
116
|
ValidDuring: {
|
|
@@ -144,8 +144,8 @@ declare class Transaction {
|
|
|
144
144
|
digest: string;
|
|
145
145
|
}[] | null;
|
|
146
146
|
};
|
|
147
|
-
inputs:
|
|
148
|
-
Object:
|
|
147
|
+
inputs: _mysten_bcs1257.EnumOutputShapeWithKeys<{
|
|
148
|
+
Object: _mysten_bcs1257.EnumOutputShapeWithKeys<{
|
|
149
149
|
ImmOrOwnedObject: {
|
|
150
150
|
objectId: string;
|
|
151
151
|
version: string | number;
|
|
@@ -184,7 +184,7 @@ declare class Transaction {
|
|
|
184
184
|
Balance: string;
|
|
185
185
|
$kind: "Balance";
|
|
186
186
|
};
|
|
187
|
-
withdrawFrom:
|
|
187
|
+
withdrawFrom: _mysten_bcs1257.EnumOutputShapeWithKeys<{
|
|
188
188
|
Sender: true;
|
|
189
189
|
Sponsor: true;
|
|
190
190
|
SenderAllowance: {
|
|
@@ -194,7 +194,7 @@ declare class Transaction {
|
|
|
194
194
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
195
195
|
};
|
|
196
196
|
}, "Object" | "Pure" | "FundsWithdrawal" | "UnresolvedPure" | "UnresolvedObject">[];
|
|
197
|
-
commands:
|
|
197
|
+
commands: _mysten_bcs1257.EnumOutputShapeWithKeys<{
|
|
198
198
|
MoveCall: {
|
|
199
199
|
package: string;
|
|
200
200
|
module: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.mts","names":[],"sources":["../../src/verify/verify.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"verify.d.mts","names":[],"sources":["../../src/verify/verify.ts"],"mappings":";;;;;;;;;;AAuBA;;;iBAAsB,gBAAA,CACrB,KAAA,EAAO,UAAA,EACP,SAAA,UACA,OAAA;EAAW,OAAA;AAAA,IACT,OAAA;;iBAQmB,+BAAA,CACrB,OAAA,EAAS,UAAA,EACT,SAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,OAAA;AAAA,IACrC,OAAA;;iBAUmB,2BAAA,CACrB,WAAA,EAAa,UAAA,EACb,SAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,OAAA;AAAA,IACrC,OAAA;AAAA,iBASmB,eAAA,CACrB,KAAA,EAAO,UAAA,EACP,SAAA,UACA,OAAA;EAAW,OAAA;AAAA,IACT,OAAA,CAAQ,SAAA;AAAA,iBAWW,8BAAA,CACrB,OAAA,EAAS,UAAA,EACT,SAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,OAAA;AAAA,IACrC,OAAA,CAAQ,SAAA;AAAA,iBAWW,0BAAA,CACrB,WAAA,EAAa,UAAA,EACb,SAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,OAAA;AAAA,IACrC,OAAA,CAAQ,SAAA;AAAA,iBAyCK,qBAAA,CACf,eAAA,EAAiB,eAAA,EACjB,KAAA,EAAO,UAAA,EACP,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,OAAA;AAAA,IACrC,SAAA;AAAA,iBAmCa,qBAAA,CACf,SAAA,WAAoB,UAAA,EACpB,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,OAAA;AAAA,IAAuB,SAAA"}
|
package/dist/verify/verify.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { parseSerializedSignature } from "../cryptography/signature.mjs";
|
|
|
5
5
|
import { Ed25519PublicKey } from "../keypairs/ed25519/publickey.mjs";
|
|
6
6
|
import { Secp256k1PublicKey } from "../keypairs/secp256k1/publickey.mjs";
|
|
7
7
|
import { Secp256r1PublicKey } from "../keypairs/secp256r1/publickey.mjs";
|
|
8
|
+
import { MLDSA65PublicKey } from "../keypairs/mldsa65/publickey.mjs";
|
|
8
9
|
import { MultiSigPublicKey } from "../multisig/publickey.mjs";
|
|
9
10
|
import { fromBase64 } from "@mysten/bcs";
|
|
10
11
|
|
|
@@ -95,6 +96,9 @@ function publicKeyFromRawBytes(signatureScheme, bytes, options = {}) {
|
|
|
95
96
|
case "Passkey":
|
|
96
97
|
publicKey = new PasskeyPublicKey(bytes);
|
|
97
98
|
break;
|
|
99
|
+
case "MLDSA65":
|
|
100
|
+
publicKey = new MLDSA65PublicKey(bytes);
|
|
101
|
+
break;
|
|
98
102
|
default: throw new Error(`Unsupported signature scheme ${signatureScheme}`);
|
|
99
103
|
}
|
|
100
104
|
if (options.address && publicKey.toSuiAddress() !== options.address) throw new Error(`Public key bytes do not match the provided address`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.mjs","names":[],"sources":["../../src/verify/verify.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\n\nimport type { PublicKey, SignatureFlag, SignatureScheme } from '../cryptography/index.js';\nimport { parseSerializedSignature, SIGNATURE_FLAG_TO_SCHEME } from '../cryptography/index.js';\nimport { Ed25519PublicKey } from '../keypairs/ed25519/publickey.js';\nimport { PasskeyPublicKey } from '../keypairs/passkey/publickey.js';\nimport { Secp256k1PublicKey } from '../keypairs/secp256k1/publickey.js';\nimport { Secp256r1PublicKey } from '../keypairs/secp256r1/publickey.js';\nimport { MultiSigPublicKey } from '../multisig/publickey.js';\nimport { ZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * Whether `signature` is a valid signature over `bytes` (and, if `options.address`\n * is given, was produced by that address). Returns `false` for a malformed or\n * cryptographically invalid signature, or one that doesn't match the address;\n * only an *environmental* failure (e.g. a zkLogin JWK/epoch lookup) throws, so a\n * network blip is never reported as an invalid signature.\n */\nexport async function isValidSignature(\n\tbytes: Uint8Array,\n\tsignature: string,\n\toptions: { address?: string } = {},\n): Promise<boolean> {\n\tconst parsed = tryParseSignature(signature);\n\tif (!parsed) return false;\n\tif (!(await parsed.publicKey.verify(bytes, parsed.serializedSignature))) return false;\n\treturn options.address ? parsed.publicKey.verifyAddress(options.address) : true;\n}\n\n/** Like {@link isValidSignature}, for a personal message. */\nexport async function isValidPersonalMessageSignature(\n\tmessage: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<boolean> {\n\tconst parsed = tryParseSignature(signature, { client: options.client });\n\tif (!parsed) return false;\n\tif (!(await parsed.publicKey.verifyPersonalMessage(message, parsed.serializedSignature))) {\n\t\treturn false;\n\t}\n\treturn options.address ? parsed.publicKey.verifyAddress(options.address) : true;\n}\n\n/** Like {@link isValidSignature}, for transaction bytes. */\nexport async function isValidTransactionSignature(\n\ttransaction: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<boolean> {\n\tconst parsed = tryParseSignature(signature, { client: options.client });\n\tif (!parsed) return false;\n\tif (!(await parsed.publicKey.verifyTransaction(transaction, parsed.serializedSignature))) {\n\t\treturn false;\n\t}\n\treturn options.address ? parsed.publicKey.verifyAddress(options.address) : true;\n}\n\nexport async function verifySignature(\n\tbytes: Uint8Array,\n\tsignature: string,\n\toptions: { address?: string } = {},\n): Promise<PublicKey> {\n\tconst { publicKey } = parseSignature(signature);\n\tif (!(await isValidSignature(bytes, signature))) {\n\t\tthrow new Error(`Signature is not valid for the provided data`);\n\t}\n\tif (options.address && !publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\treturn publicKey;\n}\n\nexport async function verifyPersonalMessageSignature(\n\tmessage: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst { publicKey } = parseSignature(signature, options);\n\tif (!(await isValidPersonalMessageSignature(message, signature, { client: options.client }))) {\n\t\tthrow new Error(`Signature is not valid for the provided message`);\n\t}\n\tif (options.address && !publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\treturn publicKey;\n}\n\nexport async function verifyTransactionSignature(\n\ttransaction: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst { publicKey } = parseSignature(signature, options);\n\tif (!(await isValidTransactionSignature(transaction, signature, { client: options.client }))) {\n\t\tthrow new Error(`Signature is not valid for the provided Transaction`);\n\t}\n\tif (options.address && !publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\treturn publicKey;\n}\n\nfunction parseSignature(signature: string, options: { client?: ClientWithCoreApi } = {}) {\n\tconst parsedSignature = parseSerializedSignature(signature);\n\n\tif (parsedSignature.signatureScheme === 'MultiSig') {\n\t\treturn {\n\t\t\t...parsedSignature,\n\t\t\tpublicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk),\n\t\t};\n\t}\n\n\tconst publicKey = publicKeyFromRawBytes(\n\t\tparsedSignature.signatureScheme,\n\t\tparsedSignature.publicKey,\n\t\toptions,\n\t);\n\treturn {\n\t\t...parsedSignature,\n\t\tpublicKey,\n\t};\n}\n\n/** {@link parseSignature}, returning `null` instead of throwing on a malformed signature. */\nfunction tryParseSignature(signature: string, options: { client?: ClientWithCoreApi } = {}) {\n\ttry {\n\t\treturn parseSignature(signature, options);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function publicKeyFromRawBytes(\n\tsignatureScheme: SignatureScheme,\n\tbytes: Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): PublicKey {\n\tlet publicKey: PublicKey;\n\tswitch (signatureScheme) {\n\t\tcase 'ED25519':\n\t\t\tpublicKey = new Ed25519PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256k1':\n\t\t\tpublicKey = new Secp256k1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256r1':\n\t\t\tpublicKey = new Secp256r1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'MultiSig':\n\t\t\tpublicKey = new MultiSigPublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'ZkLogin':\n\t\t\tpublicKey = ZkLoginPublicIdentifier.fromBytes(bytes, options);\n\t\t\tbreak;\n\t\tcase 'Passkey':\n\t\t\tpublicKey = new PasskeyPublicKey(bytes);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported signature scheme ${signatureScheme}`);\n\t}\n\n\tif (options.address && publicKey.toSuiAddress() !== options.address) {\n\t\tthrow new Error(`Public key bytes do not match the provided address`);\n\t}\n\n\treturn publicKey;\n}\n\nexport function publicKeyFromSuiBytes(\n\tpublicKey: string | Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n) {\n\tconst bytes = typeof publicKey === 'string' ? fromBase64(publicKey) : publicKey;\n\n\tconst signatureScheme = SIGNATURE_FLAG_TO_SCHEME[bytes[0] as SignatureFlag];\n\n\treturn publicKeyFromRawBytes(signatureScheme, bytes.slice(1), options);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify.mjs","names":[],"sources":["../../src/verify/verify.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\n\nimport type { PublicKey, SignatureFlag, SignatureScheme } from '../cryptography/index.js';\nimport { parseSerializedSignature, SIGNATURE_FLAG_TO_SCHEME } from '../cryptography/index.js';\nimport { Ed25519PublicKey } from '../keypairs/ed25519/publickey.js';\nimport { MLDSA65PublicKey } from '../keypairs/mldsa65/publickey.js';\nimport { PasskeyPublicKey } from '../keypairs/passkey/publickey.js';\nimport { Secp256k1PublicKey } from '../keypairs/secp256k1/publickey.js';\nimport { Secp256r1PublicKey } from '../keypairs/secp256r1/publickey.js';\nimport { MultiSigPublicKey } from '../multisig/publickey.js';\nimport { ZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * Whether `signature` is a valid signature over `bytes` (and, if `options.address`\n * is given, was produced by that address). Returns `false` for a malformed or\n * cryptographically invalid signature, or one that doesn't match the address;\n * only an *environmental* failure (e.g. a zkLogin JWK/epoch lookup) throws, so a\n * network blip is never reported as an invalid signature.\n */\nexport async function isValidSignature(\n\tbytes: Uint8Array,\n\tsignature: string,\n\toptions: { address?: string } = {},\n): Promise<boolean> {\n\tconst parsed = tryParseSignature(signature);\n\tif (!parsed) return false;\n\tif (!(await parsed.publicKey.verify(bytes, parsed.serializedSignature))) return false;\n\treturn options.address ? parsed.publicKey.verifyAddress(options.address) : true;\n}\n\n/** Like {@link isValidSignature}, for a personal message. */\nexport async function isValidPersonalMessageSignature(\n\tmessage: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<boolean> {\n\tconst parsed = tryParseSignature(signature, { client: options.client });\n\tif (!parsed) return false;\n\tif (!(await parsed.publicKey.verifyPersonalMessage(message, parsed.serializedSignature))) {\n\t\treturn false;\n\t}\n\treturn options.address ? parsed.publicKey.verifyAddress(options.address) : true;\n}\n\n/** Like {@link isValidSignature}, for transaction bytes. */\nexport async function isValidTransactionSignature(\n\ttransaction: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<boolean> {\n\tconst parsed = tryParseSignature(signature, { client: options.client });\n\tif (!parsed) return false;\n\tif (!(await parsed.publicKey.verifyTransaction(transaction, parsed.serializedSignature))) {\n\t\treturn false;\n\t}\n\treturn options.address ? parsed.publicKey.verifyAddress(options.address) : true;\n}\n\nexport async function verifySignature(\n\tbytes: Uint8Array,\n\tsignature: string,\n\toptions: { address?: string } = {},\n): Promise<PublicKey> {\n\tconst { publicKey } = parseSignature(signature);\n\tif (!(await isValidSignature(bytes, signature))) {\n\t\tthrow new Error(`Signature is not valid for the provided data`);\n\t}\n\tif (options.address && !publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\treturn publicKey;\n}\n\nexport async function verifyPersonalMessageSignature(\n\tmessage: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst { publicKey } = parseSignature(signature, options);\n\tif (!(await isValidPersonalMessageSignature(message, signature, { client: options.client }))) {\n\t\tthrow new Error(`Signature is not valid for the provided message`);\n\t}\n\tif (options.address && !publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\treturn publicKey;\n}\n\nexport async function verifyTransactionSignature(\n\ttransaction: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst { publicKey } = parseSignature(signature, options);\n\tif (!(await isValidTransactionSignature(transaction, signature, { client: options.client }))) {\n\t\tthrow new Error(`Signature is not valid for the provided Transaction`);\n\t}\n\tif (options.address && !publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\treturn publicKey;\n}\n\nfunction parseSignature(signature: string, options: { client?: ClientWithCoreApi } = {}) {\n\tconst parsedSignature = parseSerializedSignature(signature);\n\n\tif (parsedSignature.signatureScheme === 'MultiSig') {\n\t\treturn {\n\t\t\t...parsedSignature,\n\t\t\tpublicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk),\n\t\t};\n\t}\n\n\tconst publicKey = publicKeyFromRawBytes(\n\t\tparsedSignature.signatureScheme,\n\t\tparsedSignature.publicKey,\n\t\toptions,\n\t);\n\treturn {\n\t\t...parsedSignature,\n\t\tpublicKey,\n\t};\n}\n\n/** {@link parseSignature}, returning `null` instead of throwing on a malformed signature. */\nfunction tryParseSignature(signature: string, options: { client?: ClientWithCoreApi } = {}) {\n\ttry {\n\t\treturn parseSignature(signature, options);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function publicKeyFromRawBytes(\n\tsignatureScheme: SignatureScheme,\n\tbytes: Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): PublicKey {\n\tlet publicKey: PublicKey;\n\tswitch (signatureScheme) {\n\t\tcase 'ED25519':\n\t\t\tpublicKey = new Ed25519PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256k1':\n\t\t\tpublicKey = new Secp256k1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256r1':\n\t\t\tpublicKey = new Secp256r1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'MultiSig':\n\t\t\tpublicKey = new MultiSigPublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'ZkLogin':\n\t\t\tpublicKey = ZkLoginPublicIdentifier.fromBytes(bytes, options);\n\t\t\tbreak;\n\t\tcase 'Passkey':\n\t\t\tpublicKey = new PasskeyPublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'MLDSA65':\n\t\t\tpublicKey = new MLDSA65PublicKey(bytes);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported signature scheme ${signatureScheme}`);\n\t}\n\n\tif (options.address && publicKey.toSuiAddress() !== options.address) {\n\t\tthrow new Error(`Public key bytes do not match the provided address`);\n\t}\n\n\treturn publicKey;\n}\n\nexport function publicKeyFromSuiBytes(\n\tpublicKey: string | Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n) {\n\tconst bytes = typeof publicKey === 'string' ? fromBase64(publicKey) : publicKey;\n\n\tconst signatureScheme = SIGNATURE_FLAG_TO_SCHEME[bytes[0] as SignatureFlag];\n\n\treturn publicKeyFromRawBytes(signatureScheme, bytes.slice(1), options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,eAAsB,iBACrB,OACA,WACA,UAAgC,EAAE,EACf;CACnB,MAAM,SAAS,kBAAkB,UAAU;AAC3C,KAAI,CAAC,OAAQ,QAAO;AACpB,KAAI,CAAE,MAAM,OAAO,UAAU,OAAO,OAAO,OAAO,oBAAoB,CAAG,QAAO;AAChF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,OAAM,IAAI,MAAM,qDAAqD;AAGtE,QAAO;;AAGR,SAAgB,sBACf,WACA,UAA4D,EAAE,EAC7D;CACD,MAAM,QAAQ,OAAO,cAAc,WAAW,WAAW,UAAU,GAAG;CAEtE,MAAM,kBAAkB,yBAAyB,MAAM;AAEvD,QAAO,sBAAsB,iBAAiB,MAAM,MAAM,EAAE,EAAE,QAAQ"}
|
package/dist/version.mjs
CHANGED
package/dist/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.36.0';\n"],"mappings":";AAKA,MAAa,kBAAkB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/zklogin/address-seed.d.ts
|
|
2
|
+
declare function hashASCIIStrToField(str: string, maxSize: number): bigint;
|
|
3
|
+
declare function genAddressSeed(salt: string | bigint, name: string, value: string, aud: string, max_name_length?: number, max_value_length?: number, max_aud_length?: number): bigint;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { genAddressSeed, hashASCIIStrToField };
|
|
6
|
+
//# sourceMappingURL=address-seed.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-seed.d.mts","names":[],"sources":["../../src/zklogin/address-seed.ts"],"mappings":";iBAoCgB,mBAAA,CAAoB,GAAA,UAAa,OAAA;AAAA,iBA+BjC,cAAA,CACf,IAAA,mBACA,IAAA,UACA,KAAA,UACA,GAAA,UACA,eAAA,WACA,gBAAA,WACA,cAAA"}
|