@mysten/sui 1.10.0 → 1.11.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 +23 -0
- package/dist/cjs/bcs/bcs.js +14 -14
- package/dist/cjs/bcs/bcs.js.map +2 -2
- package/dist/cjs/client/client.js +6 -6
- package/dist/cjs/client/client.js.map +2 -2
- package/dist/cjs/client/types/generated.d.ts +1 -2
- package/dist/cjs/client/types/generated.js.map +1 -1
- package/dist/cjs/cryptography/keypair.js +2 -2
- package/dist/cjs/cryptography/keypair.js.map +2 -2
- package/dist/cjs/cryptography/mnemonics.js +1 -1
- package/dist/cjs/cryptography/mnemonics.js.map +1 -1
- package/dist/cjs/cryptography/publickey.js +2 -2
- package/dist/cjs/cryptography/publickey.js.map +2 -2
- package/dist/cjs/cryptography/signature.js +2 -2
- package/dist/cjs/cryptography/signature.js.map +2 -2
- package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js +1 -1
- package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js.map +1 -1
- package/dist/cjs/keypairs/ed25519/keypair.d.ts +2 -2
- package/dist/cjs/keypairs/ed25519/keypair.js +8 -1
- package/dist/cjs/keypairs/ed25519/keypair.js.map +2 -2
- package/dist/cjs/keypairs/ed25519/publickey.js +1 -1
- package/dist/cjs/keypairs/ed25519/publickey.js.map +2 -2
- package/dist/cjs/keypairs/secp256k1/keypair.d.ts +2 -2
- package/dist/cjs/keypairs/secp256k1/keypair.js +8 -1
- package/dist/cjs/keypairs/secp256k1/keypair.js.map +2 -2
- package/dist/cjs/keypairs/secp256k1/publickey.js +1 -1
- package/dist/cjs/keypairs/secp256k1/publickey.js.map +2 -2
- package/dist/cjs/keypairs/secp256r1/keypair.d.ts +2 -2
- package/dist/cjs/keypairs/secp256r1/keypair.js +8 -1
- package/dist/cjs/keypairs/secp256r1/keypair.js.map +2 -2
- package/dist/cjs/keypairs/secp256r1/publickey.js +1 -1
- package/dist/cjs/keypairs/secp256r1/publickey.js.map +2 -2
- package/dist/cjs/multisig/publickey.js +2 -2
- 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/Commands.js +2 -2
- package/dist/cjs/transactions/Commands.js.map +2 -2
- package/dist/cjs/transactions/Inputs.js +1 -1
- package/dist/cjs/transactions/Inputs.js.map +2 -2
- package/dist/cjs/transactions/Transaction.js +2 -2
- package/dist/cjs/transactions/Transaction.js.map +2 -2
- package/dist/cjs/transactions/TransactionData.js +1 -1
- package/dist/cjs/transactions/TransactionData.js.map +2 -2
- package/dist/cjs/transactions/data/v1.js +6 -6
- package/dist/cjs/transactions/data/v1.js.map +2 -2
- package/dist/cjs/transactions/executor/parallel.js +1 -1
- package/dist/cjs/transactions/executor/parallel.js.map +2 -2
- package/dist/cjs/transactions/executor/serial.js +1 -1
- package/dist/cjs/transactions/executor/serial.js.map +2 -2
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.js +7 -1
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/sui-types.js +1 -1
- package/dist/cjs/utils/sui-types.js.map +2 -2
- package/dist/cjs/verify/verify.js +1 -1
- package/dist/cjs/verify/verify.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/cjs/zklogin/publickey.js +5 -5
- package/dist/cjs/zklogin/publickey.js.map +2 -2
- package/dist/cjs/zklogin/signature.js +3 -3
- package/dist/cjs/zklogin/signature.js.map +2 -2
- package/dist/esm/bcs/bcs.js +15 -15
- package/dist/esm/bcs/bcs.js.map +2 -2
- package/dist/esm/client/client.js +7 -7
- package/dist/esm/client/client.js.map +2 -2
- package/dist/esm/client/types/generated.d.ts +1 -2
- package/dist/esm/cryptography/keypair.js +3 -3
- package/dist/esm/cryptography/keypair.js.map +2 -2
- package/dist/esm/cryptography/mnemonics.js +2 -2
- package/dist/esm/cryptography/mnemonics.js.map +1 -1
- package/dist/esm/cryptography/publickey.js +3 -3
- package/dist/esm/cryptography/publickey.js.map +2 -2
- package/dist/esm/cryptography/signature.js +3 -3
- package/dist/esm/cryptography/signature.js.map +2 -2
- package/dist/esm/keypairs/ed25519/ed25519-hd-key.js +2 -2
- package/dist/esm/keypairs/ed25519/ed25519-hd-key.js.map +1 -1
- package/dist/esm/keypairs/ed25519/keypair.d.ts +2 -2
- package/dist/esm/keypairs/ed25519/keypair.js +14 -2
- package/dist/esm/keypairs/ed25519/keypair.js.map +2 -2
- package/dist/esm/keypairs/ed25519/publickey.js +2 -2
- package/dist/esm/keypairs/ed25519/publickey.js.map +2 -2
- package/dist/esm/keypairs/secp256k1/keypair.d.ts +2 -2
- package/dist/esm/keypairs/secp256k1/keypair.js +9 -2
- package/dist/esm/keypairs/secp256k1/keypair.js.map +2 -2
- package/dist/esm/keypairs/secp256k1/publickey.js +2 -2
- package/dist/esm/keypairs/secp256k1/publickey.js.map +2 -2
- package/dist/esm/keypairs/secp256r1/keypair.d.ts +2 -2
- package/dist/esm/keypairs/secp256r1/keypair.js +9 -2
- package/dist/esm/keypairs/secp256r1/keypair.js.map +2 -2
- package/dist/esm/keypairs/secp256r1/publickey.js +2 -2
- package/dist/esm/keypairs/secp256r1/publickey.js.map +2 -2
- package/dist/esm/multisig/publickey.js +3 -3
- package/dist/esm/multisig/publickey.js.map +2 -2
- package/dist/esm/multisig/signer.js +3 -3
- package/dist/esm/multisig/signer.js.map +2 -2
- package/dist/esm/transactions/Commands.js +3 -3
- package/dist/esm/transactions/Commands.js.map +2 -2
- package/dist/esm/transactions/Inputs.js +2 -2
- package/dist/esm/transactions/Inputs.js.map +2 -2
- package/dist/esm/transactions/Transaction.js +3 -3
- package/dist/esm/transactions/Transaction.js.map +2 -2
- package/dist/esm/transactions/TransactionData.js +2 -2
- package/dist/esm/transactions/TransactionData.js.map +2 -2
- package/dist/esm/transactions/data/v1.js +7 -7
- package/dist/esm/transactions/data/v1.js.map +2 -2
- package/dist/esm/transactions/executor/parallel.js +2 -2
- package/dist/esm/transactions/executor/parallel.js.map +2 -2
- package/dist/esm/transactions/executor/serial.js +2 -2
- package/dist/esm/transactions/executor/serial.js.map +2 -2
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +19 -2
- package/dist/esm/utils/index.js.map +2 -2
- package/dist/esm/utils/sui-types.js +2 -2
- package/dist/esm/utils/sui-types.js.map +2 -2
- package/dist/esm/verify/verify.js +2 -2
- package/dist/esm/verify/verify.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/esm/zklogin/publickey.js +6 -6
- package/dist/esm/zklogin/publickey.js.map +2 -2
- package/dist/esm/zklogin/signature.js +4 -4
- package/dist/esm/zklogin/signature.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/bcs/bcs.ts +15 -15
- package/src/client/client.ts +7 -7
- package/src/client/types/generated.ts +1 -2
- package/src/cryptography/keypair.ts +3 -3
- package/src/cryptography/mnemonics.ts +2 -2
- package/src/cryptography/publickey.ts +3 -3
- package/src/cryptography/signature.ts +3 -3
- package/src/keypairs/ed25519/ed25519-hd-key.ts +2 -2
- package/src/keypairs/ed25519/keypair.ts +18 -3
- package/src/keypairs/ed25519/publickey.ts +2 -2
- package/src/keypairs/secp256k1/keypair.ts +13 -3
- package/src/keypairs/secp256k1/publickey.ts +2 -2
- package/src/keypairs/secp256r1/keypair.ts +13 -3
- package/src/keypairs/secp256r1/publickey.ts +2 -2
- package/src/multisig/publickey.ts +3 -3
- package/src/multisig/signer.ts +3 -3
- package/src/transactions/Commands.ts +3 -3
- package/src/transactions/Inputs.ts +2 -2
- package/src/transactions/Transaction.ts +3 -3
- package/src/transactions/TransactionData.ts +2 -2
- package/src/transactions/__tests__/Transaction.test.ts +2 -2
- package/src/transactions/__tests__/bcs.test.ts +2 -2
- package/src/transactions/data/v1.ts +7 -7
- package/src/transactions/executor/parallel.ts +2 -2
- package/src/transactions/executor/serial.ts +2 -2
- package/src/utils/index.ts +12 -1
- package/src/utils/sui-types.ts +2 -2
- package/src/verify/verify.ts +2 -2
- package/src/version.ts +1 -1
- package/src/zklogin/publickey.ts +6 -6
- package/src/zklogin/signature.ts +5 -4
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,
|
|
5
|
+
import { bcs, fromBase58, fromBase64, fromHex, 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';
|
|
@@ -29,22 +29,22 @@ function optionEnum<T extends BcsType<any, any>>(type: T) {
|
|
|
29
29
|
|
|
30
30
|
export const Address = bcs.bytes(SUI_ADDRESS_LENGTH).transform({
|
|
31
31
|
validate: (val) => {
|
|
32
|
-
const address = typeof val === 'string' ? val :
|
|
32
|
+
const address = typeof val === 'string' ? val : toHex(val);
|
|
33
33
|
if (!address || !isValidSuiAddress(normalizeSuiAddress(address))) {
|
|
34
34
|
throw new Error(`Invalid Sui address ${address}`);
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
input: (val: string | Uint8Array) =>
|
|
38
|
-
typeof val === 'string' ?
|
|
39
|
-
output: (val) => normalizeSuiAddress(
|
|
38
|
+
typeof val === 'string' ? fromHex(normalizeSuiAddress(val)) : val,
|
|
39
|
+
output: (val) => normalizeSuiAddress(toHex(val)),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
export const ObjectDigest = bcs.vector(bcs.u8()).transform({
|
|
43
43
|
name: 'ObjectDigest',
|
|
44
|
-
input: (value: string) =>
|
|
45
|
-
output: (value) =>
|
|
44
|
+
input: (value: string) => fromBase58(value),
|
|
45
|
+
output: (value) => toBase58(new Uint8Array(value)),
|
|
46
46
|
validate: (value) => {
|
|
47
|
-
if (
|
|
47
|
+
if (fromBase58(value).length !== 32) {
|
|
48
48
|
throw new Error('ObjectDigest must be 32 bytes');
|
|
49
49
|
}
|
|
50
50
|
},
|
|
@@ -71,8 +71,8 @@ export const ObjectArg = bcs.enum('ObjectArg', {
|
|
|
71
71
|
export const CallArg = bcs.enum('CallArg', {
|
|
72
72
|
Pure: bcs.struct('Pure', {
|
|
73
73
|
bytes: bcs.vector(bcs.u8()).transform({
|
|
74
|
-
input: (val: string | Uint8Array) => (typeof val === 'string' ?
|
|
75
|
-
output: (val) =>
|
|
74
|
+
input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
|
|
75
|
+
output: (val) => toBase64(new Uint8Array(val)),
|
|
76
76
|
}),
|
|
77
77
|
}),
|
|
78
78
|
Object: ObjectArg,
|
|
@@ -147,8 +147,8 @@ export const Command = bcs.enum('Command', {
|
|
|
147
147
|
Publish: bcs.struct('Publish', {
|
|
148
148
|
modules: bcs.vector(
|
|
149
149
|
bcs.vector(bcs.u8()).transform({
|
|
150
|
-
input: (val: string | Uint8Array) => (typeof val === 'string' ?
|
|
151
|
-
output: (val) =>
|
|
150
|
+
input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
|
|
151
|
+
output: (val) => toBase64(new Uint8Array(val)),
|
|
152
152
|
}),
|
|
153
153
|
),
|
|
154
154
|
dependencies: bcs.vector(Address),
|
|
@@ -175,8 +175,8 @@ export const Command = bcs.enum('Command', {
|
|
|
175
175
|
Upgrade: bcs.struct('Upgrade', {
|
|
176
176
|
modules: bcs.vector(
|
|
177
177
|
bcs.vector(bcs.u8()).transform({
|
|
178
|
-
input: (val: string | Uint8Array) => (typeof val === 'string' ?
|
|
179
|
-
output: (val) =>
|
|
178
|
+
input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
|
|
179
|
+
output: (val) => toBase64(new Uint8Array(val)),
|
|
180
180
|
}),
|
|
181
181
|
),
|
|
182
182
|
dependencies: bcs.vector(Address),
|
|
@@ -286,8 +286,8 @@ export const MultiSig = bcs.struct('MultiSig', {
|
|
|
286
286
|
});
|
|
287
287
|
|
|
288
288
|
export const base64String = bcs.vector(bcs.u8()).transform({
|
|
289
|
-
input: (val: string | Uint8Array) => (typeof val === 'string' ?
|
|
290
|
-
output: (val) =>
|
|
289
|
+
input: (val: string | Uint8Array) => (typeof val === 'string' ? fromBase64(val) : val),
|
|
290
|
+
output: (val) => toBase64(new Uint8Array(val)),
|
|
291
291
|
});
|
|
292
292
|
|
|
293
293
|
export const SenderSignedTransaction = bcs.struct('SenderSignedTransaction', {
|
package/src/client/client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { fromBase58, toBase64, toHex } from '@mysten/bcs';
|
|
4
4
|
|
|
5
5
|
import type { Signer } from '../cryptography/index.js';
|
|
6
6
|
import type { Transaction } from '../transactions/index.js';
|
|
@@ -415,7 +415,7 @@ export class SuiClient {
|
|
|
415
415
|
const result: SuiTransactionBlockResponse = await this.transport.request({
|
|
416
416
|
method: 'sui_executeTransactionBlock',
|
|
417
417
|
params: [
|
|
418
|
-
typeof transactionBlock === 'string' ? transactionBlock :
|
|
418
|
+
typeof transactionBlock === 'string' ? transactionBlock : toBase64(transactionBlock),
|
|
419
419
|
Array.isArray(signature) ? signature : [signature],
|
|
420
420
|
options,
|
|
421
421
|
],
|
|
@@ -580,7 +580,7 @@ export class SuiClient {
|
|
|
580
580
|
let devInspectTxBytes;
|
|
581
581
|
if (isTransaction(input.transactionBlock)) {
|
|
582
582
|
input.transactionBlock.setSenderIfNotSet(input.sender);
|
|
583
|
-
devInspectTxBytes =
|
|
583
|
+
devInspectTxBytes = toBase64(
|
|
584
584
|
await input.transactionBlock.build({
|
|
585
585
|
client: this,
|
|
586
586
|
onlyTransactionKind: true,
|
|
@@ -589,7 +589,7 @@ export class SuiClient {
|
|
|
589
589
|
} else if (typeof input.transactionBlock === 'string') {
|
|
590
590
|
devInspectTxBytes = input.transactionBlock;
|
|
591
591
|
} else if (input.transactionBlock instanceof Uint8Array) {
|
|
592
|
-
devInspectTxBytes =
|
|
592
|
+
devInspectTxBytes = toBase64(input.transactionBlock);
|
|
593
593
|
} else {
|
|
594
594
|
throw new Error('Unknown transaction block format.');
|
|
595
595
|
}
|
|
@@ -611,7 +611,7 @@ export class SuiClient {
|
|
|
611
611
|
params: [
|
|
612
612
|
typeof input.transactionBlock === 'string'
|
|
613
613
|
? input.transactionBlock
|
|
614
|
-
:
|
|
614
|
+
: toBase64(input.transactionBlock),
|
|
615
615
|
],
|
|
616
616
|
});
|
|
617
617
|
}
|
|
@@ -743,8 +743,8 @@ export class SuiClient {
|
|
|
743
743
|
// TODO: Migrate this to `sui_getChainIdentifier` once it is widely available.
|
|
744
744
|
async getChainIdentifier(): Promise<string> {
|
|
745
745
|
const checkpoint = await this.getCheckpoint({ id: '0' });
|
|
746
|
-
const bytes =
|
|
747
|
-
return
|
|
746
|
+
const bytes = fromBase58(checkpoint.digest);
|
|
747
|
+
return toHex(bytes.slice(0, 4));
|
|
748
748
|
}
|
|
749
749
|
|
|
750
750
|
async resolveNameServiceAddress(input: ResolveNameServiceAddressParams): Promise<string | null> {
|
|
@@ -290,8 +290,7 @@ export type SuiEventFilter =
|
|
|
290
290
|
Or: [SuiEventFilter, SuiEventFilter];
|
|
291
291
|
};
|
|
292
292
|
/**
|
|
293
|
-
* Unique ID of a Sui Event, the ID is a combination of
|
|
294
|
-
* local to this particular fullnode and will be different from other fullnode.
|
|
293
|
+
* Unique ID of a Sui Event, the ID is a combination of transaction digest and event seq number.
|
|
295
294
|
*/
|
|
296
295
|
export interface EventId {
|
|
297
296
|
eventSeq: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { bcs,
|
|
4
|
+
import { bcs, toBase64 } from '@mysten/bcs';
|
|
5
5
|
import { blake2b } from '@noble/hashes/blake2b';
|
|
6
6
|
import { bech32 } from 'bech32';
|
|
7
7
|
|
|
@@ -47,7 +47,7 @@ export abstract class Signer {
|
|
|
47
47
|
|
|
48
48
|
return {
|
|
49
49
|
signature,
|
|
50
|
-
bytes:
|
|
50
|
+
bytes: toBase64(bytes),
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -66,7 +66,7 @@ export abstract class Signer {
|
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
return {
|
|
69
|
-
bytes:
|
|
69
|
+
bytes: toBase64(bytes),
|
|
70
70
|
signature,
|
|
71
71
|
};
|
|
72
72
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { toHex } from '@mysten/bcs';
|
|
4
4
|
import { mnemonicToSeedSync as bip39MnemonicToSeedSync } from '@scure/bip39';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -45,5 +45,5 @@ export function mnemonicToSeed(mnemonics: string): Uint8Array {
|
|
|
45
45
|
* @param mnemonics 12 words string split by spaces.
|
|
46
46
|
*/
|
|
47
47
|
export function mnemonicToSeedHex(mnemonics: string): string {
|
|
48
|
-
return
|
|
48
|
+
return toHex(mnemonicToSeed(mnemonics));
|
|
49
49
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { toBase64 } from '@mysten/bcs';
|
|
5
5
|
import { blake2b } from '@noble/hashes/blake2b';
|
|
6
6
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
7
7
|
|
|
@@ -45,7 +45,7 @@ export abstract class PublicKey {
|
|
|
45
45
|
* Return the base-64 representation of the public key
|
|
46
46
|
*/
|
|
47
47
|
toBase64() {
|
|
48
|
-
return
|
|
48
|
+
return toBase64(this.toRawBytes());
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
toString(): never {
|
|
@@ -61,7 +61,7 @@ export abstract class PublicKey {
|
|
|
61
61
|
*/
|
|
62
62
|
toSuiPublicKey(): string {
|
|
63
63
|
const bytes = this.toSuiBytes();
|
|
64
|
-
return
|
|
64
|
+
return toBase64(bytes);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
verifyWithIntent(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { fromBase64, toBase64 } from '@mysten/bcs';
|
|
5
5
|
|
|
6
6
|
import { bcs } from '../bcs/index.js';
|
|
7
7
|
import type { MultiSigStruct } from '../multisig/publickey.js';
|
|
@@ -42,14 +42,14 @@ export function toSerializedSignature({
|
|
|
42
42
|
serializedSignature.set([SIGNATURE_SCHEME_TO_FLAG[signatureScheme]]);
|
|
43
43
|
serializedSignature.set(signature, 1);
|
|
44
44
|
serializedSignature.set(pubKeyBytes, 1 + signature.length);
|
|
45
|
-
return
|
|
45
|
+
return toBase64(serializedSignature);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Decodes a serialized signature into its constituent components: the signature scheme, the actual signature, and the public key
|
|
50
50
|
*/
|
|
51
51
|
export function parseSerializedSignature(serializedSignature: string) {
|
|
52
|
-
const bytes =
|
|
52
|
+
const bytes = fromBase64(serializedSignature);
|
|
53
53
|
|
|
54
54
|
const signatureScheme =
|
|
55
55
|
SIGNATURE_FLAG_TO_SCHEME[bytes[0] as keyof typeof SIGNATURE_FLAG_TO_SCHEME];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// This is adapted from https://github.com/alepop/ed25519-hd-key replacing create-hmac
|
|
5
5
|
// with @noble/hashes to be browser compatible.
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { fromHex } from '@mysten/bcs';
|
|
8
8
|
import { hmac } from '@noble/hashes/hmac';
|
|
9
9
|
import { sha512 } from '@noble/hashes/sha512';
|
|
10
10
|
import nacl from 'tweetnacl';
|
|
@@ -26,7 +26,7 @@ export const replaceDerive = (val: string): string => val.replace("'", '');
|
|
|
26
26
|
|
|
27
27
|
export const getMasterKeyFromSeed = (seed: Hex): Keys => {
|
|
28
28
|
const h = hmac.create(sha512, ED25519_CURVE);
|
|
29
|
-
const I = h.update(
|
|
29
|
+
const I = h.update(fromHex(seed)).digest();
|
|
30
30
|
const IL = I.slice(0, 32);
|
|
31
31
|
const IR = I.slice(32);
|
|
32
32
|
return {
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import nacl from 'tweetnacl';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
decodeSuiPrivateKey,
|
|
8
|
+
encodeSuiPrivateKey,
|
|
9
|
+
Keypair,
|
|
10
|
+
PRIVATE_KEY_SIZE,
|
|
11
|
+
} from '../../cryptography/keypair.js';
|
|
7
12
|
import { isValidHardenedPath, mnemonicToSeedHex } from '../../cryptography/mnemonics.js';
|
|
8
13
|
import type { SignatureScheme } from '../../cryptography/signature-scheme.js';
|
|
9
14
|
import { derivePath } from './ed25519-hd-key.js';
|
|
@@ -63,13 +68,23 @@ export class Ed25519Keypair extends Keypair {
|
|
|
63
68
|
*
|
|
64
69
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
65
70
|
*
|
|
66
|
-
* @param secretKey secret key byte array
|
|
71
|
+
* @param secretKey secret key as a byte array or Bech32 secret key string
|
|
67
72
|
* @param options: skip secret key validation
|
|
68
73
|
*/
|
|
69
74
|
static fromSecretKey(
|
|
70
|
-
secretKey: Uint8Array,
|
|
75
|
+
secretKey: Uint8Array | string,
|
|
71
76
|
options?: { skipValidation?: boolean },
|
|
72
77
|
): Ed25519Keypair {
|
|
78
|
+
if (typeof secretKey === 'string') {
|
|
79
|
+
const decoded = decodeSuiPrivateKey(secretKey);
|
|
80
|
+
|
|
81
|
+
if (decoded.schema !== 'ED25519') {
|
|
82
|
+
throw new Error(`Expected a ED25519 keypair, got ${decoded.schema}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return this.fromSecretKey(decoded.secretKey, options);
|
|
86
|
+
}
|
|
87
|
+
|
|
73
88
|
const secretKeyLength = secretKey.length;
|
|
74
89
|
if (secretKeyLength !== PRIVATE_KEY_SIZE) {
|
|
75
90
|
throw new Error(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { fromBase64 } from '@mysten/bcs';
|
|
5
5
|
import nacl from 'tweetnacl';
|
|
6
6
|
|
|
7
7
|
import type { PublicKeyInitData } from '../../cryptography/publickey.js';
|
|
@@ -26,7 +26,7 @@ export class Ed25519PublicKey extends PublicKey {
|
|
|
26
26
|
super();
|
|
27
27
|
|
|
28
28
|
if (typeof value === 'string') {
|
|
29
|
-
this.data =
|
|
29
|
+
this.data = fromBase64(value);
|
|
30
30
|
} else if (value instanceof Uint8Array) {
|
|
31
31
|
this.data = value;
|
|
32
32
|
} else {
|
|
@@ -7,7 +7,7 @@ import { sha256 } from '@noble/hashes/sha256';
|
|
|
7
7
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
8
8
|
import { HDKey } from '@scure/bip32';
|
|
9
9
|
|
|
10
|
-
import { encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';
|
|
10
|
+
import { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';
|
|
11
11
|
import { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';
|
|
12
12
|
import type { PublicKey } from '../../cryptography/publickey.js';
|
|
13
13
|
import type { SignatureScheme } from '../../cryptography/signature-scheme.js';
|
|
@@ -70,14 +70,24 @@ export class Secp256k1Keypair extends Keypair {
|
|
|
70
70
|
*
|
|
71
71
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
72
72
|
*
|
|
73
|
-
* @param secretKey secret key byte array
|
|
73
|
+
* @param secretKey secret key byte array or Bech32 secret key string
|
|
74
74
|
* @param options: skip secret key validation
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
77
|
static fromSecretKey(
|
|
78
|
-
secretKey: Uint8Array,
|
|
78
|
+
secretKey: Uint8Array | string,
|
|
79
79
|
options?: { skipValidation?: boolean },
|
|
80
80
|
): Secp256k1Keypair {
|
|
81
|
+
if (typeof secretKey === 'string') {
|
|
82
|
+
const decoded = decodeSuiPrivateKey(secretKey);
|
|
83
|
+
|
|
84
|
+
if (decoded.schema !== 'Secp256k1') {
|
|
85
|
+
throw new Error(`Expected a Secp256k1 keypair, got ${decoded.schema}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return this.fromSecretKey(decoded.secretKey, options);
|
|
89
|
+
}
|
|
90
|
+
|
|
81
91
|
const publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);
|
|
82
92
|
if (!options || !options.skipValidation) {
|
|
83
93
|
const encoder = new TextEncoder();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { fromBase64 } from '@mysten/bcs';
|
|
5
5
|
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
6
6
|
import { sha256 } from '@noble/hashes/sha256';
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ export class Secp256k1PublicKey extends PublicKey {
|
|
|
27
27
|
super();
|
|
28
28
|
|
|
29
29
|
if (typeof value === 'string') {
|
|
30
|
-
this.data =
|
|
30
|
+
this.data = fromBase64(value);
|
|
31
31
|
} else if (value instanceof Uint8Array) {
|
|
32
32
|
this.data = value;
|
|
33
33
|
} else {
|
|
@@ -7,7 +7,7 @@ import { sha256 } from '@noble/hashes/sha256';
|
|
|
7
7
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
8
8
|
import { HDKey } from '@scure/bip32';
|
|
9
9
|
|
|
10
|
-
import { encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';
|
|
10
|
+
import { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';
|
|
11
11
|
import { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';
|
|
12
12
|
import type { PublicKey } from '../../cryptography/publickey.js';
|
|
13
13
|
import type { SignatureScheme } from '../../cryptography/signature-scheme.js';
|
|
@@ -70,14 +70,24 @@ export class Secp256r1Keypair extends Keypair {
|
|
|
70
70
|
*
|
|
71
71
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
72
72
|
*
|
|
73
|
-
* @param secretKey secret key byte array
|
|
73
|
+
* @param secretKey secret key byte array or Bech32 secret key string
|
|
74
74
|
* @param options: skip secret key validation
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
77
|
static fromSecretKey(
|
|
78
|
-
secretKey: Uint8Array,
|
|
78
|
+
secretKey: Uint8Array | string,
|
|
79
79
|
options?: { skipValidation?: boolean },
|
|
80
80
|
): Secp256r1Keypair {
|
|
81
|
+
if (typeof secretKey === 'string') {
|
|
82
|
+
const decoded = decodeSuiPrivateKey(secretKey);
|
|
83
|
+
|
|
84
|
+
if (decoded.schema !== 'Secp256r1') {
|
|
85
|
+
throw new Error(`Expected a Secp256r1 keypair, got ${decoded.schema}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return this.fromSecretKey(decoded.secretKey, options);
|
|
89
|
+
}
|
|
90
|
+
|
|
81
91
|
const publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);
|
|
82
92
|
if (!options || !options.skipValidation) {
|
|
83
93
|
const encoder = new TextEncoder();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { fromBase64 } from '@mysten/bcs';
|
|
5
5
|
import { secp256r1 } from '@noble/curves/p256';
|
|
6
6
|
import { sha256 } from '@noble/hashes/sha256';
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ export class Secp256r1PublicKey extends PublicKey {
|
|
|
27
27
|
super();
|
|
28
28
|
|
|
29
29
|
if (typeof value === 'string') {
|
|
30
|
-
this.data =
|
|
30
|
+
this.data = fromBase64(value);
|
|
31
31
|
} else if (value instanceof Uint8Array) {
|
|
32
32
|
this.data = value;
|
|
33
33
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { fromBase64, toBase64 } from '@mysten/bcs';
|
|
5
5
|
import { blake2b } from '@noble/hashes/blake2b';
|
|
6
6
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
7
7
|
|
|
@@ -81,7 +81,7 @@ export class MultiSigPublicKey extends PublicKey {
|
|
|
81
81
|
super();
|
|
82
82
|
|
|
83
83
|
if (typeof value === 'string') {
|
|
84
|
-
this.rawBytes =
|
|
84
|
+
this.rawBytes = fromBase64(value);
|
|
85
85
|
|
|
86
86
|
this.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);
|
|
87
87
|
} else if (value instanceof Uint8Array) {
|
|
@@ -306,7 +306,7 @@ export class MultiSigPublicKey extends PublicKey {
|
|
|
306
306
|
let tmp = new Uint8Array(bytes.length + 1);
|
|
307
307
|
tmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);
|
|
308
308
|
tmp.set(bytes, 1);
|
|
309
|
-
return
|
|
309
|
+
return toBase64(tmp);
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
|
package/src/multisig/signer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { toBase64 } from '@mysten/bcs';
|
|
4
4
|
|
|
5
5
|
import type { SignatureScheme } from '../cryptography/index.js';
|
|
6
6
|
import { Signer } from '../cryptography/index.js';
|
|
@@ -73,7 +73,7 @@ export class MultiSigSigner extends Signer {
|
|
|
73
73
|
|
|
74
74
|
return {
|
|
75
75
|
signature,
|
|
76
|
-
bytes:
|
|
76
|
+
bytes: toBase64(bytes),
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -86,7 +86,7 @@ export class MultiSigSigner extends Signer {
|
|
|
86
86
|
|
|
87
87
|
return {
|
|
88
88
|
signature,
|
|
89
|
-
bytes:
|
|
89
|
+
bytes: toBase64(bytes),
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { toBase64 } from '@mysten/bcs';
|
|
5
5
|
import type { InferInput } from 'valibot';
|
|
6
6
|
import { parse } from 'valibot';
|
|
7
7
|
|
|
@@ -108,7 +108,7 @@ export const Commands = {
|
|
|
108
108
|
$kind: 'Publish',
|
|
109
109
|
Publish: {
|
|
110
110
|
modules: modules.map((module) =>
|
|
111
|
-
typeof module === 'string' ? module :
|
|
111
|
+
typeof module === 'string' ? module : toBase64(new Uint8Array(module)),
|
|
112
112
|
),
|
|
113
113
|
dependencies: dependencies.map((dep) => normalizeSuiObjectId(dep)),
|
|
114
114
|
},
|
|
@@ -129,7 +129,7 @@ export const Commands = {
|
|
|
129
129
|
$kind: 'Upgrade',
|
|
130
130
|
Upgrade: {
|
|
131
131
|
modules: modules.map((module) =>
|
|
132
|
-
typeof module === 'string' ? module :
|
|
132
|
+
typeof module === 'string' ? module : toBase64(new Uint8Array(module)),
|
|
133
133
|
),
|
|
134
134
|
dependencies: dependencies.map((dep) => normalizeSuiObjectId(dep)),
|
|
135
135
|
package: packageId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { toBase64 } from '@mysten/bcs';
|
|
5
5
|
import type { SerializedBcs } from '@mysten/bcs';
|
|
6
6
|
|
|
7
7
|
import { normalizeSuiAddress } from '../utils/sui-types.js';
|
|
@@ -11,7 +11,7 @@ function Pure(data: Uint8Array | SerializedBcs<any>): Extract<CallArg, { Pure: u
|
|
|
11
11
|
return {
|
|
12
12
|
$kind: 'Pure',
|
|
13
13
|
Pure: {
|
|
14
|
-
bytes: data instanceof Uint8Array ?
|
|
14
|
+
bytes: data instanceof Uint8Array ? toBase64(data) : data.toBase64(),
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
17
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { SerializedBcs } from '@mysten/bcs';
|
|
5
|
-
import {
|
|
5
|
+
import { fromBase64, isSerializedBcs } from '@mysten/bcs';
|
|
6
6
|
import type { InferInput } from 'valibot';
|
|
7
7
|
import { is, parse } from 'valibot';
|
|
8
8
|
|
|
@@ -144,7 +144,7 @@ export class Transaction {
|
|
|
144
144
|
const tx = new Transaction();
|
|
145
145
|
|
|
146
146
|
tx.#data = TransactionDataBuilder.fromKindBytes(
|
|
147
|
-
typeof serialized === 'string' ?
|
|
147
|
+
typeof serialized === 'string' ? fromBase64(serialized) : serialized,
|
|
148
148
|
);
|
|
149
149
|
|
|
150
150
|
return tx;
|
|
@@ -163,7 +163,7 @@ export class Transaction {
|
|
|
163
163
|
newTransaction.#data = new TransactionDataBuilder(transaction.getData());
|
|
164
164
|
} else if (typeof transaction !== 'string' || !transaction.startsWith('{')) {
|
|
165
165
|
newTransaction.#data = TransactionDataBuilder.fromBytes(
|
|
166
|
-
typeof transaction === 'string' ?
|
|
166
|
+
typeof transaction === 'string' ? fromBase64(transaction) : transaction,
|
|
167
167
|
);
|
|
168
168
|
} else {
|
|
169
169
|
newTransaction.#data = TransactionDataBuilder.restore(JSON.parse(transaction));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { toBase58 } from '@mysten/bcs';
|
|
5
5
|
import type { InferInput } from 'valibot';
|
|
6
6
|
import { parse } from 'valibot';
|
|
7
7
|
|
|
@@ -87,7 +87,7 @@ export class TransactionDataBuilder implements TransactionData {
|
|
|
87
87
|
*/
|
|
88
88
|
static getDigestFromBytes(bytes: Uint8Array) {
|
|
89
89
|
const hash = hashTypedData('TransactionData', bytes);
|
|
90
|
-
return
|
|
90
|
+
return toBase58(hash);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// @deprecated use gasData instead
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { toBase58 } from '@mysten/bcs';
|
|
5
5
|
import { describe, expect, it } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { bcs } from '../../bcs/index.js';
|
|
@@ -165,7 +165,7 @@ function ref(): { objectId: string; version: string; digest: string } {
|
|
|
165
165
|
return {
|
|
166
166
|
objectId: (Math.random() * 100000).toFixed(0).padEnd(64, '0'),
|
|
167
167
|
version: String((Math.random() * 10000).toFixed(0)),
|
|
168
|
-
digest:
|
|
168
|
+
digest: toBase58(
|
|
169
169
|
new Uint8Array([
|
|
170
170
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1,
|
|
171
171
|
2,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { toBase58 } from '@mysten/bcs';
|
|
5
5
|
import { expect, it } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { bcs } from '../../bcs/index.js';
|
|
@@ -51,7 +51,7 @@ function ref(): { objectId: string; version: string; digest: string } {
|
|
|
51
51
|
return {
|
|
52
52
|
objectId: normalizeSuiAddress((Math.random() * 100000).toFixed(0).padEnd(64, '0')),
|
|
53
53
|
version: String((Math.random() * 10000).toFixed(0)),
|
|
54
|
-
digest:
|
|
54
|
+
digest: toBase58(
|
|
55
55
|
new Uint8Array([
|
|
56
56
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1,
|
|
57
57
|
2,
|