@mysten/sui 1.26.1 → 1.27.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 +7 -0
- package/dist/cjs/bcs/bcs.d.ts +3 -2
- package/dist/cjs/bcs/bcs.js +3 -3
- package/dist/cjs/bcs/bcs.js.map +2 -2
- package/dist/cjs/bcs/effects.d.ts +18 -12
- package/dist/cjs/bcs/index.d.ts +460 -453
- package/dist/cjs/bcs/index.js +4 -4
- package/dist/cjs/bcs/index.js.map +1 -1
- package/dist/cjs/client/client.d.ts +38 -16
- package/dist/cjs/client/client.js +142 -62
- package/dist/cjs/client/client.js.map +2 -2
- package/dist/cjs/client/http-transport.d.ts +2 -0
- package/dist/cjs/client/http-transport.js +7 -0
- package/dist/cjs/client/http-transport.js.map +2 -2
- package/dist/cjs/client/rpc-websocket-client.d.ts +2 -1
- package/dist/cjs/client/rpc-websocket-client.js +7 -2
- package/dist/cjs/client/rpc-websocket-client.js.map +2 -2
- package/dist/cjs/client/types/generated.d.ts +1 -0
- package/dist/cjs/client/types/generated.js.map +1 -1
- package/dist/cjs/client/types/params.d.ts +56 -0
- package/dist/cjs/client/types/params.js.map +1 -1
- package/dist/cjs/experimental/cache.d.ts +11 -0
- package/dist/cjs/experimental/cache.js +79 -0
- package/dist/cjs/experimental/cache.js.map +7 -0
- package/dist/cjs/experimental/client.d.ts +4 -2
- package/dist/cjs/experimental/client.js +4 -2
- package/dist/cjs/experimental/client.js.map +2 -2
- package/dist/cjs/experimental/core.d.ts +10 -2
- package/dist/cjs/experimental/core.js +59 -1
- package/dist/cjs/experimental/core.js.map +2 -2
- package/dist/cjs/experimental/index.d.ts +5 -0
- package/dist/cjs/experimental/index.js +29 -0
- package/dist/cjs/experimental/index.js.map +7 -0
- package/dist/cjs/experimental/transports/jsonRPC.d.ts +19 -5
- package/dist/cjs/experimental/transports/jsonRPC.js +270 -12
- package/dist/cjs/experimental/transports/jsonRPC.js.map +2 -2
- package/dist/cjs/experimental/types.d.ts +84 -41
- package/dist/cjs/experimental/types.js.map +1 -1
- package/dist/cjs/keypairs/secp256k1/keypair.js +1 -1
- package/dist/cjs/keypairs/secp256k1/keypair.js.map +2 -2
- package/dist/cjs/keypairs/secp256r1/keypair.js +1 -1
- package/dist/cjs/keypairs/secp256r1/keypair.js.map +2 -2
- package/dist/cjs/multisig/publickey.js +5 -5
- package/dist/cjs/multisig/publickey.js.map +2 -2
- package/dist/cjs/multisig/signer.js +2 -2
- package/dist/cjs/multisig/signer.js.map +2 -2
- package/dist/cjs/transactions/plugins/utils.js +2 -2
- package/dist/cjs/transactions/plugins/utils.js.map +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/bcs/bcs.d.ts +3 -2
- package/dist/esm/bcs/bcs.js +3 -3
- package/dist/esm/bcs/bcs.js.map +2 -2
- package/dist/esm/bcs/effects.d.ts +18 -12
- package/dist/esm/bcs/index.d.ts +460 -453
- package/dist/esm/bcs/index.js +4 -4
- package/dist/esm/bcs/index.js.map +1 -1
- package/dist/esm/client/client.d.ts +38 -16
- package/dist/esm/client/client.js +143 -63
- package/dist/esm/client/client.js.map +2 -2
- package/dist/esm/client/http-transport.d.ts +2 -0
- package/dist/esm/client/http-transport.js +7 -0
- package/dist/esm/client/http-transport.js.map +2 -2
- package/dist/esm/client/rpc-websocket-client.d.ts +2 -1
- package/dist/esm/client/rpc-websocket-client.js +7 -2
- package/dist/esm/client/rpc-websocket-client.js.map +2 -2
- package/dist/esm/client/types/generated.d.ts +1 -0
- package/dist/esm/client/types/params.d.ts +56 -0
- package/dist/esm/experimental/cache.d.ts +11 -0
- package/dist/esm/experimental/cache.js +59 -0
- package/dist/esm/experimental/cache.js.map +7 -0
- package/dist/esm/experimental/client.d.ts +4 -2
- package/dist/esm/experimental/client.js +4 -2
- package/dist/esm/experimental/client.js.map +2 -2
- package/dist/esm/experimental/core.d.ts +10 -2
- package/dist/esm/experimental/core.js +60 -2
- package/dist/esm/experimental/core.js.map +2 -2
- package/dist/esm/experimental/index.d.ts +5 -0
- package/dist/esm/experimental/index.js +9 -0
- package/dist/esm/experimental/index.js.map +7 -0
- package/dist/esm/experimental/transports/jsonRPC.d.ts +19 -5
- package/dist/esm/experimental/transports/jsonRPC.js +270 -12
- package/dist/esm/experimental/transports/jsonRPC.js.map +2 -2
- package/dist/esm/experimental/types.d.ts +84 -41
- package/dist/esm/keypairs/secp256k1/keypair.js +1 -1
- package/dist/esm/keypairs/secp256k1/keypair.js.map +2 -2
- package/dist/esm/keypairs/secp256r1/keypair.js +1 -1
- package/dist/esm/keypairs/secp256r1/keypair.js.map +2 -2
- package/dist/esm/multisig/publickey.js +5 -5
- package/dist/esm/multisig/publickey.js.map +2 -2
- package/dist/esm/multisig/signer.js +2 -2
- package/dist/esm/multisig/signer.js.map +2 -2
- package/dist/esm/transactions/plugins/utils.js +2 -2
- package/dist/esm/transactions/plugins/utils.js.map +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/experimental/package.json +6 -0
- package/package.json +7 -2
- package/src/bcs/bcs.ts +3 -3
- package/src/bcs/index.ts +3 -3
- package/src/client/client.ts +119 -26
- package/src/client/http-transport.ts +10 -0
- package/src/client/rpc-websocket-client.ts +8 -1
- package/src/client/types/generated.ts +1 -0
- package/src/client/types/params.ts +68 -6
- package/src/experimental/cache.ts +64 -0
- package/src/experimental/client.ts +4 -2
- package/src/experimental/core.ts +89 -2
- package/src/experimental/index.ts +20 -0
- package/src/experimental/transports/jsonRPC.ts +319 -9
- package/src/experimental/types.ts +92 -48
- package/src/keypairs/secp256k1/keypair.ts +1 -1
- package/src/keypairs/secp256r1/keypair.ts +1 -1
- package/src/multisig/publickey.ts +5 -5
- package/src/multisig/signer.ts +2 -2
- package/src/transactions/__tests__/bcs.test.ts +2 -2
- package/src/transactions/plugins/utils.ts +2 -2
- package/src/version.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type SuiClientRegistration<T extends
|
|
1
|
+
import type { Experimental_BaseClient } from './client.js';
|
|
2
|
+
export type SuiClientRegistration<T extends Experimental_BaseClient = Experimental_BaseClient, Name extends string = string, Extension = unknown> = {
|
|
3
3
|
readonly name: Name;
|
|
4
4
|
readonly register: (client: T) => Extension;
|
|
5
5
|
} | SelfRegisteringClientExtension<T, Name, Extension>;
|
|
6
|
-
export interface SelfRegisteringClientExtension<T extends
|
|
6
|
+
export interface SelfRegisteringClientExtension<T extends Experimental_BaseClient = Experimental_BaseClient, Name extends string = string, Extension = unknown> {
|
|
7
7
|
experimental_asClientExtension: () => {
|
|
8
8
|
readonly name: Name;
|
|
9
9
|
readonly register: (client: T) => Extension;
|
|
@@ -13,31 +13,45 @@ export type Simplify<T> = {
|
|
|
13
13
|
[K in keyof T]: T[K];
|
|
14
14
|
} & {};
|
|
15
15
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
16
|
-
export type ClientWithExtensions<T> =
|
|
16
|
+
export type ClientWithExtensions<T> = Experimental_BaseClient & T;
|
|
17
17
|
export declare namespace Experimental_SuiClientTypes {
|
|
18
18
|
type Network = 'mainnet' | 'testnet' | 'devnet' | 'localnet' | (string & {});
|
|
19
19
|
interface SuiClientOptions {
|
|
20
20
|
network: Network;
|
|
21
21
|
}
|
|
22
|
+
interface CoreClientMethodOptions {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
22
25
|
/** Object methods */
|
|
23
26
|
interface TransportMethods {
|
|
24
|
-
getObjects
|
|
25
|
-
getOwnedObjects
|
|
26
|
-
getCoins
|
|
27
|
+
getObjects: (options: GetObjectsOptions) => Promise<GetObjectsResponse>;
|
|
28
|
+
getOwnedObjects: (options: GetOwnedObjectsOptions) => Promise<GetOwnedObjectsResponse>;
|
|
29
|
+
getCoins: (options: GetCoinsOptions) => Promise<GetCoinsResponse>;
|
|
30
|
+
getDynamicFields: (options: GetDynamicFieldsOptions) => Promise<GetDynamicFieldsResponse>;
|
|
31
|
+
getDynamicField: (options: GetDynamicFieldOptions) => Promise<GetDynamicFieldResponse>;
|
|
27
32
|
}
|
|
28
|
-
interface GetObjectsOptions {
|
|
33
|
+
interface GetObjectsOptions extends CoreClientMethodOptions {
|
|
29
34
|
objectIds: string[];
|
|
30
35
|
}
|
|
31
|
-
interface GetOwnedObjectsOptions {
|
|
36
|
+
interface GetOwnedObjectsOptions extends CoreClientMethodOptions {
|
|
32
37
|
address: string;
|
|
33
38
|
limit?: number;
|
|
34
39
|
cursor?: string | null;
|
|
35
40
|
type?: string;
|
|
36
41
|
}
|
|
37
|
-
interface GetCoinsOptions {
|
|
42
|
+
interface GetCoinsOptions extends CoreClientMethodOptions {
|
|
38
43
|
address: string;
|
|
39
44
|
coinType: string;
|
|
40
45
|
}
|
|
46
|
+
interface GetDynamicFieldsOptions extends CoreClientMethodOptions {
|
|
47
|
+
parentId: string;
|
|
48
|
+
limit?: number;
|
|
49
|
+
cursor?: string | null;
|
|
50
|
+
}
|
|
51
|
+
interface GetDynamicFieldOptions extends CoreClientMethodOptions {
|
|
52
|
+
parentId: string;
|
|
53
|
+
name: DynamicFieldName;
|
|
54
|
+
}
|
|
41
55
|
interface GetObjectsResponse {
|
|
42
56
|
objects: (ObjectResponse | Error)[];
|
|
43
57
|
}
|
|
@@ -60,25 +74,54 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
60
74
|
content: Uint8Array;
|
|
61
75
|
}
|
|
62
76
|
interface CoinResponse extends ObjectResponse {
|
|
63
|
-
balance:
|
|
77
|
+
balance: string;
|
|
78
|
+
}
|
|
79
|
+
interface GetDynamicFieldsResponse {
|
|
80
|
+
hasNextPage: boolean;
|
|
81
|
+
cursor: string | null;
|
|
82
|
+
dynamicFields: {
|
|
83
|
+
name: DynamicFieldName;
|
|
84
|
+
id: string;
|
|
85
|
+
version: string;
|
|
86
|
+
digest: string;
|
|
87
|
+
type: string;
|
|
88
|
+
}[];
|
|
89
|
+
}
|
|
90
|
+
interface GetDynamicFieldResponse {
|
|
91
|
+
dynamicField: {
|
|
92
|
+
name: DynamicFieldName;
|
|
93
|
+
value: DynamicFieldValue;
|
|
94
|
+
id: string;
|
|
95
|
+
version: string;
|
|
96
|
+
digest: string;
|
|
97
|
+
type: string;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
interface DynamicFieldName {
|
|
101
|
+
type: string;
|
|
102
|
+
bcs: Uint8Array;
|
|
103
|
+
}
|
|
104
|
+
interface DynamicFieldValue {
|
|
105
|
+
type: string;
|
|
106
|
+
bcs: Uint8Array;
|
|
64
107
|
}
|
|
65
108
|
/** Balance methods */
|
|
66
109
|
interface TransportMethods {
|
|
67
|
-
getBalance
|
|
68
|
-
getAllBalances
|
|
110
|
+
getBalance: (options: GetBalanceOptions) => Promise<GetBalanceResponse>;
|
|
111
|
+
getAllBalances: (options: GetAllBalancesOptions) => Promise<GetAllBalancesResponse>;
|
|
69
112
|
}
|
|
70
|
-
interface GetBalanceOptions {
|
|
113
|
+
interface GetBalanceOptions extends CoreClientMethodOptions {
|
|
71
114
|
address: string;
|
|
72
115
|
coinType: string;
|
|
73
116
|
}
|
|
74
117
|
interface CoinBalance {
|
|
75
118
|
coinType: string;
|
|
76
|
-
balance:
|
|
119
|
+
balance: string;
|
|
77
120
|
}
|
|
78
121
|
interface GetBalanceResponse {
|
|
79
122
|
balance: CoinBalance;
|
|
80
123
|
}
|
|
81
|
-
interface GetAllBalancesOptions {
|
|
124
|
+
interface GetAllBalancesOptions extends CoreClientMethodOptions {
|
|
82
125
|
address: string;
|
|
83
126
|
limit?: number;
|
|
84
127
|
cursor?: string | null;
|
|
@@ -90,28 +133,28 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
90
133
|
}
|
|
91
134
|
/** Transaction methods */
|
|
92
135
|
interface TransportMethods {
|
|
93
|
-
getTransaction
|
|
94
|
-
executeTransaction
|
|
95
|
-
dryRunTransaction
|
|
136
|
+
getTransaction: (options: GetTransactionOptions) => Promise<GetTransactionResponse>;
|
|
137
|
+
executeTransaction: (options: ExecuteTransactionOptions) => Promise<ExecuteTransactionResponse>;
|
|
138
|
+
dryRunTransaction: (options: DryRunTransactionOptions) => Promise<DryRunTransactionResponse>;
|
|
96
139
|
}
|
|
97
140
|
interface TransactionResponse {
|
|
98
141
|
digest: string;
|
|
99
142
|
signatures: string[];
|
|
100
143
|
bcs: Uint8Array;
|
|
101
|
-
effects:
|
|
144
|
+
effects: TransactionEffects;
|
|
102
145
|
events?: Uint8Array;
|
|
103
146
|
}
|
|
104
|
-
interface GetTransactionOptions {
|
|
147
|
+
interface GetTransactionOptions extends CoreClientMethodOptions {
|
|
105
148
|
digest: string;
|
|
106
149
|
}
|
|
107
150
|
interface GetTransactionResponse {
|
|
108
151
|
transaction: TransactionResponse;
|
|
109
152
|
}
|
|
110
|
-
interface ExecuteTransactionOptions {
|
|
153
|
+
interface ExecuteTransactionOptions extends CoreClientMethodOptions {
|
|
111
154
|
transaction: Uint8Array;
|
|
112
155
|
signatures: string[];
|
|
113
156
|
}
|
|
114
|
-
interface DryRunTransactionOptions {
|
|
157
|
+
interface DryRunTransactionOptions extends CoreClientMethodOptions {
|
|
115
158
|
transaction: Uint8Array;
|
|
116
159
|
}
|
|
117
160
|
interface DryRunTransactionResponse {
|
|
@@ -124,7 +167,7 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
124
167
|
getReferenceGasPrice?: () => Promise<GetReferenceGasPriceResponse>;
|
|
125
168
|
}
|
|
126
169
|
interface GetReferenceGasPriceResponse {
|
|
127
|
-
referenceGasPrice:
|
|
170
|
+
referenceGasPrice: string;
|
|
128
171
|
}
|
|
129
172
|
/** ObjectOwner types */
|
|
130
173
|
interface AddressOwner {
|
|
@@ -145,9 +188,9 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
145
188
|
$kind: 'Immutable';
|
|
146
189
|
Immutable: true;
|
|
147
190
|
}
|
|
148
|
-
interface
|
|
191
|
+
interface ConsensusV2 {
|
|
149
192
|
$kind: 'ConsensusV2';
|
|
150
|
-
|
|
193
|
+
ConsensusV2: {
|
|
151
194
|
authenticator: ConsensusV2Authenticator;
|
|
152
195
|
startVersion: string;
|
|
153
196
|
};
|
|
@@ -157,20 +200,20 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
157
200
|
SingleOwner: string;
|
|
158
201
|
}
|
|
159
202
|
type ConsensusV2Authenticator = SingleOwnerAuthenticator;
|
|
160
|
-
type ObjectOwner = AddressOwner | ParentOwner | SharedOwner | ImmutableOwner |
|
|
203
|
+
type ObjectOwner = AddressOwner | ParentOwner | SharedOwner | ImmutableOwner | ConsensusV2;
|
|
161
204
|
/** Effects */
|
|
162
205
|
interface TransactionEffects {
|
|
163
|
-
bcs: Uint8Array;
|
|
206
|
+
bcs: Uint8Array | null;
|
|
164
207
|
digest: string;
|
|
165
208
|
version: number;
|
|
166
209
|
status: ExecutionStatus;
|
|
167
|
-
epoch:
|
|
210
|
+
epoch: string | null;
|
|
168
211
|
gasUsed: GasCostSummary;
|
|
169
212
|
transactionDigest: string;
|
|
170
|
-
gasObject: ChangedObject;
|
|
213
|
+
gasObject: ChangedObject | null;
|
|
171
214
|
eventsDigest: string | null;
|
|
172
215
|
dependencies: string[];
|
|
173
|
-
lamportVersion:
|
|
216
|
+
lamportVersion: string | null;
|
|
174
217
|
changedObjects: ChangedObject[];
|
|
175
218
|
unchangedSharedObjects: UnchangedSharedObject[];
|
|
176
219
|
auxiliaryDataDigest: string | null;
|
|
@@ -178,21 +221,21 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
178
221
|
interface ChangedObject {
|
|
179
222
|
id: string;
|
|
180
223
|
inputState: 'Unknown' | 'DoesNotExist' | 'Exists';
|
|
181
|
-
inputVersion:
|
|
224
|
+
inputVersion: string | null;
|
|
182
225
|
inputDigest: string | null;
|
|
183
226
|
inputOwner: ObjectOwner | null;
|
|
184
227
|
outputState: 'Unknown' | 'DoesNotExist' | 'ObjectWrite' | 'PackageWrite';
|
|
185
|
-
outputVersion:
|
|
228
|
+
outputVersion: string | null;
|
|
186
229
|
outputDigest: string | null;
|
|
187
230
|
outputOwner: ObjectOwner | null;
|
|
188
231
|
idOperation: 'Unknown' | 'None' | 'Created' | 'Deleted';
|
|
189
232
|
objectType: string | null;
|
|
190
233
|
}
|
|
191
234
|
interface GasCostSummary {
|
|
192
|
-
computationCost:
|
|
193
|
-
storageCost:
|
|
194
|
-
storageRebate:
|
|
195
|
-
nonRefundableStorageFee:
|
|
235
|
+
computationCost: string;
|
|
236
|
+
storageCost: string;
|
|
237
|
+
storageRebate: string;
|
|
238
|
+
nonRefundableStorageFee: string;
|
|
196
239
|
}
|
|
197
240
|
type ExecutionStatus = {
|
|
198
241
|
success: true;
|
|
@@ -202,10 +245,10 @@ export declare namespace Experimental_SuiClientTypes {
|
|
|
202
245
|
error: string;
|
|
203
246
|
};
|
|
204
247
|
interface UnchangedSharedObject {
|
|
205
|
-
kind: 'Unknown' | 'ReadOnlyRoot' | 'MutateDeleted' | 'ReadDeleted' | '
|
|
248
|
+
kind: 'Unknown' | 'ReadOnlyRoot' | 'MutateDeleted' | 'ReadDeleted' | 'Cancelled' | 'PerEpochConfig';
|
|
206
249
|
objectId: string;
|
|
207
|
-
version:
|
|
208
|
-
digest: string;
|
|
209
|
-
objectType: string;
|
|
250
|
+
version: string | null;
|
|
251
|
+
digest: string | null;
|
|
252
|
+
objectType: string | null;
|
|
210
253
|
}
|
|
211
254
|
}
|
|
@@ -74,7 +74,7 @@ class Secp256k1Keypair extends Keypair {
|
|
|
74
74
|
* @param seed seed byte array
|
|
75
75
|
*/
|
|
76
76
|
static fromSeed(seed) {
|
|
77
|
-
|
|
77
|
+
const publicKey = secp256k1.getPublicKey(seed, true);
|
|
78
78
|
return new Secp256k1Keypair({ publicKey, secretKey: seed });
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256k1/keypair.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256k1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256K1_DERIVATION_PATH = \"m/54'/784'/0'/0/0\";\n\n/**\n * Secp256k1 Keypair data\n */\nexport interface Secp256k1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256k1 Keypair used for signing transactions.\n */\nexport class Secp256k1Keypair extends Keypair {\n\tprivate keypair: Secp256k1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256k1Keypair} is provided.\n\t *\n\t * @param keypair secp256k1 keypair\n\t */\n\tconstructor(keypair?: Secp256k1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256k1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256k1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256k1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256k1Keypair {\n\t\treturn new Secp256k1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256k1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256k1') {\n\t\t\t\tthrow new Error(`Expected a Secp256k1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256k1.sign(msgHash, secretKey);\n\t\t\tif (!secp256k1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256k1Keypair {\n\t\
|
|
5
|
-
"mappings": "AAGA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACx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,SAAS,WAAW,EAAE,MAAM,KAAK,CAAC,GAAG;AACrE,cAAM,IAAI,MAAM,+BAA+B;AAAA,MAChD;AAAA,IACD;AACA,WAAO,IAAI,iBAAiB,EAAE,WAAW,UAAU,CAAC;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,SAAS,MAAoC;AACnD,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256k1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256K1_DERIVATION_PATH = \"m/54'/784'/0'/0/0\";\n\n/**\n * Secp256k1 Keypair data\n */\nexport interface Secp256k1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256k1 Keypair used for signing transactions.\n */\nexport class Secp256k1Keypair extends Keypair {\n\tprivate keypair: Secp256k1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256k1Keypair} is provided.\n\t *\n\t * @param keypair secp256k1 keypair\n\t */\n\tconstructor(keypair?: Secp256k1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256k1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256k1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256k1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256k1Keypair {\n\t\treturn new Secp256k1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256k1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256k1') {\n\t\t\t\tthrow new Error(`Expected a Secp256k1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256k1.sign(msgHash, secretKey);\n\t\t\tif (!secp256k1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256k1Keypair {\n\t\tconst publicKey = secp256k1.getPublicKey(seed, true);\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256k1PublicKey(this.keypair.publicKey);\n\t}\n\t/**\n\t * The Bech32 secret key string for this Secp256k1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\tconst msgHash = sha256(data);\n\t\tconst sig = secp256k1.sign(msgHash, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t});\n\t\treturn sig.toCompactRawBytes();\n\t}\n\n\t/**\n\t * Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/54'/784'/0'/0/0, otherwise the path must\n\t * be compliant to BIP-32 in form m/54'/784'/{account_index}'/{change_index}/{address_index}.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Secp256k1Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_SECP256K1_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidBIP32Path(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst key = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path);\n\t\tif (key.publicKey == null || key.privateKey == null) {\n\t\t\tthrow new Error('Invalid key');\n\t\t}\n\t\treturn new Secp256k1Keypair({\n\t\t\tpublicKey: key.publicKey,\n\t\t\tsecretKey: key.privateKey,\n\t\t});\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAEtB,SAAS,qBAAqB,qBAAqB,eAAe;AAClE,SAAS,kBAAkB,s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
*/
|
|
76
76
|
static fromSeed(seed) {
|
|
77
|
-
|
|
77
|
+
const publicKey = secp256r1.getPublicKey(seed, true);
|
|
78
78
|
return new Secp256r1Keypair({ publicKey, secretKey: seed });
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256r1/keypair.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256r1 } from '@noble/curves/p256';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256r1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256R1_DERIVATION_PATH = \"m/74'/784'/0'/0/0\";\n\n/**\n * Secp256r1 Keypair data\n */\nexport interface Secp256r1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256r1 Keypair used for signing transactions.\n */\nexport class Secp256r1Keypair extends Keypair {\n\tprivate keypair: Secp256r1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256r1Keypair} is provided.\n\t *\n\t * @param keypair Secp256r1 keypair\n\t */\n\tconstructor(keypair?: Secp256r1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256r1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256r1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256r1Keypair {\n\t\treturn new Secp256r1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256r1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256r1') {\n\t\t\t\tthrow new Error(`Expected a Secp256r1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256r1.sign(msgHash, secretKey, { lowS: true });\n\t\t\tif (!secp256r1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\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,EAAE,OAAO,GAAG,CAAC,CAAC;AAC3D,YAAM,YAAY,UAAU,KAAK,SAAS,WAAW,EAAE,MAAM,KAAK,CAAC;AACnE,UAAI,CAAC,UAAU,OAAO,WAAW,SAAS,WAAW,EAAE,MAAM,KAAK,CAAC,GAAG;AACrE,cAAM,IAAI,MAAM,+BAA+B;AAAA,MAChD;AAAA,IACD;AACA,WAAO,IAAI,iBAAiB,EAAE,WAAW,UAAU,CAAC;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,SAAS,MAAoC;AACnD,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256r1 } from '@noble/curves/p256';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256r1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256R1_DERIVATION_PATH = \"m/74'/784'/0'/0/0\";\n\n/**\n * Secp256r1 Keypair data\n */\nexport interface Secp256r1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256r1 Keypair used for signing transactions.\n */\nexport class Secp256r1Keypair extends Keypair {\n\tprivate keypair: Secp256r1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256r1Keypair} is provided.\n\t *\n\t * @param keypair Secp256r1 keypair\n\t */\n\tconstructor(keypair?: Secp256r1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256r1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256r1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256r1Keypair {\n\t\treturn new Secp256r1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256r1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256r1') {\n\t\t\t\tthrow new Error(`Expected a Secp256r1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256r1.sign(msgHash, secretKey, { lowS: true });\n\t\t\tif (!secp256r1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256r1Keypair {\n\t\tconst publicKey = secp256r1.getPublicKey(seed, true);\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256r1PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Secp256r1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\tconst msgHash = sha256(data);\n\t\tconst sig = secp256r1.sign(msgHash, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t});\n\t\treturn sig.toCompactRawBytes();\n\t}\n\n\t/**\n\t * Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/74'/784'/0'/0/0, otherwise the path must\n\t * be compliant to BIP-32 in form m/74'/784'/{account_index}'/{change_index}/{address_index}.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Secp256r1Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_SECP256R1_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidBIP32Path(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\t// We use HDKey which is hardcoded to use Secp256k1 but since we only need the 32 bytes for the private key it's okay to use here as well.\n\t\tconst privateKey = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path).privateKey;\n\t\treturn Secp256r1Keypair.fromSecretKey(privateKey!);\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,S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= new Array(signatures.length);
|
|
159
159
|
for (let i = 0; i < signatures.length; i++) {
|
|
160
|
-
|
|
160
|
+
const parsed = parseSerializedSignature(signatures[i]);
|
|
161
161
|
if (parsed.signatureScheme === "MultiSig") {
|
|
162
162
|
throw new Error("MultiSig is not supported inside MultiSig");
|
|
163
163
|
}
|
|
@@ -188,20 +188,20 @@ class MultiSigPublicKey extends PublicKey {
|
|
|
188
188
|
}
|
|
189
189
|
bitmap |= 1 << publicKeyIndex;
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
const multisig = {
|
|
192
192
|
sigs: compressedSignatures,
|
|
193
193
|
bitmap,
|
|
194
194
|
multisig_pk: this.multisigPublicKey
|
|
195
195
|
};
|
|
196
196
|
const bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();
|
|
197
|
-
|
|
197
|
+
const tmp = new Uint8Array(bytes.length + 1);
|
|
198
198
|
tmp.set([SIGNATURE_SCHEME_TO_FLAG["MultiSig"]]);
|
|
199
199
|
tmp.set(bytes, 1);
|
|
200
200
|
return toBase64(tmp);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
function parsePartialSignatures(multisig, options = {}) {
|
|
204
|
-
|
|
204
|
+
const res = new Array(multisig.sigs.length);
|
|
205
205
|
for (let i = 0; i < multisig.sigs.length; i++) {
|
|
206
206
|
const [signatureScheme, signature] = Object.entries(multisig.sigs[i]).filter(
|
|
207
207
|
([name]) => name !== "$kind"
|
|
@@ -226,7 +226,7 @@ function asIndices(bitmap) {
|
|
|
226
226
|
if (bitmap < 0 || bitmap > 1024) {
|
|
227
227
|
throw new Error("Invalid bitmap");
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
const res = [];
|
|
230
230
|
for (let i = 0; i < 10; i++) {
|
|
231
231
|
if ((bitmap & 1 << i) !== 0) {
|
|
232
232
|
res.push(i);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/multisig/publickey.ts"],
|
|
4
|
-
"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/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\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 type { SuiGraphQLClient } from '../graphql/client.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\n// eslint-disable-next-line import/no-cycle\nimport { publicKeyFromRawBytes } from '../verify/index.js';\nimport { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport { MultiSigSigner } from './signer.js';\n\ntype CompressedSignature =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] };\n\ntype PublicKeyEnum =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] };\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;\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?: SuiGraphQLClient } = {},\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;\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\tnumber[],\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]: Array.from(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 {\n\t\treturn this.rawBytes;\n\t}\n\n\tgetPublicKeys() {\n\t\treturn this.publicKeys;\n\t}\n\n\tgetThreshold() {\n\t\treturn this.multisigPublicKey.threshold;\n\t}\n\n\tgetSigner(...signers: [signer: Signer]) {\n\t\treturn new MultiSigSigner(this, signers);\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\toverride toSuiAddress(): string {\n\t\t// max length = 1 flag byte + (max pk size + max weight size (u8)) * max signer size + 2 threshold bytes (u16)\n\t\tconst maxLength = 1 + (64 + 1) * MAX_SIGNER_IN_MULTISIG + 2;\n\t\tconst tmp = new Uint8Array(maxLength);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\n\t\ttmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);\n\t\t// The initial value 3 ensures that following data will be after the flag byte and threshold bytes\n\t\tlet i = 3;\n\t\tfor (const { publicKey, weight } of this.publicKeys) {\n\t\t\tconst bytes = publicKey.toSuiBytes();\n\t\t\ttmp.set(bytes, i);\n\t\t\ti += bytes.length;\n\t\t\ttmp.set([weight], i++);\n\t\t}\n\t\treturn normalizeSuiAddress(bytesToHex(blake2b(tmp.slice(0, i), { dkLen: 32 })));\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MultiSig'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Multisig verification only supports serialized signature\n\t\tconst parsed = parseSerializedSignature(multisigSignature);\n\n\t\tif (parsed.signatureScheme !== 'MultiSig') {\n\t\t\tthrow new Error('Invalid signature scheme');\n\t\t}\n\n\t\tconst { multisig } = parsed;\n\n\t\tlet signatureWeight = 0;\n\n\t\tif (\n\t\t\t!bytesEqual(\n\t\t\t\tbcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),\n\t\t\t\tbcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),\n\t\t\t)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {\n\t\t\tif (!(await publicKey.verify(message, signature))) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tsignatureWeight += weight;\n\t\t}\n\n\t\treturn signatureWeight >= this.multisigPublicKey.threshold;\n\t}\n\n\t/**\n\t * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once\n\t * and that all the public keys involved are known and valid, and then serializes multisig into the standard format\n\t */\n\tcombinePartialSignatures(signatures: string[]): string {\n\t\tif (signatures.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tlet bitmap = 0;\n\t\tconst compressedSignatures: CompressedSignature[] = new Array(signatures.length);\n\n\t\tfor (let i = 0; i < signatures.length; i++) {\n\t\t\tlet 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(\n\t\t\t\t\tparsed.zkLogin?.addressSeed,\n\t\t\t\t\tparsed.zkLogin?.iss,\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]: Array.from(parsed.signature.map((x: number) => Number(x))),\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\tlet multisig: MultiSigStruct = {\n\t\t\tsigs: compressedSignatures,\n\t\t\tbitmap,\n\t\t\tmultisig_pk: this.multisigPublicKey,\n\t\t};\n\t\tconst bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();\n\t\tlet 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?: SuiGraphQLClient } = {},\n): ParsedPartialMultiSigSignature[] {\n\tlet 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, number[]];\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\tlet 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"],
|
|
5
|
-
"mappings": "AAGA,SAAS,YAAY,gBAAgB;AACrC,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAE3B,SAAS,WAAW;AAEpB,SAAS,YAAY,iBAAiB;AACtC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAEP,SAAS,gCAAgC;AAEzC,SAAS,2BAA2B;AAEpC,SAAS,6BAA6B;AACtC,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;AAqCxB,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAI/B,MAAM,0BAA0B,UAAU;AAAA;AAAA;AAAA;AAAA,EAUhD,YAIC,OACA,UAAyC,CAAC,GACzC;AACD,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,WAAW,WAAW,KAAK;AAEhC,WAAK,oBAAoB,IAAI,kBAAkB,MAAM,KAAK,QAAQ;AAAA,IACnE,WAAW,iBAAiB,YAAY;AACvC,WAAK,WAAW;AAChB,WAAK,oBAAoB,IAAI,kBAAkB,MAAM,KAAK,QAAQ;AAAA,IACnE,OAAO;AACN,WAAK,oBAAoB;AACzB,WAAK,WAAW,IAAI,kBAAkB,UAAU,KAAK,EAAE,QAAQ;AAAA,IAChE;AACA,QAAI,KAAK,kBAAkB,YAAY,GAAG;AACzC,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,UAAM,iBAAiB,oBAAI,IAAY;AAEvC,SAAK,aAAa,KAAK,kBAAkB,OAAO,IAAI,CAAC,EAAE,QAAQ,OAAO,MAAM;AAC3E,YAAM,CAAC,QAAQ,KAAK,IAAI,OAAO,QAAQ,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,MAAM,SAAS,OAAO,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D,aAAO;AAAA,IACR;AAEA,eAAW,EAAE,WAAW,QAAQ,UAAU,KAAK,uBAAuB,QAAQ,GAAG;AAChF,UAAI,CAAE,MAAM,UAAU,OAAO,SAAS,SAAS,GAAI;AAClD,eAAO;AAAA,MACR;AAEA,yBAAmB;AAAA,IACpB;AAEA,WAAO,mBAAmB,KAAK,kBAAkB;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,yBAAyB,YAA8B;AACtD,QAAI,WAAW,SAAS,wBAAwB;AAC/C,YAAM,IAAI,MAAM,6CAA6C,sBAAsB,EAAE;AAAA,IACtF;AAEA,QAAI,SAAS;AACb,UAAM,uBAA8C,IAAI,MAAM,WAAW,MAAM;AAE/E,aAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC3C,
|
|
4
|
+
"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/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\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 type { SuiGraphQLClient } from '../graphql/client.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\n// eslint-disable-next-line import/no-cycle\nimport { publicKeyFromRawBytes } from '../verify/index.js';\nimport { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport { MultiSigSigner } from './signer.js';\n\ntype CompressedSignature =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] };\n\ntype PublicKeyEnum =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] };\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;\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?: SuiGraphQLClient } = {},\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;\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\tnumber[],\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]: Array.from(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 {\n\t\treturn this.rawBytes;\n\t}\n\n\tgetPublicKeys() {\n\t\treturn this.publicKeys;\n\t}\n\n\tgetThreshold() {\n\t\treturn this.multisigPublicKey.threshold;\n\t}\n\n\tgetSigner(...signers: [signer: Signer]) {\n\t\treturn new MultiSigSigner(this, signers);\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\toverride toSuiAddress(): string {\n\t\t// max length = 1 flag byte + (max pk size + max weight size (u8)) * max signer size + 2 threshold bytes (u16)\n\t\tconst maxLength = 1 + (64 + 1) * MAX_SIGNER_IN_MULTISIG + 2;\n\t\tconst tmp = new Uint8Array(maxLength);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\n\t\ttmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);\n\t\t// The initial value 3 ensures that following data will be after the flag byte and threshold bytes\n\t\tlet i = 3;\n\t\tfor (const { publicKey, weight } of this.publicKeys) {\n\t\t\tconst bytes = publicKey.toSuiBytes();\n\t\t\ttmp.set(bytes, i);\n\t\t\ti += bytes.length;\n\t\t\ttmp.set([weight], i++);\n\t\t}\n\t\treturn normalizeSuiAddress(bytesToHex(blake2b(tmp.slice(0, i), { dkLen: 32 })));\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MultiSig'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Multisig verification only supports serialized signature\n\t\tconst parsed = parseSerializedSignature(multisigSignature);\n\n\t\tif (parsed.signatureScheme !== 'MultiSig') {\n\t\t\tthrow new Error('Invalid signature scheme');\n\t\t}\n\n\t\tconst { multisig } = parsed;\n\n\t\tlet signatureWeight = 0;\n\n\t\tif (\n\t\t\t!bytesEqual(\n\t\t\t\tbcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),\n\t\t\t\tbcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),\n\t\t\t)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {\n\t\t\tif (!(await publicKey.verify(message, signature))) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tsignatureWeight += weight;\n\t\t}\n\n\t\treturn signatureWeight >= this.multisigPublicKey.threshold;\n\t}\n\n\t/**\n\t * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once\n\t * and that all the public keys involved are known and valid, and then serializes multisig into the standard format\n\t */\n\tcombinePartialSignatures(signatures: string[]): string {\n\t\tif (signatures.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tlet bitmap = 0;\n\t\tconst compressedSignatures: CompressedSignature[] = new Array(signatures.length);\n\n\t\tfor (let i = 0; i < signatures.length; i++) {\n\t\t\tconst parsed = parseSerializedSignature(signatures[i]);\n\t\t\tif (parsed.signatureScheme === 'MultiSig') {\n\t\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t\t}\n\n\t\t\tlet publicKey;\n\t\t\tif (parsed.signatureScheme === 'ZkLogin') {\n\t\t\t\tpublicKey = toZkLoginPublicIdentifier(\n\t\t\t\t\tparsed.zkLogin?.addressSeed,\n\t\t\t\t\tparsed.zkLogin?.iss,\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]: Array.from(parsed.signature.map((x: number) => Number(x))),\n\t\t\t} as CompressedSignature;\n\n\t\t\tlet publicKeyIndex;\n\t\t\tfor (let j = 0; j < this.publicKeys.length; j++) {\n\t\t\t\tif (bytesEqual(publicKey, this.publicKeys[j].publicKey.toRawBytes())) {\n\t\t\t\t\tif (bitmap & (1 << j)) {\n\t\t\t\t\t\tthrow new Error('Received multiple signatures from the same public key');\n\t\t\t\t\t}\n\n\t\t\t\t\tpublicKeyIndex = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (publicKeyIndex === undefined) {\n\t\t\t\tthrow new Error('Received signature from unknown public key');\n\t\t\t}\n\n\t\t\tbitmap |= 1 << publicKeyIndex;\n\t\t}\n\n\t\tconst multisig: MultiSigStruct = {\n\t\t\tsigs: compressedSignatures,\n\t\t\tbitmap,\n\t\t\tmultisig_pk: this.multisigPublicKey,\n\t\t};\n\t\tconst bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();\n\t\tconst tmp = new Uint8Array(bytes.length + 1);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\t\ttmp.set(bytes, 1);\n\t\treturn toBase64(tmp);\n\t}\n}\n\n/**\n * Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.\n */\nexport function parsePartialSignatures(\n\tmultisig: MultiSigStruct,\n\toptions: { client?: SuiGraphQLClient } = {},\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, number[]];\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"],
|
|
5
|
+
"mappings": "AAGA,SAAS,YAAY,gBAAgB;AACrC,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAE3B,SAAS,WAAW;AAEpB,SAAS,YAAY,iBAAiB;AACtC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAEP,SAAS,gCAAgC;AAEzC,SAAS,2BAA2B;AAEpC,SAAS,6BAA6B;AACtC,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;AAqCxB,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAI/B,MAAM,0BAA0B,UAAU;AAAA;AAAA;AAAA;AAAA,EAUhD,YAIC,OACA,UAAyC,CAAC,GACzC;AACD,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,WAAW,WAAW,KAAK;AAEhC,WAAK,oBAAoB,IAAI,kBAAkB,MAAM,KAAK,QAAQ;AAAA,IACnE,WAAW,iBAAiB,YAAY;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AAM,OAAO,SAAS,YAAY,OAAO,OAAO;AAChD,UAAM,UAAU,WAAW,KAAK,OAAO,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;AAE7D,QAAI,oBAAoB,YAAY;AACnC,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,UAAM,YAAY,sBAAsB,iBAAiB,SAAS,OAAO;AAEzE,QAAI,CAAC,IAAI;AAAA,MACR;AAAA,MACA,WAAW,WAAW,KAAK,SAAS;AAAA,MACpC;AAAA,MACA,QAAQ,KAAK;AAAA,IACd;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,UAAU,QAA4B;AAC9C,MAAI,SAAS,KAAK,SAAS,MAAM;AAChC,UAAM,IAAI,MAAM,gBAAgB;AAAA,EACjC;AACA,QAAM,MAAgB,CAAC;AACvB,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAC5B,SAAK,SAAU,KAAK,OAAQ,GAAG;AAC9B,UAAI,KAAK,CAAC;AAAA,IACX;AAAA,EACD;AACA,SAAO,WAAW,KAAK,GAAG;AAC3B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,13 +15,13 @@ class MultiSigSigner extends Signer {
|
|
|
15
15
|
__privateAdd(this, _signers);
|
|
16
16
|
__privateSet(this, _pubkey, pubkey);
|
|
17
17
|
__privateSet(this, _signers, signers);
|
|
18
|
-
|
|
18
|
+
const uniqueKeys = /* @__PURE__ */ new Set();
|
|
19
19
|
let combinedWeight = 0;
|
|
20
20
|
const weights = pubkey.getPublicKeys().map(({ weight, publicKey }) => ({
|
|
21
21
|
weight,
|
|
22
22
|
address: publicKey.toSuiAddress()
|
|
23
23
|
}));
|
|
24
|
-
for (
|
|
24
|
+
for (const signer of signers) {
|
|
25
25
|
const address = signer.toSuiAddress();
|
|
26
26
|
if (uniqueKeys.has(address)) {
|
|
27
27
|
throw new Error(`Can't create MultiSigSigner with duplicate signers`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/multisig/signer.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { toBase64 } from '@mysten/bcs';\n\nimport type { SignatureScheme } from '../cryptography/index.js';\nimport { Signer } from '../cryptography/index.js';\nimport type { MultiSigPublicKey } from './publickey.js';\n\nexport class MultiSigSigner extends Signer {\n\t#pubkey: MultiSigPublicKey;\n\t#signers: Signer[];\n\n\tconstructor(pubkey: MultiSigPublicKey, signers: Signer[] = []) {\n\t\tsuper();\n\t\tthis.#pubkey = pubkey;\n\t\tthis.#signers = signers;\n\n\t\
|
|
5
|
-
"mappings": ";;;;;;;AAAA;AAEA,SAAS,gBAAgB;AAGzB,SAAS,cAAc;AAGhB,MAAM,uBAAuB,OAAO;AAAA,EAI1C,YAAY,QAA2B,UAAoB,CAAC,GAAG;AAC9D,UAAM;AAJP;AACA;AAIC,uBAAK,SAAU;AACf,uBAAK,UAAW;AAEhB,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { toBase64 } from '@mysten/bcs';\n\nimport type { SignatureScheme } from '../cryptography/index.js';\nimport { Signer } from '../cryptography/index.js';\nimport type { MultiSigPublicKey } from './publickey.js';\n\nexport class MultiSigSigner extends Signer {\n\t#pubkey: MultiSigPublicKey;\n\t#signers: Signer[];\n\n\tconstructor(pubkey: MultiSigPublicKey, signers: Signer[] = []) {\n\t\tsuper();\n\t\tthis.#pubkey = pubkey;\n\t\tthis.#signers = signers;\n\n\t\tconst uniqueKeys = new Set();\n\t\tlet combinedWeight = 0;\n\n\t\tconst weights = pubkey.getPublicKeys().map(({ weight, publicKey }) => ({\n\t\t\tweight,\n\t\t\taddress: publicKey.toSuiAddress(),\n\t\t}));\n\n\t\tfor (const signer of signers) {\n\t\t\tconst address = signer.toSuiAddress();\n\t\t\tif (uniqueKeys.has(address)) {\n\t\t\t\tthrow new Error(`Can't create MultiSigSigner with duplicate signers`);\n\t\t\t}\n\t\t\tuniqueKeys.add(address);\n\n\t\t\tconst weight = weights.find((w) => w.address === address)?.weight;\n\n\t\t\tif (!weight) {\n\t\t\t\tthrow new Error(`Signer ${address} is not part of the MultiSig public key`);\n\t\t\t}\n\n\t\t\tcombinedWeight += weight;\n\t\t}\n\n\t\tif (combinedWeight < pubkey.getThreshold()) {\n\t\t\tthrow new Error(`Combined weight of signers is less than threshold`);\n\t\t}\n\t}\n\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'MultiSig';\n\t}\n\n\tgetPublicKey(): MultiSigPublicKey {\n\t\treturn this.#pubkey;\n\t}\n\n\tsign(_data: Uint8Array): never {\n\t\tthrow new Error(\n\t\t\t'MultiSigSigner does not support signing directly. Use signTransaction or signPersonalMessage instead',\n\t\t);\n\t}\n\n\tsignData(_data: Uint8Array): never {\n\t\tthrow new Error(\n\t\t\t'MultiSigSigner does not support signing directly. Use signTransaction or signPersonalMessage instead',\n\t\t);\n\t}\n\n\tasync signTransaction(bytes: Uint8Array) {\n\t\tconst signature = this.#pubkey.combinePartialSignatures(\n\t\t\tawait Promise.all(\n\t\t\t\tthis.#signers.map(async (signer) => (await signer.signTransaction(bytes)).signature),\n\t\t\t),\n\t\t);\n\n\t\treturn {\n\t\t\tsignature,\n\t\t\tbytes: toBase64(bytes),\n\t\t};\n\t}\n\n\tasync signPersonalMessage(bytes: Uint8Array) {\n\t\tconst signature = this.#pubkey.combinePartialSignatures(\n\t\t\tawait Promise.all(\n\t\t\t\tthis.#signers.map(async (signer) => (await signer.signPersonalMessage(bytes)).signature),\n\t\t\t),\n\t\t);\n\n\t\treturn {\n\t\t\tsignature,\n\t\t\tbytes: toBase64(bytes),\n\t\t};\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAEA,SAAS,gBAAgB;AAGzB,SAAS,cAAc;AAGhB,MAAM,uBAAuB,OAAO;AAAA,EAI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ACD;AAAA,EAEA,MAAM,oBAAoB,OAAmB;AAC5C,UAAM,YAAY,mBAAK,SAAQ;AAAA,MAC9B,MAAM,QAAQ;AAAA,QACb,mBAAK,UAAS,IAAI,OAAO,YAAY,MAAM,OAAO,oBAAoB,KAAK,GAAG,SAAS;AAAA,MACxF;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,MACA,OAAO,SAAS,KAAK;AAAA,IACtB;AAAA,EACD;AACD;AAlFC;AACA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -38,7 +38,7 @@ function getFirstLevelNamedTypes(types) {
|
|
|
38
38
|
function findMvrNames(type) {
|
|
39
39
|
const types = /* @__PURE__ */ new Set();
|
|
40
40
|
if (typeof type === "string" && !hasMvrName(type)) return types;
|
|
41
|
-
|
|
41
|
+
const tag = isStructTag(type) ? type : parseStructTag(type);
|
|
42
42
|
if (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);
|
|
43
43
|
for (const param of tag.typeParams) {
|
|
44
44
|
findMvrNames(param).forEach((name) => types.add(name));
|
|
@@ -55,7 +55,7 @@ function populateNamedTypesFromCache(types, typeCache) {
|
|
|
55
55
|
}
|
|
56
56
|
function findAndReplaceCachedTypes(tag, typeCache) {
|
|
57
57
|
const type = isStructTag(tag) ? tag : parseStructTag(tag);
|
|
58
|
-
|
|
58
|
+
const typeTag = `${type.address}::${type.module}::${type.name}`;
|
|
59
59
|
const cacheHit = typeCache[typeTag];
|
|
60
60
|
return {
|
|
61
61
|
...type,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/plugins/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';\nimport { normalizeStructTag, parseStructTag } from '../../utils/sui-types.js';\nimport type { StructTag } from '../../utils/sui-types.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\n\nexport type NamedPackagesPluginCache = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\nconst NAME_SEPARATOR = '/';\n\nexport type NameResolutionRequest = {\n\tid: number;\n\ttype: 'package' | 'moveType';\n\tname: string;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport function findNamesInTransaction(builder: TransactionDataBuilder): {\n\tpackages: string[];\n\ttypes: string[];\n} {\n\tconst packages: Set<string> = new Set();\n\tconst types: Set<string> = new Set();\n\n\tfor (const command of builder.commands) {\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tgetNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {\n\t\t\t\ttypes.add(type);\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (!('MoveCall' in command)) continue;\n\t\tconst tx = command.MoveCall;\n\n\t\tif (!tx) continue;\n\n\t\tconst pkg = tx.package.split('::')[0];\n\t\tif (hasMvrName(pkg)) {\n\t\t\tif (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);\n\t\t\tpackages.add(pkg);\n\t\t}\n\n\t\tgetNamesFromTypeList(tx.typeArguments ?? []).forEach((type) => {\n\t\t\ttypes.add(type);\n\t\t});\n\t}\n\n\treturn {\n\t\tpackages: [...packages],\n\t\ttypes: [...types],\n\t};\n}\n\n/**\n * Extracts all first-level types from a list of types.\n * E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,\n * the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.\n */\nexport function getFirstLevelNamedTypes(types: string[]) {\n\tconst results: Set<string> = new Set();\n\n\tfor (const type of types) {\n\t\tfindMvrNames(type).forEach((name) => results.add(name));\n\t}\n\n\treturn results;\n}\n\n/**\n * Extracts all named types from a given type.\n */\nfunction findMvrNames(type: string | StructTag) {\n\tconst types: Set<string> = new Set();\n\n\tif (typeof type === 'string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
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';\nimport { normalizeStructTag, parseStructTag } from '../../utils/sui-types.js';\nimport type { StructTag } from '../../utils/sui-types.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\n\nexport type NamedPackagesPluginCache = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\nconst NAME_SEPARATOR = '/';\n\nexport type NameResolutionRequest = {\n\tid: number;\n\ttype: 'package' | 'moveType';\n\tname: string;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport function findNamesInTransaction(builder: TransactionDataBuilder): {\n\tpackages: string[];\n\ttypes: string[];\n} {\n\tconst packages: Set<string> = new Set();\n\tconst types: Set<string> = new Set();\n\n\tfor (const command of builder.commands) {\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tgetNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {\n\t\t\t\ttypes.add(type);\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (!('MoveCall' in command)) continue;\n\t\tconst tx = command.MoveCall;\n\n\t\tif (!tx) continue;\n\n\t\tconst pkg = tx.package.split('::')[0];\n\t\tif (hasMvrName(pkg)) {\n\t\t\tif (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);\n\t\t\tpackages.add(pkg);\n\t\t}\n\n\t\tgetNamesFromTypeList(tx.typeArguments ?? []).forEach((type) => {\n\t\t\ttypes.add(type);\n\t\t});\n\t}\n\n\treturn {\n\t\tpackages: [...packages],\n\t\ttypes: [...types],\n\t};\n}\n\n/**\n * Extracts all first-level types from a list of types.\n * E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,\n * the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.\n */\nexport function getFirstLevelNamedTypes(types: string[]) {\n\tconst results: Set<string> = new Set();\n\n\tfor (const type of types) {\n\t\tfindMvrNames(type).forEach((name) => results.add(name));\n\t}\n\n\treturn results;\n}\n\n/**\n * Extracts all named types from a given type.\n */\nfunction findMvrNames(type: string | StructTag) {\n\tconst types: Set<string> = new Set();\n\n\tif (typeof type === 'string' && !hasMvrName(type)) return types;\n\n\tconst tag = isStructTag(type) ? type : parseStructTag(type);\n\n\tif (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);\n\n\tfor (const param of tag.typeParams) {\n\t\tfindMvrNames(param).forEach((name) => types.add(name));\n\t}\n\n\treturn types;\n}\n\n// /**\n// * Allows partial replacements of known types with their resolved equivalents.\n// * E.g. `@mvr/demo::a::A<@mvr/demo::b::B>` can be resolved, if we already have\n// * the address for `@mvr/demo::b::B` and the address for `@mvr/demo::a::A`,\n// * without the need to have the full type in the cache.\n// *\n// * Returns the fully composed resolved types (if any) in a `named-type -> normalized-type` map.\n// */\nexport function populateNamedTypesFromCache(types: string[], typeCache: Record<string, string>) {\n\tconst composedTypes: Record<string, string> = {};\n\n\ttypes.forEach((type) => {\n\t\tconst normalized = normalizeStructTag(findAndReplaceCachedTypes(type, typeCache));\n\t\tcomposedTypes[type] = normalized;\n\t});\n\n\treturn composedTypes;\n}\n\n/**\n * Traverses a type, and replaces any found names with their resolved equivalents,\n * based on the supplied type cache.\n */\nfunction findAndReplaceCachedTypes(\n\ttag: string | StructTag,\n\ttypeCache: Record<string, string>,\n): StructTag {\n\tconst type = isStructTag(tag) ? tag : parseStructTag(tag);\n\n\tconst typeTag = `${type.address}::${type.module}::${type.name}`;\n\tconst cacheHit = typeCache[typeTag];\n\n\treturn {\n\t\t...type,\n\t\taddress: cacheHit ? cacheHit.split('::')[0] : type.address,\n\t\ttypeParams: type.typeParams.map((param) => findAndReplaceCachedTypes(param, typeCache)),\n\t};\n}\n\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport function replaceNames(builder: TransactionDataBuilder, cache: NamedPackagesPluginCache) {\n\tfor (const command of builder.commands) {\n\t\t// Replacements for `MakeMoveVec` commands (that can include types)\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tif (!hasMvrName(command.MakeMoveVec.type)) continue;\n\t\t\tif (!cache.types[command.MakeMoveVec.type])\n\t\t\t\tthrow new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);\n\t\t\tcommand.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];\n\t\t}\n\t\t// Replacements for `MoveCall` commands (that can include packages & types)\n\t\tconst tx = command.MoveCall;\n\t\tif (!tx) continue;\n\n\t\tconst nameParts = tx.package.split('::');\n\t\tconst name = nameParts[0];\n\n\t\tif (hasMvrName(name) && !cache.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\t// Replace package name with address.\n\t\tif (hasMvrName(name)) {\n\t\t\tnameParts[0] = cache.packages[name];\n\t\t\ttx.package = nameParts.join('::');\n\t\t}\n\n\t\tconst types = tx.typeArguments;\n\t\tif (!types) continue;\n\n\t\tfor (let i = 0; i < types.length; i++) {\n\t\t\tif (!hasMvrName(types[i])) continue;\n\n\t\t\tif (!cache.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);\n\t\t\ttypes[i] = cache.types[types[i]];\n\t\t}\n\n\t\ttx.typeArguments = types;\n\t}\n}\n\nexport function batch<T>(arr: T[], size: number): T[][] {\n\tconst batches = [];\n\tfor (let i = 0; i < arr.length; i += size) {\n\t\tbatches.push(arr.slice(i, i + size));\n\t}\n\treturn batches;\n}\n\n/**\n * Returns a list of unique types that include a name\n * from the given list. This list is retrieved from the Transaction Data.\n */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (hasMvrName(type)) {\n\t\t\tif (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);\n\t\t\tnames.add(type);\n\t\t}\n\t}\n\treturn names;\n}\n\nfunction hasMvrName(nameOrType: string) {\n\treturn (\n\t\tnameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')\n\t);\n}\n\nfunction isStructTag(type: string | StructTag): type is StructTag {\n\treturn (\n\t\ttypeof type === 'object' &&\n\t\t'address' in type &&\n\t\t'module' in type &&\n\t\t'name' in type &&\n\t\t'typeParams' in type\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,qBAAqB,wBAAwB;AACtD,SAAS,oBAAoB,sBAAsB;AASnD,MAAM,iBAAiB;AAYhB,SAAS,uBAAuB,SAGrC;AACD,QAAM,WAAwB,oBAAI,IAAI;AACtC,QAAM,QAAqB,oBAAI,IAAI;AAEnC,aAAW,WAAW,QAAQ,UAAU;AACvC,QAAI,QAAQ,aAAa,MAAM;AAC9B,2BAAqB,CAAC,QAAQ,YAAY,IAAI,CAAC,EAAE,QAAQ,CAAC,SAAS;AAClE,cAAM,IAAI,IAAI;AAAA,MACf,CAAC;AACD;AAAA,IACD;AACA,QAAI,EAAE,cAAc,SAAU;AAC9B,UAAM,KAAK,QAAQ;AAEnB,QAAI,CAAC,GAAI;AAET,UAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;AACpC,QAAI,WAAW,GAAG,GAAG;AACpB,UAAI,CAAC,oBAAoB,GAAG,EAAG,OAAM,IAAI,MAAM,yBAAyB,GAAG,EAAE;AAC7E,eAAS,IAAI,GAAG;AAAA,IACjB;AAEA,yBAAqB,GAAG,iBAAiB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS;AAC9D,YAAM,IAAI,IAAI;AAAA,IACf,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN,UAAU,CAAC,GAAG,QAAQ;AAAA,IACtB,OAAO,CAAC,GAAG,KAAK;AAAA,EACjB;AACD;AAOO,SAAS,wBAAwB,OAAiB;AACxD,QAAM,UAAuB,oBAAI,IAAI;AAErC,aAAW,QAAQ,OAAO;AACzB,iBAAa,IAAI,EAAE,QAAQ,CAAC,SAAS,QAAQ,IAAI,IAAI,CAAC;AAAA,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ACf;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,WAAW,YAAoB;AACvC,SACC,WAAW,SAAS,cAAc,KAAK,WAAW,SAAS,GAAG,KAAK,WAAW,SAAS,MAAM;AAE/F;AAEA,SAAS,YAAY,MAA6C;AACjE,SACC,OAAO,SAAS,YAChB,aAAa,QACb,YAAY,QACZ,UAAU,QACV,gBAAgB;AAElB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "1.
|
|
1
|
+
export declare const PACKAGE_VERSION = "1.27.0";
|
|
2
2
|
export declare const TARGETED_RPC_VERSION = "1.47.0";
|
package/dist/esm/version.js
CHANGED