@mysten/sui 2.36.0 → 2.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @mysten/sui.js
2
2
 
3
+ ## 2.37.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 785655d: Fix verifying multisig signatures with zkLogin members: the client passed to
8
+ `verifyTransactionSignature`, `verifyPersonalMessageSignature`, `publicKeyFromSuiBytes`, or
9
+ `MultiSigPublicKey.fromPublicKeys` (new optional `client` option) is now used to verify each
10
+ zkLogin member. zkLogin signatures are now verified against the identifier's own address rather
11
+ than one derived from the signature, so a member's signature must come from that member's zkLogin
12
+ identity.
13
+
14
+ ### Patch Changes
15
+
16
+ - 3aa65e2: Speed up BCS parsing and serialization: faster ULEB, integer and byte reads and writes,
17
+ enum and option encoding, string decoding, and a single input conversion per write for transformed
18
+ types. Base58, base64 and hex helpers in `@mysten/utils` are faster and no longer depend on
19
+ `@scure/base`. Sui address and object digest encoding is faster.
20
+
21
+ Behaviour changes:
22
+
23
+ - `BcsReader.readBytes` and `readULEB` throw instead of reading past the end of a view into the
24
+ rest of its buffer.
25
+ - `bcs.option(T)` returns `null`/`undefined` when `T` reads as `null`/`undefined` (for example a
26
+ nested option's inner `None`), instead of `true`.
27
+ - `bcs.Address.serializedSize` and `bcs.ObjectDigest.serializedSize` throw on invalid input
28
+ instead of returning a size.
29
+
3
30
  ## 2.36.0
4
31
 
5
32
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/bcs/bcs.ts"],"mappings":";;;;;cAwIa,OAAA,EAAO,OAAA,kBAAA,SAAA;AAAA,iBAkMJ,aAAA,WAAwB,OAAA,MAAA,CAAc,CAAA,EAAG,CAAA,mBAAC,SAAA;;WAAA,eAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/bcs/bcs.ts"],"mappings":";;;;;cA+La,OAAA,EAAO,OAAA,kBAAA,SAAA;AAAA,iBAkMJ,aAAA,WAAwB,OAAA,MAAA,CAAc,CAAA,EAAG,CAAA,mBAAC,SAAA;;WAAA,eAAA,CAAA,OAAA"}
package/dist/bcs/bcs.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SUI_ADDRESS_LENGTH, isValidSuiAddress, normalizeSuiAddress } from "../utils/sui-types.mjs";
2
2
  import { TypeTagSerializer } from "./type-tag-serializer.mjs";
3
- import { bcs, fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from "@mysten/bcs";
3
+ import { bcs, fromBase58, fromBase64, toBase58, toBase64, toHex } from "@mysten/bcs";
4
4
 
5
5
  //#region src/bcs/bcs.ts
6
6
  function unsafe_u64(options) {
@@ -18,21 +18,55 @@ function optionEnum(type) {
18
18
  Some: type
19
19
  });
20
20
  }
21
+ const HEX_NIBBLES = new Int8Array(128).fill(-1);
22
+ for (let i = 0; i < 16; i++) {
23
+ HEX_NIBBLES["0123456789abcdef".charCodeAt(i)] = i;
24
+ HEX_NIBBLES["0123456789ABCDEF".charCodeAt(i)] = i;
25
+ }
26
+ function hexNibble(code) {
27
+ return code < 128 ? HEX_NIBBLES[code] : -1;
28
+ }
29
+ function decodeAddress(value) {
30
+ if (!value) return null;
31
+ const start = value.length >= 2 && value[0] === "0" && (value[1] === "x" || value[1] === "X") ? 2 : 0;
32
+ if (value.length - start > SUI_ADDRESS_LENGTH * 2) return null;
33
+ const bytes = new Uint8Array(SUI_ADDRESS_LENGTH);
34
+ let byteIndex = SUI_ADDRESS_LENGTH - 1;
35
+ let i = value.length - 1;
36
+ for (; i >= start + 1; i -= 2) {
37
+ const low = hexNibble(value.charCodeAt(i));
38
+ const high = hexNibble(value.charCodeAt(i - 1));
39
+ if (low < 0 || high < 0) return null;
40
+ bytes[byteIndex--] = high << 4 | low;
41
+ }
42
+ if (i === start) {
43
+ const low = hexNibble(value.charCodeAt(i));
44
+ if (low < 0) return null;
45
+ bytes[byteIndex] = low;
46
+ }
47
+ return bytes;
48
+ }
21
49
  const Address = bcs.bytes(SUI_ADDRESS_LENGTH).transform({
22
- validate: (val) => {
23
- const address = typeof val === "string" ? val : toHex(val);
50
+ input: (val) => {
51
+ if (typeof val === "string") {
52
+ const bytes = decodeAddress(val);
53
+ if (!bytes) throw new Error(`Invalid Sui address ${val}`);
54
+ return bytes;
55
+ }
56
+ const address = toHex(val);
24
57
  if (!address || !isValidSuiAddress(normalizeSuiAddress(address))) throw new Error(`Invalid Sui address ${address}`);
58
+ return val;
25
59
  },
26
- input: (val) => typeof val === "string" ? fromHex(normalizeSuiAddress(val)) : val,
27
- output: (val) => normalizeSuiAddress(toHex(val))
60
+ output: (val) => `0x${toHex(val)}`
28
61
  });
29
62
  const ObjectDigest = bcs.byteVector().transform({
30
63
  name: "ObjectDigest",
31
- input: (value) => fromBase58(value),
32
- output: (value) => toBase58(new Uint8Array(value)),
33
- validate: (value) => {
34
- if (fromBase58(value).length !== 32) throw new Error("ObjectDigest must be 32 bytes");
35
- }
64
+ input: (value) => {
65
+ const bytes = fromBase58(value);
66
+ if (bytes.length !== 32) throw new Error("ObjectDigest must be 32 bytes");
67
+ return bytes;
68
+ },
69
+ output: (value) => toBase58(value)
36
70
  });
37
71
  const SuiObjectRef = bcs.struct("SuiObjectRef", {
38
72
  objectId: Address,
@@ -77,7 +111,7 @@ const FundsWithdrawal = bcs.struct("FundsWithdrawal", {
77
111
  const CallArg = bcs.enum("CallArg", {
78
112
  Pure: bcs.struct("Pure", { bytes: bcs.byteVector().transform({
79
113
  input: (val) => typeof val === "string" ? fromBase64(val) : val,
80
- output: (val) => toBase64(new Uint8Array(val))
114
+ output: (val) => toBase64(val)
81
115
  }) }),
82
116
  Object: ObjectArg,
83
117
  FundsWithdrawal
@@ -129,7 +163,7 @@ const Command = bcs.enum("Command", {
129
163
  Publish: bcs.struct("Publish", {
130
164
  modules: bcs.vector(bcs.byteVector().transform({
131
165
  input: (val) => typeof val === "string" ? fromBase64(val) : val,
132
- output: (val) => toBase64(new Uint8Array(val))
166
+ output: (val) => toBase64(val)
133
167
  })),
134
168
  dependencies: bcs.vector(Address)
135
169
  }),
@@ -143,7 +177,7 @@ const Command = bcs.enum("Command", {
143
177
  Upgrade: bcs.struct("Upgrade", {
144
178
  modules: bcs.vector(bcs.byteVector().transform({
145
179
  input: (val) => typeof val === "string" ? fromBase64(val) : val,
146
- output: (val) => toBase64(new Uint8Array(val))
180
+ output: (val) => toBase64(val)
147
181
  })),
148
182
  dependencies: bcs.vector(Address),
149
183
  package: Address,
@@ -256,7 +290,7 @@ const MultiSig = bcs.struct("MultiSig", {
256
290
  });
257
291
  const base64String = bcs.byteVector().transform({
258
292
  input: (val) => typeof val === "string" ? fromBase64(val) : val,
259
- output: (val) => toBase64(new Uint8Array(val))
293
+ output: (val) => toBase64(val)
260
294
  });
261
295
  const PasskeyAuthenticator = bcs.struct("PasskeyAuthenticator", {
262
296
  authenticatorData: bcs.byteVector(),
@@ -1 +1 @@
1
- {"version":3,"file":"bcs.mjs","names":[],"sources":["../../src/bcs/bcs.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { BcsType, BcsTypeOptions } from '@mysten/bcs';\nimport { bcs, fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from '@mysten/bcs';\n\nimport { isValidSuiAddress, normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport { TypeTagSerializer } from './type-tag-serializer.js';\nimport type { TypeTag as TypeTagType } from './types.js';\n\nfunction unsafe_u64(options?: BcsTypeOptions<number>) {\n\treturn bcs\n\t\t.u64({\n\t\t\tname: 'unsafe_u64',\n\t\t\t...(options as object),\n\t\t})\n\t\t.transform({\n\t\t\tinput: (val: number | string) => val,\n\t\t\toutput: (val) => Number(val),\n\t\t});\n}\n\nfunction optionEnum<T extends BcsType<any, any>>(type: T) {\n\treturn bcs.enum('Option', {\n\t\tNone: null,\n\t\tSome: type,\n\t});\n}\n\nexport const Address = bcs.bytes(SUI_ADDRESS_LENGTH).transform({\n\tvalidate: (val) => {\n\t\tconst address = typeof val === 'string' ? val : toHex(val);\n\t\tif (!address || !isValidSuiAddress(normalizeSuiAddress(address))) {\n\t\t\tthrow new Error(`Invalid Sui address ${address}`);\n\t\t}\n\t},\n\tinput: (val: string | Uint8Array) =>\n\t\ttypeof val === 'string' ? fromHex(normalizeSuiAddress(val)) : val,\n\toutput: (val) => normalizeSuiAddress(toHex(val)),\n});\n\nexport const ObjectDigest = bcs.byteVector().transform({\n\tname: 'ObjectDigest',\n\tinput: (value: string) => fromBase58(value),\n\toutput: (value) => toBase58(new Uint8Array(value)),\n\tvalidate: (value) => {\n\t\tif (fromBase58(value).length !== 32) {\n\t\t\tthrow new Error('ObjectDigest must be 32 bytes');\n\t\t}\n\t},\n});\n\nexport const SuiObjectRef = bcs.struct('SuiObjectRef', {\n\tobjectId: Address,\n\tversion: bcs.u64(),\n\tdigest: ObjectDigest,\n});\n\nexport const SharedObjectRef = bcs.struct('SharedObjectRef', {\n\tobjectId: Address,\n\tinitialSharedVersion: bcs.u64(),\n\tmutable: bcs.bool(),\n});\n\nexport const ObjectArg = bcs.enum('ObjectArg', {\n\tImmOrOwnedObject: SuiObjectRef,\n\tSharedObject: SharedObjectRef,\n\tReceiving: SuiObjectRef,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const Owner = bcs.enum('Owner', {\n\tAddressOwner: Address,\n\tObjectOwner: Address,\n\tShared: bcs.struct('Shared', {\n\t\tinitialSharedVersion: bcs.u64(),\n\t}),\n\tImmutable: null,\n\tConsensusAddressOwner: bcs.struct('ConsensusAddressOwner', {\n\t\tstartVersion: bcs.u64(),\n\t\towner: Address,\n\t}),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const Reservation = bcs.enum('Reservation', {\n\tMaxAmountU64: bcs.u64(),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const WithdrawalType = bcs.enum('WithdrawalType', {\n\tBalance: bcs.lazy(() => TypeTag),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const WithdrawFrom = bcs.enum('WithdrawFrom', {\n\tSender: null,\n\tSponsor: null,\n\tSenderAllowance: bcs.struct('SenderAllowance', {\n\t\tfunder: Address,\n\t\tallowance: Address,\n\t}),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const FundsWithdrawal = bcs.struct('FundsWithdrawal', {\n\treservation: Reservation,\n\ttypeArg: WithdrawalType,\n\twithdrawFrom: WithdrawFrom,\n});\n\nexport const CallArg = bcs.enum('CallArg', {\n\tPure: bcs.struct('Pure', {\n\t\tbytes: bcs.byteVector().transform({\n\t\t\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\t\t\toutput: (val) => toBase64(new Uint8Array(val)),\n\t\t}),\n\t}),\n\tObject: ObjectArg,\n\tFundsWithdrawal: FundsWithdrawal,\n});\n\nconst InnerTypeTag: BcsType<TypeTagType, TypeTagType> = bcs.enum('TypeTag', {\n\tbool: null,\n\tu8: null,\n\tu64: null,\n\tu128: null,\n\taddress: null,\n\tsigner: null,\n\tvector: bcs.lazy(() => InnerTypeTag),\n\tstruct: bcs.lazy(() => StructTag),\n\tu16: null,\n\tu32: null,\n\tu256: null,\n}) as BcsType<TypeTagType>;\n\nexport const TypeTag = InnerTypeTag.transform({\n\tinput: (typeTag: string | TypeTagType) =>\n\t\ttypeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag, true) : typeTag,\n\toutput: (typeTag: TypeTagType) => TypeTagSerializer.tagToString(typeTag),\n});\n\nexport const Argument = bcs.enum('Argument', {\n\tGasCoin: null,\n\tInput: bcs.u16(),\n\tResult: bcs.u16(),\n\tNestedResult: bcs.tuple([bcs.u16(), bcs.u16()]),\n});\n\nexport const ProgrammableMoveCall = bcs.struct('ProgrammableMoveCall', {\n\tpackage: Address,\n\tmodule: bcs.string(),\n\tfunction: bcs.string(),\n\ttypeArguments: bcs.vector(TypeTag),\n\targuments: bcs.vector(Argument),\n});\n\nexport const Command = bcs.enum('Command', {\n\t/**\n\t * A Move Call - any public Move function can be called via\n\t * this transaction. The results can be used that instant to pass\n\t * into the next transaction.\n\t */\n\tMoveCall: ProgrammableMoveCall,\n\t/**\n\t * Transfer vector of objects to a receiver.\n\t */\n\tTransferObjects: bcs.struct('TransferObjects', {\n\t\tobjects: bcs.vector(Argument),\n\t\taddress: Argument,\n\t}),\n\t// /**\n\t// * Split `amount` from a `coin`.\n\t// */\n\tSplitCoins: bcs.struct('SplitCoins', {\n\t\tcoin: Argument,\n\t\tamounts: bcs.vector(Argument),\n\t}),\n\t// /**\n\t// * Merge Vector of Coins (`sources`) into a `destination`.\n\t// */\n\tMergeCoins: bcs.struct('MergeCoins', {\n\t\tdestination: Argument,\n\t\tsources: bcs.vector(Argument),\n\t}),\n\t// /**\n\t// * Publish a Move module.\n\t// */\n\tPublish: bcs.struct('Publish', {\n\t\tmodules: bcs.vector(\n\t\t\tbcs.byteVector().transform({\n\t\t\t\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\t\t\t\toutput: (val) => toBase64(new Uint8Array(val)),\n\t\t\t}),\n\t\t),\n\t\tdependencies: bcs.vector(Address),\n\t}),\n\t// /**\n\t// * Build a vector of objects using the input arguments.\n\t// * It is impossible to export construct a `vector<T: key>` otherwise,\n\t// * so this call serves a utility function.\n\t// */\n\tMakeMoveVec: bcs.struct('MakeMoveVec', {\n\t\ttype: optionEnum(TypeTag).transform({\n\t\t\tinput: (val: string | null) =>\n\t\t\t\tval === null\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tNone: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tSome: val,\n\t\t\t\t\t\t},\n\t\t\toutput: (val) => val.Some ?? null,\n\t\t}),\n\t\telements: bcs.vector(Argument),\n\t}),\n\tUpgrade: bcs.struct('Upgrade', {\n\t\tmodules: bcs.vector(\n\t\t\tbcs.byteVector().transform({\n\t\t\t\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\t\t\t\toutput: (val) => toBase64(new Uint8Array(val)),\n\t\t\t}),\n\t\t),\n\t\tdependencies: bcs.vector(Address),\n\t\tpackage: Address,\n\t\tticket: Argument,\n\t}),\n});\n\nexport const ProgrammableTransaction = bcs.struct('ProgrammableTransaction', {\n\tinputs: bcs.vector(CallArg),\n\tcommands: bcs.vector(Command),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const ValidDuring = bcs.struct('ValidDuring', {\n\tminEpoch: bcs.option(bcs.u64()),\n\tmaxEpoch: bcs.option(bcs.u64()),\n\tminTimestamp: bcs.option(bcs.u64()),\n\tmaxTimestamp: bcs.option(bcs.u64()),\n\tchain: ObjectDigest,\n\tnonce: bcs.u32(),\n});\n\nexport function assertAllowedProposersNotEmpty(proposers: number[]) {\n\tif (proposers.length === 0) {\n\t\tthrow new Error('Allowed proposers must not be empty');\n\t}\n\n\treturn proposers;\n}\n\nexport function assertAllowedProposersStrictlyIncreasing(proposers: number[]) {\n\tassertAllowedProposersNotEmpty(proposers);\n\n\tfor (let i = 1; i < proposers.length; i++) {\n\t\tif (proposers[i] <= proposers[i - 1]) {\n\t\t\tthrow new Error('Allowed proposers must be strictly increasing');\n\t\t}\n\t}\n\n\treturn proposers;\n}\n\n// Upstream only checks sortedness in `validity_check`, on submission, so decoding an unsorted\n// set must succeed. Empty is a deserialization error there, and here.\nconst AllowedProposerIndices = bcs.vector(bcs.u32()).transform({\n\tinput: assertAllowedProposersStrictlyIncreasing,\n\toutput: assertAllowedProposersNotEmpty,\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const AllowedProposers = bcs.struct('AllowedProposers', {\n\tepoch: bcs.u64(),\n\tproposers: AllowedProposerIndices,\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const Validity = bcs.struct('Validity', {\n\tminEpoch: bcs.option(bcs.u64()),\n\tmaxEpoch: bcs.option(bcs.u64()),\n\tminTimestamp: bcs.option(bcs.u64()),\n\tmaxTimestamp: bcs.option(bcs.u64()),\n\tchain: ObjectDigest,\n\tnonce: bcs.u32(),\n\tallowedProposers: bcs.option(AllowedProposers),\n});\n\nexport const TransactionExpiration = bcs.enum('TransactionExpiration', {\n\tNone: null,\n\tEpoch: unsafe_u64(),\n\tValidDuring: ValidDuring,\n\tValidity,\n});\n\nexport const StructTag = bcs.struct('StructTag', {\n\taddress: Address,\n\tmodule: bcs.string(),\n\tname: bcs.string(),\n\ttypeParams: bcs.vector(InnerTypeTag),\n});\n\nexport const GasData = bcs.struct('GasData', {\n\tpayment: bcs.vector(SuiObjectRef),\n\towner: Address,\n\tprice: bcs.u64(),\n\tbudget: bcs.u64(),\n});\n\nexport const IntentScope = bcs.enum('IntentScope', {\n\tTransactionData: null,\n\tTransactionEffects: null,\n\tCheckpointSummary: null,\n\tPersonalMessage: null,\n});\n\nexport const IntentVersion = bcs.enum('IntentVersion', {\n\tV0: null,\n});\n\nexport const AppId = bcs.enum('AppId', {\n\tSui: null,\n});\n\nexport const Intent = bcs.struct('Intent', {\n\tscope: IntentScope,\n\tversion: IntentVersion,\n\tappId: AppId,\n});\n\nexport function IntentMessage<T extends BcsType<any>>(T: T) {\n\treturn bcs.struct(`IntentMessage<${T.name}>`, {\n\t\tintent: Intent,\n\t\tvalue: T,\n\t});\n}\n\nexport const CompressedSignature = bcs.enum('CompressedSignature', {\n\tED25519: bcs.bytes(64),\n\tSecp256k1: bcs.bytes(64),\n\tSecp256r1: bcs.bytes(64),\n\tZkLogin: bcs.byteVector(),\n\tPasskey: bcs.byteVector(),\n\tMLDSA65: bcs.bytes(3309),\n});\n\n// Variant order must match Sui's `PublicKey` enum, which validators hash to\n// derive a multisig address.\nexport const PublicKey = bcs.enum('PublicKey', {\n\tED25519: bcs.bytes(32),\n\tSecp256k1: bcs.bytes(33),\n\tSecp256r1: bcs.bytes(33),\n\tZkLogin: bcs.byteVector(),\n\tPasskey: bcs.bytes(33),\n\tMLDSA65: bcs.bytes(1952),\n});\n\nexport const MultiSigPkMap = bcs.struct('MultiSigPkMap', {\n\tpubKey: PublicKey,\n\tweight: bcs.u8(),\n});\n\nexport const MultiSigPublicKey = bcs.struct('MultiSigPublicKey', {\n\tpk_map: bcs.vector(MultiSigPkMap),\n\tthreshold: bcs.u16(),\n});\n\nexport const MultiSig = bcs.struct('MultiSig', {\n\tsigs: bcs.vector(CompressedSignature),\n\tbitmap: bcs.u16(),\n\tmultisig_pk: MultiSigPublicKey,\n});\n\nexport const base64String = bcs.byteVector().transform({\n\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\toutput: (val) => toBase64(new Uint8Array(val)),\n});\n\nexport const PasskeyAuthenticator = bcs.struct('PasskeyAuthenticator', {\n\tauthenticatorData: bcs.byteVector(),\n\tclientDataJson: bcs.string(),\n\tuserSignature: bcs.byteVector(),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const MoveObjectType = bcs.enum('MoveObjectType', {\n\tOther: StructTag,\n\tGasCoin: null,\n\tStakedSui: null,\n\tCoin: TypeTag,\n\tAccumulatorBalanceWrapper: null,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const TypeOrigin = bcs.struct('TypeOrigin', {\n\tmoduleName: bcs.string(),\n\tdatatypeName: bcs.string(),\n\tpackage: Address,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const UpgradeInfo = bcs.struct('UpgradeInfo', {\n\tupgradedId: Address,\n\tupgradedVersion: bcs.u64(),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const MovePackage = bcs.struct('MovePackage', {\n\tid: Address,\n\tversion: bcs.u64(),\n\tmoduleMap: bcs.map(bcs.string(), bcs.byteVector()),\n\ttypeOriginTable: bcs.vector(TypeOrigin),\n\tlinkageTable: bcs.map(Address, UpgradeInfo),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const MoveObject = bcs.struct('MoveObject', {\n\ttype: MoveObjectType,\n\thasPublicTransfer: bcs.bool(),\n\tversion: bcs.u64(),\n\tcontents: bcs.byteVector(),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const Data = bcs.enum('Data', {\n\tMove: MoveObject,\n\tPackage: MovePackage,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const ObjectInner = bcs.struct('ObjectInner', {\n\tdata: Data,\n\towner: Owner,\n\tpreviousTransaction: ObjectDigest,\n\tstorageRebate: bcs.u64(),\n});\n"],"mappings":";;;;;AAUA,SAAS,WAAW,SAAkC;AACrD,QAAO,IACL,IAAI;EACJ,MAAM;EACN,GAAI;EACJ,CAAC,CACD,UAAU;EACV,QAAQ,QAAyB;EACjC,SAAS,QAAQ,OAAO,IAAI;EAC5B,CAAC;;AAGJ,SAAS,WAAwC,MAAS;AACzD,QAAO,IAAI,KAAK,UAAU;EACzB,MAAM;EACN,MAAM;EACN,CAAC;;AAGH,MAAa,UAAU,IAAI,MAAM,mBAAmB,CAAC,UAAU;CAC9D,WAAW,QAAQ;EAClB,MAAM,UAAU,OAAO,QAAQ,WAAW,MAAM,MAAM,IAAI;AAC1D,MAAI,CAAC,WAAW,CAAC,kBAAkB,oBAAoB,QAAQ,CAAC,CAC/D,OAAM,IAAI,MAAM,uBAAuB,UAAU;;CAGnD,QAAQ,QACP,OAAO,QAAQ,WAAW,QAAQ,oBAAoB,IAAI,CAAC,GAAG;CAC/D,SAAS,QAAQ,oBAAoB,MAAM,IAAI,CAAC;CAChD,CAAC;AAEF,MAAa,eAAe,IAAI,YAAY,CAAC,UAAU;CACtD,MAAM;CACN,QAAQ,UAAkB,WAAW,MAAM;CAC3C,SAAS,UAAU,SAAS,IAAI,WAAW,MAAM,CAAC;CAClD,WAAW,UAAU;AACpB,MAAI,WAAW,MAAM,CAAC,WAAW,GAChC,OAAM,IAAI,MAAM,gCAAgC;;CAGlD,CAAC;AAEF,MAAa,eAAe,IAAI,OAAO,gBAAgB;CACtD,UAAU;CACV,SAAS,I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CACpD,YAAY;CACZ,iBAAiB,IAAI,KAAK;CAC1B,CAAC;AAGF,MAAa,cAAc,IAAI,OAAO,eAAe;CACpD,IAAI;CACJ,SAAS,IAAI,KAAK;CAClB,WAAW,IAAI,IAAI,IAAI,QAAQ,EAAE,IAAI,YAAY,CAAC;CAClD,iBAAiB,IAAI,OAAO,WAAW;CACvC,cAAc,IAAI,IAAI,SAAS,YAAY;CAC3C,CAAC;AAGF,MAAa,aAAa,IAAI,OAAO,cAAc;CAClD,MAAM;CACN,mBAAmB,IAAI,MAAM;CAC7B,SAAS,IAAI,KAAK;CAClB,UAAU,IAAI,YAAY;CAC1B,CAAC;AAGF,MAAa,OAAO,IAAI,KAAK,QAAQ;CACpC,MAAM;CACN,SAAS;CACT,CAAC;AAGF,MAAa,cAAc,IAAI,OAAO,eAAe;CACpD,MAAM;CACN,OAAO;CACP,qBAAqB;CACrB,eAAe,IAAI,KAAK;CACxB,CAAC"}
1
+ {"version":3,"file":"bcs.mjs","names":[],"sources":["../../src/bcs/bcs.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { BcsType, BcsTypeOptions } from '@mysten/bcs';\nimport { bcs, fromBase58, fromBase64, toBase58, toBase64, toHex } from '@mysten/bcs';\n\nimport { isValidSuiAddress, normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport { TypeTagSerializer } from './type-tag-serializer.js';\nimport type { TypeTag as TypeTagType } from './types.js';\n\nfunction unsafe_u64(options?: BcsTypeOptions<number>) {\n\treturn bcs\n\t\t.u64({\n\t\t\tname: 'unsafe_u64',\n\t\t\t...(options as object),\n\t\t})\n\t\t.transform({\n\t\t\tinput: (val: number | string) => val,\n\t\t\toutput: (val) => Number(val),\n\t\t});\n}\n\nfunction optionEnum<T extends BcsType<any, any>>(type: T) {\n\treturn bcs.enum('Option', {\n\t\tNone: null,\n\t\tSome: type,\n\t});\n}\n\nconst HEX_NIBBLES = new Int8Array(128).fill(-1);\nfor (let i = 0; i < 16; i++) {\n\tHEX_NIBBLES['0123456789abcdef'.charCodeAt(i)] = i;\n\tHEX_NIBBLES['0123456789ABCDEF'.charCodeAt(i)] = i;\n}\nfunction hexNibble(code: number): number {\n\treturn code < 128 ? HEX_NIBBLES[code] : -1;\n}\n\n// Same bytes as fromHex(normalizeSuiAddress(value)) for valid addresses, or null for invalid ones\nfunction decodeAddress(value: string): Uint8Array<ArrayBuffer> | null {\n\tif (!value) {\n\t\treturn null;\n\t}\n\tconst start =\n\t\tvalue.length >= 2 && value[0] === '0' && (value[1] === 'x' || value[1] === 'X') ? 2 : 0;\n\tconst digits = value.length - start;\n\tif (digits > SUI_ADDRESS_LENGTH * 2) {\n\t\treturn null;\n\t}\n\n\tconst bytes = new Uint8Array(SUI_ADDRESS_LENGTH);\n\t// Right-align the digits, as normalizeSuiAddress left-pads with zeros\n\tlet byteIndex = SUI_ADDRESS_LENGTH - 1;\n\tlet i = value.length - 1;\n\tfor (; i >= start + 1; i -= 2) {\n\t\tconst low = hexNibble(value.charCodeAt(i));\n\t\tconst high = hexNibble(value.charCodeAt(i - 1));\n\t\tif (low < 0 || high < 0) {\n\t\t\treturn null;\n\t\t}\n\t\tbytes[byteIndex--] = (high << 4) | low;\n\t}\n\tif (i === start) {\n\t\tconst low = hexNibble(value.charCodeAt(i));\n\t\tif (low < 0) {\n\t\t\treturn null;\n\t\t}\n\t\tbytes[byteIndex] = low;\n\t}\n\n\treturn bytes;\n}\n\nexport const Address = bcs.bytes(SUI_ADDRESS_LENGTH).transform({\n\t// Validation lives in input so string addresses are only decoded once per write; transform's\n\t// validate runs input, so validate() still rejects invalid addresses.\n\tinput: (val: string | Uint8Array) => {\n\t\tif (typeof val === 'string') {\n\t\t\tconst bytes = decodeAddress(val);\n\t\t\tif (!bytes) {\n\t\t\t\tthrow new Error(`Invalid Sui address ${val}`);\n\t\t\t}\n\t\t\treturn bytes;\n\t\t}\n\t\tconst address = toHex(val);\n\t\tif (!address || !isValidSuiAddress(normalizeSuiAddress(address))) {\n\t\t\tthrow new Error(`Invalid Sui address ${address}`);\n\t\t}\n\t\treturn val;\n\t},\n\toutput: (val) => `0x${toHex(val)}`,\n});\n\nexport const ObjectDigest = bcs.byteVector().transform({\n\tname: 'ObjectDigest',\n\t// The length check lives in input so the digest is only base58-decoded once per write;\n\t// transform's validate runs input, so validate() still rejects digests of the wrong length.\n\tinput: (value: string) => {\n\t\tconst bytes = fromBase58(value);\n\t\tif (bytes.length !== 32) {\n\t\t\tthrow new Error('ObjectDigest must be 32 bytes');\n\t\t}\n\t\treturn bytes;\n\t},\n\toutput: (value) => toBase58(value),\n});\n\nexport const SuiObjectRef = bcs.struct('SuiObjectRef', {\n\tobjectId: Address,\n\tversion: bcs.u64(),\n\tdigest: ObjectDigest,\n});\n\nexport const SharedObjectRef = bcs.struct('SharedObjectRef', {\n\tobjectId: Address,\n\tinitialSharedVersion: bcs.u64(),\n\tmutable: bcs.bool(),\n});\n\nexport const ObjectArg = bcs.enum('ObjectArg', {\n\tImmOrOwnedObject: SuiObjectRef,\n\tSharedObject: SharedObjectRef,\n\tReceiving: SuiObjectRef,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const Owner = bcs.enum('Owner', {\n\tAddressOwner: Address,\n\tObjectOwner: Address,\n\tShared: bcs.struct('Shared', {\n\t\tinitialSharedVersion: bcs.u64(),\n\t}),\n\tImmutable: null,\n\tConsensusAddressOwner: bcs.struct('ConsensusAddressOwner', {\n\t\tstartVersion: bcs.u64(),\n\t\towner: Address,\n\t}),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const Reservation = bcs.enum('Reservation', {\n\tMaxAmountU64: bcs.u64(),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const WithdrawalType = bcs.enum('WithdrawalType', {\n\tBalance: bcs.lazy(() => TypeTag),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const WithdrawFrom = bcs.enum('WithdrawFrom', {\n\tSender: null,\n\tSponsor: null,\n\tSenderAllowance: bcs.struct('SenderAllowance', {\n\t\tfunder: Address,\n\t\tallowance: Address,\n\t}),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const FundsWithdrawal = bcs.struct('FundsWithdrawal', {\n\treservation: Reservation,\n\ttypeArg: WithdrawalType,\n\twithdrawFrom: WithdrawFrom,\n});\n\nexport const CallArg = bcs.enum('CallArg', {\n\tPure: bcs.struct('Pure', {\n\t\tbytes: bcs.byteVector().transform({\n\t\t\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\t\t\toutput: (val) => toBase64(val),\n\t\t}),\n\t}),\n\tObject: ObjectArg,\n\tFundsWithdrawal: FundsWithdrawal,\n});\n\nconst InnerTypeTag: BcsType<TypeTagType, TypeTagType> = bcs.enum('TypeTag', {\n\tbool: null,\n\tu8: null,\n\tu64: null,\n\tu128: null,\n\taddress: null,\n\tsigner: null,\n\tvector: bcs.lazy(() => InnerTypeTag),\n\tstruct: bcs.lazy(() => StructTag),\n\tu16: null,\n\tu32: null,\n\tu256: null,\n}) as BcsType<TypeTagType>;\n\nexport const TypeTag = InnerTypeTag.transform({\n\tinput: (typeTag: string | TypeTagType) =>\n\t\ttypeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag, true) : typeTag,\n\toutput: (typeTag: TypeTagType) => TypeTagSerializer.tagToString(typeTag),\n});\n\nexport const Argument = bcs.enum('Argument', {\n\tGasCoin: null,\n\tInput: bcs.u16(),\n\tResult: bcs.u16(),\n\tNestedResult: bcs.tuple([bcs.u16(), bcs.u16()]),\n});\n\nexport const ProgrammableMoveCall = bcs.struct('ProgrammableMoveCall', {\n\tpackage: Address,\n\tmodule: bcs.string(),\n\tfunction: bcs.string(),\n\ttypeArguments: bcs.vector(TypeTag),\n\targuments: bcs.vector(Argument),\n});\n\nexport const Command = bcs.enum('Command', {\n\t/**\n\t * A Move Call - any public Move function can be called via\n\t * this transaction. The results can be used that instant to pass\n\t * into the next transaction.\n\t */\n\tMoveCall: ProgrammableMoveCall,\n\t/**\n\t * Transfer vector of objects to a receiver.\n\t */\n\tTransferObjects: bcs.struct('TransferObjects', {\n\t\tobjects: bcs.vector(Argument),\n\t\taddress: Argument,\n\t}),\n\t// /**\n\t// * Split `amount` from a `coin`.\n\t// */\n\tSplitCoins: bcs.struct('SplitCoins', {\n\t\tcoin: Argument,\n\t\tamounts: bcs.vector(Argument),\n\t}),\n\t// /**\n\t// * Merge Vector of Coins (`sources`) into a `destination`.\n\t// */\n\tMergeCoins: bcs.struct('MergeCoins', {\n\t\tdestination: Argument,\n\t\tsources: bcs.vector(Argument),\n\t}),\n\t// /**\n\t// * Publish a Move module.\n\t// */\n\tPublish: bcs.struct('Publish', {\n\t\tmodules: bcs.vector(\n\t\t\tbcs.byteVector().transform({\n\t\t\t\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\t\t\t\toutput: (val) => toBase64(val),\n\t\t\t}),\n\t\t),\n\t\tdependencies: bcs.vector(Address),\n\t}),\n\t// /**\n\t// * Build a vector of objects using the input arguments.\n\t// * It is impossible to export construct a `vector<T: key>` otherwise,\n\t// * so this call serves a utility function.\n\t// */\n\tMakeMoveVec: bcs.struct('MakeMoveVec', {\n\t\ttype: optionEnum(TypeTag).transform({\n\t\t\tinput: (val: string | null) =>\n\t\t\t\tval === null\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tNone: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tSome: val,\n\t\t\t\t\t\t},\n\t\t\toutput: (val) => val.Some ?? null,\n\t\t}),\n\t\telements: bcs.vector(Argument),\n\t}),\n\tUpgrade: bcs.struct('Upgrade', {\n\t\tmodules: bcs.vector(\n\t\t\tbcs.byteVector().transform({\n\t\t\t\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\t\t\t\toutput: (val) => toBase64(val),\n\t\t\t}),\n\t\t),\n\t\tdependencies: bcs.vector(Address),\n\t\tpackage: Address,\n\t\tticket: Argument,\n\t}),\n});\n\nexport const ProgrammableTransaction = bcs.struct('ProgrammableTransaction', {\n\tinputs: bcs.vector(CallArg),\n\tcommands: bcs.vector(Command),\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const ValidDuring = bcs.struct('ValidDuring', {\n\tminEpoch: bcs.option(bcs.u64()),\n\tmaxEpoch: bcs.option(bcs.u64()),\n\tminTimestamp: bcs.option(bcs.u64()),\n\tmaxTimestamp: bcs.option(bcs.u64()),\n\tchain: ObjectDigest,\n\tnonce: bcs.u32(),\n});\n\nexport function assertAllowedProposersNotEmpty(proposers: number[]) {\n\tif (proposers.length === 0) {\n\t\tthrow new Error('Allowed proposers must not be empty');\n\t}\n\n\treturn proposers;\n}\n\nexport function assertAllowedProposersStrictlyIncreasing(proposers: number[]) {\n\tassertAllowedProposersNotEmpty(proposers);\n\n\tfor (let i = 1; i < proposers.length; i++) {\n\t\tif (proposers[i] <= proposers[i - 1]) {\n\t\t\tthrow new Error('Allowed proposers must be strictly increasing');\n\t\t}\n\t}\n\n\treturn proposers;\n}\n\n// Upstream only checks sortedness in `validity_check`, on submission, so decoding an unsorted\n// set must succeed. Empty is a deserialization error there, and here.\nconst AllowedProposerIndices = bcs.vector(bcs.u32()).transform({\n\tinput: assertAllowedProposersStrictlyIncreasing,\n\toutput: assertAllowedProposersNotEmpty,\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const AllowedProposers = bcs.struct('AllowedProposers', {\n\tepoch: bcs.u64(),\n\tproposers: AllowedProposerIndices,\n});\n\n// Rust: crates/sui-types/src/transaction.rs\nexport const Validity = bcs.struct('Validity', {\n\tminEpoch: bcs.option(bcs.u64()),\n\tmaxEpoch: bcs.option(bcs.u64()),\n\tminTimestamp: bcs.option(bcs.u64()),\n\tmaxTimestamp: bcs.option(bcs.u64()),\n\tchain: ObjectDigest,\n\tnonce: bcs.u32(),\n\tallowedProposers: bcs.option(AllowedProposers),\n});\n\nexport const TransactionExpiration = bcs.enum('TransactionExpiration', {\n\tNone: null,\n\tEpoch: unsafe_u64(),\n\tValidDuring: ValidDuring,\n\tValidity,\n});\n\nexport const StructTag = bcs.struct('StructTag', {\n\taddress: Address,\n\tmodule: bcs.string(),\n\tname: bcs.string(),\n\ttypeParams: bcs.vector(InnerTypeTag),\n});\n\nexport const GasData = bcs.struct('GasData', {\n\tpayment: bcs.vector(SuiObjectRef),\n\towner: Address,\n\tprice: bcs.u64(),\n\tbudget: bcs.u64(),\n});\n\nexport const IntentScope = bcs.enum('IntentScope', {\n\tTransactionData: null,\n\tTransactionEffects: null,\n\tCheckpointSummary: null,\n\tPersonalMessage: null,\n});\n\nexport const IntentVersion = bcs.enum('IntentVersion', {\n\tV0: null,\n});\n\nexport const AppId = bcs.enum('AppId', {\n\tSui: null,\n});\n\nexport const Intent = bcs.struct('Intent', {\n\tscope: IntentScope,\n\tversion: IntentVersion,\n\tappId: AppId,\n});\n\nexport function IntentMessage<T extends BcsType<any>>(T: T) {\n\treturn bcs.struct(`IntentMessage<${T.name}>`, {\n\t\tintent: Intent,\n\t\tvalue: T,\n\t});\n}\n\nexport const CompressedSignature = bcs.enum('CompressedSignature', {\n\tED25519: bcs.bytes(64),\n\tSecp256k1: bcs.bytes(64),\n\tSecp256r1: bcs.bytes(64),\n\tZkLogin: bcs.byteVector(),\n\tPasskey: bcs.byteVector(),\n\tMLDSA65: bcs.bytes(3309),\n});\n\n// Variant order must match Sui's `PublicKey` enum, which validators hash to\n// derive a multisig address.\nexport const PublicKey = bcs.enum('PublicKey', {\n\tED25519: bcs.bytes(32),\n\tSecp256k1: bcs.bytes(33),\n\tSecp256r1: bcs.bytes(33),\n\tZkLogin: bcs.byteVector(),\n\tPasskey: bcs.bytes(33),\n\tMLDSA65: bcs.bytes(1952),\n});\n\nexport const MultiSigPkMap = bcs.struct('MultiSigPkMap', {\n\tpubKey: PublicKey,\n\tweight: bcs.u8(),\n});\n\nexport const MultiSigPublicKey = bcs.struct('MultiSigPublicKey', {\n\tpk_map: bcs.vector(MultiSigPkMap),\n\tthreshold: bcs.u16(),\n});\n\nexport const MultiSig = bcs.struct('MultiSig', {\n\tsigs: bcs.vector(CompressedSignature),\n\tbitmap: bcs.u16(),\n\tmultisig_pk: MultiSigPublicKey,\n});\n\nexport const base64String = bcs.byteVector().transform({\n\tinput: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),\n\toutput: (val) => toBase64(val),\n});\n\nexport const PasskeyAuthenticator = bcs.struct('PasskeyAuthenticator', {\n\tauthenticatorData: bcs.byteVector(),\n\tclientDataJson: bcs.string(),\n\tuserSignature: bcs.byteVector(),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const MoveObjectType = bcs.enum('MoveObjectType', {\n\tOther: StructTag,\n\tGasCoin: null,\n\tStakedSui: null,\n\tCoin: TypeTag,\n\tAccumulatorBalanceWrapper: null,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const TypeOrigin = bcs.struct('TypeOrigin', {\n\tmoduleName: bcs.string(),\n\tdatatypeName: bcs.string(),\n\tpackage: Address,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const UpgradeInfo = bcs.struct('UpgradeInfo', {\n\tupgradedId: Address,\n\tupgradedVersion: bcs.u64(),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const MovePackage = bcs.struct('MovePackage', {\n\tid: Address,\n\tversion: bcs.u64(),\n\tmoduleMap: bcs.map(bcs.string(), bcs.byteVector()),\n\ttypeOriginTable: bcs.vector(TypeOrigin),\n\tlinkageTable: bcs.map(Address, UpgradeInfo),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const MoveObject = bcs.struct('MoveObject', {\n\ttype: MoveObjectType,\n\thasPublicTransfer: bcs.bool(),\n\tversion: bcs.u64(),\n\tcontents: bcs.byteVector(),\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const Data = bcs.enum('Data', {\n\tMove: MoveObject,\n\tPackage: MovePackage,\n});\n\n// Rust: crates/sui-types/src/object.rs\nexport const ObjectInner = bcs.struct('ObjectInner', {\n\tdata: Data,\n\towner: Owner,\n\tpreviousTransaction: ObjectDigest,\n\tstorageRebate: bcs.u64(),\n});\n"],"mappings":";;;;;AAUA,SAAS,WAAW,SAAkC;AACrD,QAAO,IACL,IAAI;EACJ,MAAM;EACN,GAAI;EACJ,CAAC,CACD,UAAU;EACV,QAAQ,QAAyB;EACjC,SAAS,QAAQ,OAAO,IAAI;EAC5B,CAAC;;AAGJ,SAAS,WAAwC,MAAS;AACzD,QAAO,IAAI,KAAK,UAAU;EACzB,MAAM;EACN,MAAM;EACN,CAAC;;AAGH,MAAM,cAAc,IAAI,UAAU,IAAI,CAAC,KAAK,GAAG;AAC/C,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;AAC5B,aAAY,mBAAmB,WAAW,EAAE,IAAI;AAChD,aAAY,mBAAmB,WAAW,EAAE,IAAI;;AAEjD,SAAS,UAAU,MAAsB;AACxC,QAAO,OAAO,MAAM,YAAY,QAAQ;;AAIzC,SAAS,cAAc,OAA+C;AACrE,KAAI,CAAC,MACJ,QAAO;CAER,MAAM,QACL,MAAM,UAAU,KAAK,MAAM,OAAO,QAAQ,MAAM,OAAO,OAAO,MAAM,OAAO,OAAO,IAAI;AAEvF,KADe,MAAM,SAAS,QACjB,qBAAqB,EACjC,QAAO;CAGR,MAAM,QAAQ,IAAI,WAAW,mBAAmB;CAEhD,IAAI,YAAY,qBAAqB;CACrC,IAAI,IAAI,MAAM,SAAS;AACvB,QAAO,KAAK,QAAQ,GAAG,KAAK,GAAG;EAC9B,MAAM,MAAM,UAAU,MAAM,WAAW,EAAE,CAAC;EAC1C,MAAM,OAAO,UAAU,MAAM,WAAW,IAAI,EAAE,CAAC;AAC/C,MAAI,MAAM,KAAK,OAAO,EACrB,QAAO;AAER,QAAM,eAAgB,QAAQ,IAAK;;AAEpC,KAAI,MAAM,OAAO;EAChB,MAAM,MAAM,UAAU,MAAM,WAAW,EAAE,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e,IAAI,KAAK;CACxB,CAAC"}
@@ -23,12 +23,6 @@ declare function toSerializedSignature({
23
23
  * Decodes a serialized signature into its constituent components: the signature scheme, the actual signature, and the public key
24
24
  */
25
25
  declare function parseSerializedSignature(serializedSignature: string): {
26
- serializedSignature: string;
27
- signatureScheme: "ED25519" | "Secp256k1" | "Secp256r1" | "MLDSA65";
28
- signature: Uint8Array<ArrayBuffer>;
29
- publicKey: Uint8Array<ArrayBuffer>;
30
- bytes: Uint8Array<ArrayBuffer>;
31
- } | {
32
26
  signatureScheme: "Passkey";
33
27
  serializedSignature: string;
34
28
  signature: Uint8Array<ArrayBufferLike>;
@@ -36,6 +30,12 @@ declare function parseSerializedSignature(serializedSignature: string): {
36
30
  clientDataJson: string;
37
31
  userSignature: Uint8Array<ArrayBuffer>;
38
32
  publicKey: Uint8Array<ArrayBuffer>;
33
+ } | {
34
+ serializedSignature: string;
35
+ signatureScheme: "ED25519" | "Secp256k1" | "Secp256r1" | "MLDSA65";
36
+ signature: Uint8Array<ArrayBuffer>;
37
+ publicKey: Uint8Array<ArrayBuffer>;
38
+ bytes: Uint8Array<ArrayBuffer>;
39
39
  } | {
40
40
  serializedSignature: string;
41
41
  signatureScheme: "ZkLogin";
@@ -1,6 +1,6 @@
1
1
  import { LookupNameRequest, LookupNameResponse, ReverseLookupNameRequest, ReverseLookupNameResponse } from "./name_service.mjs";
2
- import * as _protobuf_ts_runtime5 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc5 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime6 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc6 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/name_service.client.d.ts
@@ -23,9 +23,9 @@ interface INameServiceClient {
23
23
  declare class NameServiceClient implements INameServiceClient, ServiceInfo {
24
24
  private readonly _transport;
25
25
  typeName: string;
26
- methods: _protobuf_ts_runtime_rpc5.MethodInfo<any, any>[];
26
+ methods: _protobuf_ts_runtime_rpc6.MethodInfo<any, any>[];
27
27
  options: {
28
- [extensionName: string]: _protobuf_ts_runtime5.JsonValue;
28
+ [extensionName: string]: _protobuf_ts_runtime6.JsonValue;
29
29
  };
30
30
  constructor(_transport: RpcTransport);
31
31
  /**
@@ -1,6 +1,6 @@
1
1
  import { VerifySignatureRequest, VerifySignatureResponse } from "./signature_verification_service.mjs";
2
- import * as _protobuf_ts_runtime6 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc6 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime3 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc3 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.ts
@@ -21,9 +21,9 @@ interface ISignatureVerificationServiceClient {
21
21
  declare class SignatureVerificationServiceClient implements ISignatureVerificationServiceClient, ServiceInfo {
22
22
  private readonly _transport;
23
23
  typeName: string;
24
- methods: _protobuf_ts_runtime_rpc6.MethodInfo<any, any>[];
24
+ methods: _protobuf_ts_runtime_rpc3.MethodInfo<any, any>[];
25
25
  options: {
26
- [extensionName: string]: _protobuf_ts_runtime6.JsonValue;
26
+ [extensionName: string]: _protobuf_ts_runtime3.JsonValue;
27
27
  };
28
28
  constructor(_transport: RpcTransport);
29
29
  /**
@@ -1,6 +1,6 @@
1
1
  import { SubscribeCheckpointsRequest, SubscribeCheckpointsResponse, SubscribeEventsRequest, SubscribeEventsResponse, SubscribeTransactionsRequest, SubscribeTransactionsResponse } from "./subscription_service.mjs";
2
- import * as _protobuf_ts_runtime3 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc3 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime5 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc5 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServerStreamingCall, ServiceInfo } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/subscription_service.client.d.ts
@@ -100,9 +100,9 @@ interface ISubscriptionServiceClient {
100
100
  declare class SubscriptionServiceClient implements ISubscriptionServiceClient, ServiceInfo {
101
101
  private readonly _transport;
102
102
  typeName: string;
103
- methods: _protobuf_ts_runtime_rpc3.MethodInfo<any, any>[];
103
+ methods: _protobuf_ts_runtime_rpc5.MethodInfo<any, any>[];
104
104
  options: {
105
- [extensionName: string]: _protobuf_ts_runtime3.JsonValue;
105
+ [extensionName: string]: _protobuf_ts_runtime5.JsonValue;
106
106
  };
107
107
  constructor(_transport: RpcTransport);
108
108
  /**
@@ -54,6 +54,7 @@ type ParsedPartialMultiSigSignature = {
54
54
  * A MultiSig public key
55
55
  */
56
56
  declare class MultiSigPublicKey extends PublicKey {
57
+ #private;
57
58
  private rawBytes;
58
59
  private multisigPublicKey;
59
60
  private publicKeys;
@@ -73,13 +74,15 @@ declare class MultiSigPublicKey extends PublicKey {
73
74
  */
74
75
  static fromPublicKeys({
75
76
  threshold,
76
- publicKeys
77
+ publicKeys,
78
+ client
77
79
  }: {
78
80
  threshold: number;
79
81
  publicKeys: {
80
82
  publicKey: PublicKey;
81
83
  weight: number;
82
- }[];
84
+ }[]; /** Client used to verify zkLogin member signatures */
85
+ client?: ClientWithCoreApi;
83
86
  }): MultiSigPublicKey;
84
87
  /**
85
88
  * Checks if two MultiSig public keys are equal
@@ -104,9 +107,17 @@ declare class MultiSigPublicKey extends PublicKey {
104
107
  */
105
108
  flag(): number;
106
109
  /**
107
- * Verifies that the signature is valid for for the provided message
110
+ * Verifies that the signature is valid for the provided message
108
111
  */
109
112
  verify(message: Uint8Array, multisigSignature: string): Promise<boolean>;
113
+ /**
114
+ * Verifies that the signature is valid for the provided PersonalMessage
115
+ */
116
+ verifyPersonalMessage(message: Uint8Array, multisigSignature: string): Promise<boolean>;
117
+ /**
118
+ * Verifies that the signature is valid for the provided Transaction
119
+ */
120
+ verifyTransaction(transaction: Uint8Array, multisigSignature: string): Promise<boolean>;
110
121
  /**
111
122
  * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once
112
123
  * and that all the public keys involved are known and valid, and then serializes multisig into the standard format
@@ -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;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;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;;;;;EA7BR;;;;EAwCC,KAAA,WAAgB,UAAA,GAAa,u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W,MAAA,GAAS,iBAAA;AAAA,IAClB,8BAAA"}
@@ -17,11 +17,13 @@ const MIN_SIGNER_IN_MULTISIG = 1;
17
17
  * A MultiSig public key
18
18
  */
19
19
  var MultiSigPublicKey = class MultiSigPublicKey extends PublicKey {
20
+ #options;
20
21
  /**
21
22
  * Create a new MultiSigPublicKey object
22
23
  */
23
24
  constructor(value, options = {}) {
24
25
  super();
26
+ this.#options = options;
25
27
  if (typeof value === "string") {
26
28
  this.rawBytes = fromBase64(value);
27
29
  this.multisigPublicKey = suiBcs.MultiSigPublicKey.parse(this.rawBytes);
@@ -53,7 +55,7 @@ var MultiSigPublicKey = class MultiSigPublicKey extends PublicKey {
53
55
  /**
54
56
  * A static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.
55
57
  */
56
- static fromPublicKeys({ threshold, publicKeys }) {
58
+ static fromPublicKeys({ threshold, publicKeys, client }) {
57
59
  return new MultiSigPublicKey({
58
60
  pk_map: publicKeys.map(({ publicKey, weight }) => {
59
61
  return {
@@ -62,7 +64,7 @@ var MultiSigPublicKey = class MultiSigPublicKey extends PublicKey {
62
64
  };
63
65
  }),
64
66
  threshold
65
- });
67
+ }, { client });
66
68
  }
67
69
  /**
68
70
  * Checks if two MultiSig public keys are equal
@@ -110,16 +112,31 @@ var MultiSigPublicKey = class MultiSigPublicKey extends PublicKey {
110
112
  return SIGNATURE_SCHEME_TO_FLAG["MultiSig"];
111
113
  }
112
114
  /**
113
- * Verifies that the signature is valid for for the provided message
115
+ * Verifies that the signature is valid for the provided message
114
116
  */
115
117
  async verify(message, multisigSignature) {
118
+ return this.#verifyMembers(multisigSignature, (publicKey, signature) => publicKey.verify(message, signature));
119
+ }
120
+ /**
121
+ * Verifies that the signature is valid for the provided PersonalMessage
122
+ */
123
+ verifyPersonalMessage(message, multisigSignature) {
124
+ return this.#verifyMembers(multisigSignature, (publicKey, signature) => publicKey.verifyPersonalMessage(message, signature));
125
+ }
126
+ /**
127
+ * Verifies that the signature is valid for the provided Transaction
128
+ */
129
+ verifyTransaction(transaction, multisigSignature) {
130
+ return this.#verifyMembers(multisigSignature, (publicKey, signature) => publicKey.verifyTransaction(transaction, signature));
131
+ }
132
+ async #verifyMembers(multisigSignature, verifyMember) {
116
133
  const parsed = parseSerializedSignature(multisigSignature);
117
134
  if (parsed.signatureScheme !== "MultiSig") throw new Error("Invalid signature scheme");
118
135
  const { multisig } = parsed;
119
136
  let signatureWeight = 0;
120
137
  if (!bytesEqual(suiBcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(), suiBcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes())) return false;
121
- for (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {
122
- if (!await publicKey.verify(message, signature)) return false;
138
+ for (const { publicKey, weight, signature } of parsePartialSignatures(multisig, this.#options)) {
139
+ if (!await verifyMember(publicKey, signature)) return false;
123
140
  signatureWeight += weight;
124
141
  }
125
142
  return signatureWeight >= this.multisigPublicKey.threshold;
@@ -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\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,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5C,MAAI,IAAI,CAAC,yBAAyB,YAAY,CAAC;AAC/C,MAAI,IAAI,OAAO,EAAE;AACjB,SAAO,SAAS,IAAI;;;;;;AAOtB,SAAgB,uBACf,UACA,UAA0C,EAAE,EACT;CACnC,MAAM,MAAwC,IAAI,MAAM,SAAS,KAAK,OAAO;AAC7E,MAAK,IAAI,IAAI,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"}
1
+ {"version":3,"file":"publickey.mjs","names":["#options","bcs","#verifyMembers"],"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#options: { client?: ClientWithCoreApi };\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\tthis.#options = options;\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\tclient,\n\t}: {\n\t\tthreshold: number;\n\t\tpublicKeys: { publicKey: PublicKey; weight: number }[];\n\t\t/** Client used to verify zkLogin member signatures */\n\t\tclient?: ClientWithCoreApi;\n\t}) {\n\t\treturn new MultiSigPublicKey(\n\t\t\t{\n\t\t\t\tpk_map: publicKeys.map(({ publicKey, weight }) => {\n\t\t\t\t\tconst scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpubKey: { [scheme]: publicKey.toRawBytes() } as PublicKeyEnum,\n\t\t\t\t\t\tweight,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t\tthreshold,\n\t\t\t},\n\t\t\t{ client },\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 the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\treturn this.#verifyMembers(multisigSignature, (publicKey, signature) =>\n\t\t\tpublicKey.verify(message, signature),\n\t\t);\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for the provided PersonalMessage\n\t */\n\toverride verifyPersonalMessage(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Each member verifies with its own intent-aware method, so members that cannot verify a\n\t\t// raw digest (zkLogin, which is verified through the client) still work.\n\t\treturn this.#verifyMembers(multisigSignature, (publicKey, signature) =>\n\t\t\tpublicKey.verifyPersonalMessage(message, signature),\n\t\t);\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for the provided Transaction\n\t */\n\toverride verifyTransaction(transaction: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\treturn this.#verifyMembers(multisigSignature, (publicKey, signature) =>\n\t\t\tpublicKey.verifyTransaction(transaction, signature),\n\t\t);\n\t}\n\n\tasync #verifyMembers(\n\t\tmultisigSignature: string,\n\t\tverifyMember: (publicKey: PublicKey, signature: Uint8Array) => Promise<boolean>,\n\t): 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(\n\t\t\tmultisig,\n\t\t\tthis.#options,\n\t\t)) {\n\t\t\tif (!(await verifyMember(publicKey, 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;CAOhD;;;;CAIA,YAIC,OACA,UAA0C,EAAE,EAC3C;AACD,SAAO;AAEP,QAAKA,UAAW;AAEhB,MAAI,OAAO,UAAU,UAAU;AAC9B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AG,IAAI,IAAI,IACvB,MAAK,SAAU,KAAK,OAAQ,EAC3B,KAAI,KAAK,EAAE;AAGb,QAAO,WAAW,KAAK,IAAI"}
@@ -1 +1 @@
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"}
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,iBA2CK,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"}
@@ -59,7 +59,7 @@ function parseSignature(signature, options = {}) {
59
59
  const parsedSignature = parseSerializedSignature(signature);
60
60
  if (parsedSignature.signatureScheme === "MultiSig") return {
61
61
  ...parsedSignature,
62
- publicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk)
62
+ publicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk, { client: options.client })
63
63
  };
64
64
  const publicKey = publicKeyFromRawBytes(parsedSignature.signatureScheme, parsedSignature.publicKey, options);
65
65
  return {
@@ -88,7 +88,7 @@ function publicKeyFromRawBytes(signatureScheme, bytes, options = {}) {
88
88
  publicKey = new Secp256r1PublicKey(bytes);
89
89
  break;
90
90
  case "MultiSig":
91
- publicKey = new MultiSigPublicKey(bytes);
91
+ publicKey = new MultiSigPublicKey(bytes, { client: options.client });
92
92
  break;
93
93
  case "ZkLogin":
94
94
  publicKey = ZkLoginPublicIdentifier.fromBytes(bytes, options);
@@ -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 { 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,QAAO,QAAQ,UAAU,OAAO,UAAU,cAAc,QAAQ,QAAQ,GAAG;;;AAI5E,eAAsB,gCACrB,SACA,WACA,UAA4D,EAAE,EAC3C;CACnB,MAAM,SAAS,kBAAkB,WAAW,EAAE,QAAQ,QAAQ,QAAQ,CAAC;AACvE,KAAI,CAAC,OAAQ,QAAO;AACpB,KAAI,CAAE,MAAM,OAAO,UAAU,sBAAsB,SAAS,OAAO,oBAAoB,CACtF,QAAO;AAER,QAAO,QAAQ,UAAU,OA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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\t\tclient: options.client,\n\t\t\t}),\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, { client: options.client });\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,QAAO,QAAQ,UAAU,OAAO,UAAU,cAAc,QAAQ,QAAQ,GAAG;;;AAI5E,eAAsB,gCACrB,SACA,WACA,UAA4D,EAAE,EAC3C;CACnB,MAAM,SAAS,kBAAkB,WAAW,EAAE,QAAQ,QAAQ,QAAQ,CAAC;AACvE,KAAI,CAAC,OAAQ,QAAO;AACpB,KAAI,CAAE,MAAM,OAAO,UAAU,sBAAsB,SAAS,OAAO,oBAAoB,CACtF,QAAO;AAER,QAAO,QAAQ,UAAU,OAAO,UAAU,cAAc,QAAQ,QAAQ,GAAG;;;AAI5E,eAAsB,4BACrB,aACA,WACA,UAA4D,EAAE,EAC3C;CACnB,MAAM,SAAS,kBAAkB,WAAW,EAAE,QAAQ,QAAQ,QAAQ,CAAC;AACvE,KAAI,CAAC,OAAQ,QAAO;AACpB,KAAI,CAAE,MAAM,OAAO,UAAU,kBAAkB,aAAa,OAAO,oBAAoB,CACtF,QAAO;AAER,QAAO,QAAQ,UAAU,OAAO,UAAU,cAAc,QAAQ,QAAQ,GAAG;;AAG5E,eAAsB,gBACrB,OACA,WACA,U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AACH,SAAO,eAAe,WAAW,QAAQ;SAClC;AACP,SAAO;;;AAIT,SAAgB,sBACf,iBACA,OACA,UAA4D,EAAE,EAClD;CACZ,IAAI;AACJ,SAAQ,iBAAR;EACC,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,KAAK;AACJ,eAAY,IAAI,mBAAmB,MAAM;AACzC;EACD,KAAK;AACJ,eAAY,IAAI,mBAAmB,MAAM;AACzC;EACD,KAAK;AACJ,eAAY,IAAI,kBAAkB,OAAO,EAAE,QAAQ,QAAQ,QAAQ,CAAC;AACpE;EACD,KAAK;AACJ,eAAY,wBAAwB,UAAU,OAAO,QAAQ;AAC7D;EACD,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,QACC,OAAM,IAAI,MAAM,gCAAgC,kBAAkB;;AAGpE,KAAI,QAAQ,WAAW,UAAU,cAAc,KAAK,QAAQ,QAC3D,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
@@ -1,5 +1,5 @@
1
1
  //#region src/version.ts
2
- const PACKAGE_VERSION = "2.36.0";
2
+ const PACKAGE_VERSION = "2.37.0";
3
3
 
4
4
  //#endregion
5
5
  export { PACKAGE_VERSION };
@@ -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.36.0';\n"],"mappings":";AAKA,MAAa,kBAAkB"}
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.37.0';\n"],"mappings":";AAKA,MAAa,kBAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"mappings":";;;;;;AAoBA;;cAAa,uBAAA,SAAgC,SAAA;EAAA;EASJ;;;;cAA5B,KAAA,EAAO,iBAAA;IAAqB;EAAA;IAAY,MAAA,GAAS,iBAAA;EAAA;EAgCqB;;;EAAA,IAV9E,aAAA,CAAA;EAAA,OAIG,SAAA,CACN,KAAA,EAAO,UAAA;IAEN,MAAA;IACA,OAAA;IACA;EAAA;IACI,MAAA,GAAS,iBAAA;IAAmB,OAAA;IAAkB,aAAA;EAAA,IAA8B,uBAAA;EAAA,OAmC3E,SAAA,CAAU,OAAA,UAAiB,KAAA,EAAO,sBAAA,GAAsB,uBAAA;EAwET;;;EA9C7C,MAAA,CAAO,SAAA,EAAW,uBAAA;EAIlB,YAAA,CAAA;EA1GmC;;;EA+H5C,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;;;;EAOzB,IAAA,CAAA;EA7HwC;;;EAoIlC,MAAA,CAAO,QAAA,EAAU,UAAA,EAAY,UAAA,EAAY,UAAA,YAAsB,OAAA;EA9GjE;;;EAqHJ,qBAAA,CAAsB,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA9G1E;;;EA8HF,iBAAA,CAAkB,WAAA,EAAa,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA5H1E;;;EA2IO,aAAA,CAAc,OAAA;AAAA;AAAA,iBAMR,yBAAA,CACf,WAAA,UACA,GAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,aAAA;AAAA,IACrC,uBAAA"}
1
+ {"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"mappings":";;;;;;AAoBA;;cAAa,uBAAA,SAAgC,SAAA;EAAA;EASJ;;;;cAA5B,KAAA,EAAO,iBAAA;IAAqB;EAAA;IAAY,MAAA,GAAS,iBAAA;EAAA;EAgCqB;;;EAAA,IAV9E,aAAA,CAAA;EAAA,OAIG,SAAA,CACN,KAAA,EAAO,UAAA;IAEN,MAAA;IACA,OAAA;IACA;EAAA;IACI,MAAA,GAAS,iBAAA;IAAmB,OAAA;IAAkB,aAAA;EAAA,IAA8B,uBAAA;EAAA,OAmC3E,SAAA,CAAU,OAAA,UAAiB,KAAA,EAAO,sBAAA,GAAsB,uBAAA;EAwET;;;EA9C7C,MAAA,CAAO,SAAA,EAAW,uBAAA;EAIlB,YAAA,CAAA;EA1GmC;;;EA+H5C,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;;;;EAOzB,IAAA,CAAA;EA7HwC;;;EAoIlC,MAAA,CAAO,QAAA,EAAU,UAAA,EAAY,UAAA,EAAY,UAAA,YAAsB,OAAA;EA9GjE;;;EAqHJ,qBAAA,CAAsB,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA9G1E;;;EA+HF,iBAAA,CAAkB,WAAA,EAAa,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA7H1E;;;EA2IO,aAAA,CAAc,OAAA;AAAA;AAAA,iBAMR,yBAAA,CACf,WAAA,UACA,GAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,aAAA;AAAA,IACrC,uBAAA"}
@@ -96,7 +96,7 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
96
96
  verifyPersonalMessage(message, signature) {
97
97
  const parsedSignature = parseSerializedZkLoginSignature(signature);
98
98
  return graphqlVerifyZkLoginSignature({
99
- address: new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress(),
99
+ address: this.toSuiAddress(),
100
100
  bytes: toBase64(message),
101
101
  signature: parsedSignature.serializedSignature,
102
102
  intentScope: "PersonalMessage",
@@ -109,7 +109,7 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
109
109
  verifyTransaction(transaction, signature) {
110
110
  const parsedSignature = parseSerializedZkLoginSignature(signature);
111
111
  return graphqlVerifyZkLoginSignature({
112
- address: new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress(),
112
+ address: this.toSuiAddress(),
113
113
  bytes: toBase64(transaction),
114
114
  signature: parsedSignature.serializedSignature,
115
115
  intentScope: "TransactionData",
@@ -1 +1 @@
1
- {"version":3,"file":"publickey.mjs","names":["#client","#data","#legacyAddress","#toLegacyAddress"],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array<ArrayBuffer>;\n\t#client?: ClientWithCoreApi;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: ClientWithCoreApi } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\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\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);\n\t\t}\n\t}\n\n\t/**\n\t * Whether this identifier resolves to the deprecated legacy address derivation.\n\t */\n\tget legacyAddress(): boolean {\n\t\treturn this.#legacyAddress;\n\t}\n\n\tstatic fromBytes(\n\t\tbytes: Uint8Array,\n\t\t{\n\t\t\tclient,\n\t\t\taddress,\n\t\t\tlegacyAddress,\n\t\t}: { client?: ClientWithCoreApi; address?: string; legacyAddress?: boolean } = {},\n\t) {\n\t\tlet publicKey: ZkLoginPublicIdentifier;\n\n\t\tif (legacyAddress === true) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (legacyAddress === false) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (address) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\n\t\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\t\tclient,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(bytes, {\n\t\t\t\tclient,\n\t\t\t});\n\t\t}\n\n\t\tif (address && publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Public key bytes do not match the provided address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\tstatic fromProof(address: string, proof: ZkLoginSignatureInputs) {\n\t\tconst { issBase64Details, addressSeed } = proof;\n\t\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\n\t\tconst legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: true,\n\t\t});\n\n\t\tif (legacyPublicKey.toSuiAddress() === address) {\n\t\t\treturn legacyPublicKey;\n\t\t}\n\n\t\tconst publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: false,\n\t\t});\n\n\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Proof does not match address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toSuiAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\treturn this.#toLegacyAddress();\n\t\t}\n\n\t\treturn super.toSuiAddress();\n\t}\n\n\t#toLegacyAddress() {\n\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\taddressBytes[0] = this.flag();\n\t\taddressBytes.set(legacyBytes, 1);\n\t\treturn normalizeSuiAddress(\n\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),\n\t\t);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\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, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PersonalMessage',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TransactionData',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the public key is associated with the provided address\n\t */\n\toverride verifyAddress(address: string): boolean {\n\t\treturn address === super.toSuiAddress() || address === this.#toLegacyAddress();\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions: { client?: ClientWithCoreApi; legacyAddress: boolean },\n): ZkLoginPublicIdentifier {\n\tif (options.legacyAddress === undefined) {\n\t\tthrow new Error('legacyAddress parameter must be specified');\n\t}\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(normalizeZkLoginIssuer(iss));\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress: boolean) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient,\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PersonalMessage' | 'TransactionData';\n\tclient?: ClientWithCoreApi;\n}) {\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'A Sui Client (GRPC, GraphQL, or JSON RPC) is required to verify zkLogin signatures',\n\t\t);\n\t}\n\tconst resp = await client.core.verifyZkLoginSignature({\n\t\tbytes,\n\t\tsignature,\n\t\tintentScope,\n\t\taddress: address,\n\t});\n\n\treturn resp.success === true && resp.errors.length === 0;\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifier = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\tlegacyAddress: false,\n\t});\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifier.toRawBytes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,0BAAb,MAAa,gCAAgC,UAAU;CACtD;CACA;CACA;;;;;CAMA,YAAY,OAA0B,EAAE,WAA2C,EAAE,EAAE;AACtF,SAAO;AAEP,QAAKA,SAAU;AAEf,MAAI,OAAO,UAAU,SACpB,OAAKC,OAAQ,WAAW,MAAM;WACpB,iBAAiB,WAC3B,OAAKA,OAAQ;MAEb,OAAKA,OAAQ,WAAW,KAAK,MAAM;AAEpC,QAAKC,gBAAiB,MAAKD,KAAM,WAAW,MAAKA,KAAM,KAAK,IAAI;AAEhE,MAAI,MAAKC,cACR,OAAKD,OAAQ,+BAA+B,MAAKA,MAAO,MAAM;;;;;CAOhE,IAAI,gBAAyB;AAC5B,SAAO,MAAKC;;CAGb,OAAO,UACN,OACA,EACC,QACA,SACA,kBAC8E,EAAE,EAChF;EACD,IAAI;AAEJ,MAAI,kBAAkB,KACrB,aAAY,IAAI,wBAAwB,+BAA+B,OAAO,KAAK,EAAE,EACpF,QACA,CAAC;WACQ,kBAAkB,MAC5B,aAAY,IAAI,wBAAwB,+BAA+B,OAAO,MAAM,EAAE,EACrF,QACA,CAA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,iBAAiB,aAAa,GAAG,GACjC,uBAAuB,aAAa,GAAG;CAC1C,MAAM,OAAO,IAAI,WAAW,gBAAgB,UAAU,OAAO;AAC7D,MAAK,IAAI,MAAM,MAAM,GAAG,cAAc,EAAE,EAAE;AAC1C,MAAK,IAAI,WAAW,cAAc;AAClC,QAAO;;AAGR,eAAe,8BAA8B,EAC5C,SACA,OACA,WACA,aACA,UAOE;AACF,KAAI,CAAC,OACJ,OAAM,IAAI,MACT,qFACA;CAEF,MAAM,OAAO,MAAM,OAAO,KAAK,uBAAuB;EACrD;EACA;EACA;EACS;EACT,CAAC;AAEF,QAAO,KAAK,YAAY,QAAQ,KAAK,OAAO,WAAW;;AAGxD,SAAgB,gCAAgC,WAAgC;CAC/E,MAAM,QAAQ,OAAO,cAAc,WAAW,WAAW,UAAU,GAAG;AAEtE,KAAI,MAAM,OAAO,yBAAyB,QACzC,OAAM,IAAI,MAAM,2BAA2B;CAI5C,MAAM,EAAE,QAAQ,UAAU,kBAAkB,sBADrB,MAAM,MAAM,EAAE,CAC4C;CACjF,MAAM,EAAE,kBAAkB,gBAAgB;CAC1C,MAAM,MAAM,kBAA0B,kBAAkB,MAAM;CAC9D,MAAM,mBAAmB,0BAA0B,OAAO,YAAY,EAAE,KAAK,EAC5E,eAAe,OACf,CAAC;AACF,QAAO;EACN,qBAAqB,SAAS,MAAM;EACpC,iBAAiB;EACjB,SAAS;GACR;GACA;GACA;GACA;GACA,aAAa,OAAO,YAAY;GAChC;EACD,WAAW;EACX,WAAW,iBAAiB,YAAY;EACxC"}
1
+ {"version":3,"file":"publickey.mjs","names":["#client","#data","#legacyAddress","#toLegacyAddress"],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array<ArrayBuffer>;\n\t#client?: ClientWithCoreApi;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: ClientWithCoreApi } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\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\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);\n\t\t}\n\t}\n\n\t/**\n\t * Whether this identifier resolves to the deprecated legacy address derivation.\n\t */\n\tget legacyAddress(): boolean {\n\t\treturn this.#legacyAddress;\n\t}\n\n\tstatic fromBytes(\n\t\tbytes: Uint8Array,\n\t\t{\n\t\t\tclient,\n\t\t\taddress,\n\t\t\tlegacyAddress,\n\t\t}: { client?: ClientWithCoreApi; address?: string; legacyAddress?: boolean } = {},\n\t) {\n\t\tlet publicKey: ZkLoginPublicIdentifier;\n\n\t\tif (legacyAddress === true) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (legacyAddress === false) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (address) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\n\t\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\t\tclient,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(bytes, {\n\t\t\t\tclient,\n\t\t\t});\n\t\t}\n\n\t\tif (address && publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Public key bytes do not match the provided address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\tstatic fromProof(address: string, proof: ZkLoginSignatureInputs) {\n\t\tconst { issBase64Details, addressSeed } = proof;\n\t\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\n\t\tconst legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: true,\n\t\t});\n\n\t\tif (legacyPublicKey.toSuiAddress() === address) {\n\t\t\treturn legacyPublicKey;\n\t\t}\n\n\t\tconst publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: false,\n\t\t});\n\n\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Proof does not match address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toSuiAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\treturn this.#toLegacyAddress();\n\t\t}\n\n\t\treturn super.toSuiAddress();\n\t}\n\n\t#toLegacyAddress() {\n\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\taddressBytes[0] = this.flag();\n\t\taddressBytes.set(legacyBytes, 1);\n\t\treturn normalizeSuiAddress(\n\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),\n\t\t);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\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, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\t// Verify against this identifier's address, not one derived from the signature, so a\n\t\t\t// signature from a different zkLogin identity is rejected (as the chain does for multisig).\n\t\t\taddress: this.toSuiAddress(),\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PersonalMessage',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: this.toSuiAddress(),\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TransactionData',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the public key is associated with the provided address\n\t */\n\toverride verifyAddress(address: string): boolean {\n\t\treturn address === super.toSuiAddress() || address === this.#toLegacyAddress();\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions: { client?: ClientWithCoreApi; legacyAddress: boolean },\n): ZkLoginPublicIdentifier {\n\tif (options.legacyAddress === undefined) {\n\t\tthrow new Error('legacyAddress parameter must be specified');\n\t}\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(normalizeZkLoginIssuer(iss));\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress: boolean) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient,\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PersonalMessage' | 'TransactionData';\n\tclient?: ClientWithCoreApi;\n}) {\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'A Sui Client (GRPC, GraphQL, or JSON RPC) is required to verify zkLogin signatures',\n\t\t);\n\t}\n\tconst resp = await client.core.verifyZkLoginSignature({\n\t\tbytes,\n\t\tsignature,\n\t\tintentScope,\n\t\taddress: address,\n\t});\n\n\treturn resp.success === true && resp.errors.length === 0;\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifier = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\tlegacyAddress: false,\n\t});\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifier.toRawBytes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,0BAAb,MAAa,gCAAgC,UAAU;CACtD;CACA;CACA;;;;;CAMA,YAAY,OAA0B,EAAE,WAA2C,EAAE,EAAE;AACtF,SAAO;AAEP,QAAKA,SAAU;AAEf,MAAI,OAAO,UAAU,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OAAO,YAAY,EAAE,KAAK,EAC5E,eAAe,OACf,CAAC;AACF,QAAO;EACN,qBAAqB,SAAS,MAAM;EACpC,iBAAiB;EACjB,SAAS;GACR;GACA;GACA;GACA;GACA,aAAa,OAAO,YAAY;GAChC;EACD,WAAW;EACX,WAAW,iBAAiB,YAAY;EACxC"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui TypeScript API",
5
5
  "homepage": "https://sdk.mystenlabs.com",
6
- "version": "2.36.0",
6
+ "version": "2.37.0",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [
@@ -174,8 +174,8 @@
174
174
  "graphql": "^17.0.2",
175
175
  "poseidon-lite": "0.3.0",
176
176
  "valibot": "^1.4.2",
177
- "@mysten/utils": "^0.4.1",
178
- "@mysten/bcs": "^2.1.2"
177
+ "@mysten/bcs": "^2.1.3",
178
+ "@mysten/utils": "^0.4.2"
179
179
  },
180
180
  "scripts": {
181
181
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
package/src/bcs/bcs.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { BcsType, BcsTypeOptions } from '@mysten/bcs';
5
- import { bcs, fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from '@mysten/bcs';
5
+ import { bcs, fromBase58, fromBase64, toBase58, toBase64, toHex } from '@mysten/bcs';
6
6
 
7
7
  import { isValidSuiAddress, normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';
8
8
  import { TypeTagSerializer } from './type-tag-serializer.js';
@@ -27,27 +27,82 @@ function optionEnum<T extends BcsType<any, any>>(type: T) {
27
27
  });
28
28
  }
29
29
 
30
+ const HEX_NIBBLES = new Int8Array(128).fill(-1);
31
+ for (let i = 0; i < 16; i++) {
32
+ HEX_NIBBLES['0123456789abcdef'.charCodeAt(i)] = i;
33
+ HEX_NIBBLES['0123456789ABCDEF'.charCodeAt(i)] = i;
34
+ }
35
+ function hexNibble(code: number): number {
36
+ return code < 128 ? HEX_NIBBLES[code] : -1;
37
+ }
38
+
39
+ // Same bytes as fromHex(normalizeSuiAddress(value)) for valid addresses, or null for invalid ones
40
+ function decodeAddress(value: string): Uint8Array<ArrayBuffer> | null {
41
+ if (!value) {
42
+ return null;
43
+ }
44
+ const start =
45
+ value.length >= 2 && value[0] === '0' && (value[1] === 'x' || value[1] === 'X') ? 2 : 0;
46
+ const digits = value.length - start;
47
+ if (digits > SUI_ADDRESS_LENGTH * 2) {
48
+ return null;
49
+ }
50
+
51
+ const bytes = new Uint8Array(SUI_ADDRESS_LENGTH);
52
+ // Right-align the digits, as normalizeSuiAddress left-pads with zeros
53
+ let byteIndex = SUI_ADDRESS_LENGTH - 1;
54
+ let i = value.length - 1;
55
+ for (; i >= start + 1; i -= 2) {
56
+ const low = hexNibble(value.charCodeAt(i));
57
+ const high = hexNibble(value.charCodeAt(i - 1));
58
+ if (low < 0 || high < 0) {
59
+ return null;
60
+ }
61
+ bytes[byteIndex--] = (high << 4) | low;
62
+ }
63
+ if (i === start) {
64
+ const low = hexNibble(value.charCodeAt(i));
65
+ if (low < 0) {
66
+ return null;
67
+ }
68
+ bytes[byteIndex] = low;
69
+ }
70
+
71
+ return bytes;
72
+ }
73
+
30
74
  export const Address = bcs.bytes(SUI_ADDRESS_LENGTH).transform({
31
- validate: (val) => {
32
- const address = typeof val === 'string' ? val : toHex(val);
75
+ // Validation lives in input so string addresses are only decoded once per write; transform's
76
+ // validate runs input, so validate() still rejects invalid addresses.
77
+ input: (val: string | Uint8Array) => {
78
+ if (typeof val === 'string') {
79
+ const bytes = decodeAddress(val);
80
+ if (!bytes) {
81
+ throw new Error(`Invalid Sui address ${val}`);
82
+ }
83
+ return bytes;
84
+ }
85
+ const address = toHex(val);
33
86
  if (!address || !isValidSuiAddress(normalizeSuiAddress(address))) {
34
87
  throw new Error(`Invalid Sui address ${address}`);
35
88
  }
89
+ return val;
36
90
  },
37
- input: (val: string | Uint8Array) =>
38
- typeof val === 'string' ? fromHex(normalizeSuiAddress(val)) : val,
39
- output: (val) => normalizeSuiAddress(toHex(val)),
91
+ output: (val) => `0x${toHex(val)}`,
40
92
  });
41
93
 
42
94
  export const ObjectDigest = bcs.byteVector().transform({
43
95
  name: 'ObjectDigest',
44
- input: (value: string) => fromBase58(value),
45
- output: (value) => toBase58(new Uint8Array(value)),
46
- validate: (value) => {
47
- if (fromBase58(value).length !== 32) {
96
+ // The length check lives in input so the digest is only base58-decoded once per write;
97
+ // transform's validate runs input, so validate() still rejects digests of the wrong length.
98
+ input: (value: string) => {
99
+ const bytes = fromBase58(value);
100
+ if (bytes.length !== 32) {
48
101
  throw new Error('ObjectDigest must be 32 bytes');
49
102
  }
103
+ return bytes;
50
104
  },
105
+ output: (value) => toBase58(value),
51
106
  });
52
107
 
53
108
  export const SuiObjectRef = bcs.struct('SuiObjectRef', {
@@ -113,7 +168,7 @@ export const CallArg = bcs.enum('CallArg', {
113
168
  Pure: bcs.struct('Pure', {
114
169
  bytes: bcs.byteVector().transform({
115
170
  input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
116
- output: (val) => toBase64(new Uint8Array(val)),
171
+ output: (val) => toBase64(val),
117
172
  }),
118
173
  }),
119
174
  Object: ObjectArg,
@@ -190,7 +245,7 @@ export const Command = bcs.enum('Command', {
190
245
  modules: bcs.vector(
191
246
  bcs.byteVector().transform({
192
247
  input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
193
- output: (val) => toBase64(new Uint8Array(val)),
248
+ output: (val) => toBase64(val),
194
249
  }),
195
250
  ),
196
251
  dependencies: bcs.vector(Address),
@@ -218,7 +273,7 @@ export const Command = bcs.enum('Command', {
218
273
  modules: bcs.vector(
219
274
  bcs.byteVector().transform({
220
275
  input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
221
- output: (val) => toBase64(new Uint8Array(val)),
276
+ output: (val) => toBase64(val),
222
277
  }),
223
278
  ),
224
279
  dependencies: bcs.vector(Address),
@@ -373,7 +428,7 @@ export const MultiSig = bcs.struct('MultiSig', {
373
428
 
374
429
  export const base64String = bcs.byteVector().transform({
375
430
  input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
376
- output: (val) => toBase64(new Uint8Array(val)),
431
+ output: (val) => toBase64(val),
377
432
  });
378
433
 
379
434
  export const PasskeyAuthenticator = bcs.struct('PasskeyAuthenticator', {
@@ -71,6 +71,7 @@ export class MultiSigPublicKey extends PublicKey {
71
71
  weight: number;
72
72
  publicKey: PublicKey;
73
73
  }[];
74
+ #options: { client?: ClientWithCoreApi };
74
75
  /**
75
76
  * Create a new MultiSigPublicKey object
76
77
  */
@@ -83,6 +84,8 @@ export class MultiSigPublicKey extends PublicKey {
83
84
  ) {
84
85
  super();
85
86
 
87
+ this.#options = options;
88
+
86
89
  if (typeof value === 'string') {
87
90
  this.rawBytes = fromBase64(value);
88
91
 
@@ -143,21 +146,27 @@ export class MultiSigPublicKey extends PublicKey {
143
146
  static fromPublicKeys({
144
147
  threshold,
145
148
  publicKeys,
149
+ client,
146
150
  }: {
147
151
  threshold: number;
148
152
  publicKeys: { publicKey: PublicKey; weight: number }[];
153
+ /** Client used to verify zkLogin member signatures */
154
+ client?: ClientWithCoreApi;
149
155
  }) {
150
- return new MultiSigPublicKey({
151
- pk_map: publicKeys.map(({ publicKey, weight }) => {
152
- const scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];
153
-
154
- return {
155
- pubKey: { [scheme]: publicKey.toRawBytes() } as PublicKeyEnum,
156
- weight,
157
- };
158
- }),
159
- threshold,
160
- });
156
+ return new MultiSigPublicKey(
157
+ {
158
+ pk_map: publicKeys.map(({ publicKey, weight }) => {
159
+ const scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];
160
+
161
+ return {
162
+ pubKey: { [scheme]: publicKey.toRawBytes() } as PublicKeyEnum,
163
+ weight,
164
+ };
165
+ }),
166
+ threshold,
167
+ },
168
+ { client },
169
+ );
161
170
  }
162
171
 
163
172
  /**
@@ -216,9 +225,38 @@ export class MultiSigPublicKey extends PublicKey {
216
225
  }
217
226
 
218
227
  /**
219
- * Verifies that the signature is valid for for the provided message
228
+ * Verifies that the signature is valid for the provided message
220
229
  */
221
230
  async verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {
231
+ return this.#verifyMembers(multisigSignature, (publicKey, signature) =>
232
+ publicKey.verify(message, signature),
233
+ );
234
+ }
235
+
236
+ /**
237
+ * Verifies that the signature is valid for the provided PersonalMessage
238
+ */
239
+ override verifyPersonalMessage(message: Uint8Array, multisigSignature: string): Promise<boolean> {
240
+ // Each member verifies with its own intent-aware method, so members that cannot verify a
241
+ // raw digest (zkLogin, which is verified through the client) still work.
242
+ return this.#verifyMembers(multisigSignature, (publicKey, signature) =>
243
+ publicKey.verifyPersonalMessage(message, signature),
244
+ );
245
+ }
246
+
247
+ /**
248
+ * Verifies that the signature is valid for the provided Transaction
249
+ */
250
+ override verifyTransaction(transaction: Uint8Array, multisigSignature: string): Promise<boolean> {
251
+ return this.#verifyMembers(multisigSignature, (publicKey, signature) =>
252
+ publicKey.verifyTransaction(transaction, signature),
253
+ );
254
+ }
255
+
256
+ async #verifyMembers(
257
+ multisigSignature: string,
258
+ verifyMember: (publicKey: PublicKey, signature: Uint8Array) => Promise<boolean>,
259
+ ): Promise<boolean> {
222
260
  // Multisig verification only supports serialized signature
223
261
  const parsed = parseSerializedSignature(multisigSignature);
224
262
 
@@ -239,8 +277,11 @@ export class MultiSigPublicKey extends PublicKey {
239
277
  return false;
240
278
  }
241
279
 
242
- for (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {
243
- if (!(await publicKey.verify(message, signature))) {
280
+ for (const { publicKey, weight, signature } of parsePartialSignatures(
281
+ multisig,
282
+ this.#options,
283
+ )) {
284
+ if (!(await verifyMember(publicKey, signature))) {
244
285
  return false;
245
286
  }
246
287
 
@@ -111,7 +111,9 @@ function parseSignature(signature: string, options: { client?: ClientWithCoreApi
111
111
  if (parsedSignature.signatureScheme === 'MultiSig') {
112
112
  return {
113
113
  ...parsedSignature,
114
- publicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk),
114
+ publicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk, {
115
+ client: options.client,
116
+ }),
115
117
  };
116
118
  }
117
119
 
@@ -152,7 +154,7 @@ export function publicKeyFromRawBytes(
152
154
  publicKey = new Secp256r1PublicKey(bytes);
153
155
  break;
154
156
  case 'MultiSig':
155
- publicKey = new MultiSigPublicKey(bytes);
157
+ publicKey = new MultiSigPublicKey(bytes, { client: options.client });
156
158
  break;
157
159
  case 'ZkLogin':
158
160
  publicKey = ZkLoginPublicIdentifier.fromBytes(bytes, options);
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  // This file is generated by genversion.mjs. Do not edit it directly.
5
5
 
6
- export const PACKAGE_VERSION = '2.36.0';
6
+ export const PACKAGE_VERSION = '2.37.0';
@@ -168,10 +168,11 @@ export class ZkLoginPublicIdentifier extends PublicKey {
168
168
  */
169
169
  verifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {
170
170
  const parsedSignature = parseSerializedZkLoginSignature(signature);
171
- const address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();
172
171
 
173
172
  return graphqlVerifyZkLoginSignature({
174
- address: address,
173
+ // Verify against this identifier's address, not one derived from the signature, so a
174
+ // signature from a different zkLogin identity is rejected (as the chain does for multisig).
175
+ address: this.toSuiAddress(),
175
176
  bytes: toBase64(message),
176
177
  signature: parsedSignature.serializedSignature,
177
178
  intentScope: 'PersonalMessage',
@@ -184,9 +185,8 @@ export class ZkLoginPublicIdentifier extends PublicKey {
184
185
  */
185
186
  verifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {
186
187
  const parsedSignature = parseSerializedZkLoginSignature(signature);
187
- const address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();
188
188
  return graphqlVerifyZkLoginSignature({
189
- address: address,
189
+ address: this.toSuiAddress(),
190
190
  bytes: toBase64(transaction),
191
191
  signature: parsedSignature.serializedSignature,
192
192
  intentScope: 'TransactionData',