@mysten/sui 1.10.0 → 1.12.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 +30 -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/graphql/generated/2024.1/tada-env.d.js.map +1 -1
- package/dist/cjs/graphql/generated/2024.4/tada-env.d.js.map +1 -1
- package/dist/cjs/graphql/schemas/2024.1/index.d.ts +32 -0
- package/dist/cjs/graphql/schemas/2024.4/index.d.ts +63 -1
- 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/transactions/json-rpc-resolver.js +1 -1
- package/dist/cjs/transactions/json-rpc-resolver.js.map +1 -1
- package/dist/cjs/utils/dynamic-fields.d.ts +2 -0
- package/dist/cjs/utils/dynamic-fields.js +41 -0
- package/dist/cjs/utils/dynamic-fields.js.map +7 -0
- package/dist/cjs/utils/index.d.ts +2 -1
- package/dist/cjs/utils/index.js +9 -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 +2 -2
- package/dist/cjs/version.js +2 -2
- 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/graphql/schemas/2024.1/index.d.ts +32 -0
- package/dist/esm/graphql/schemas/2024.4/index.d.ts +63 -1
- 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/transactions/json-rpc-resolver.js +1 -1
- package/dist/esm/transactions/json-rpc-resolver.js.map +1 -1
- package/dist/esm/utils/dynamic-fields.d.ts +2 -0
- package/dist/esm/utils/dynamic-fields.js +21 -0
- package/dist/esm/utils/dynamic-fields.js.map +7 -0
- package/dist/esm/utils/index.d.ts +2 -1
- package/dist/esm/utils/index.js +21 -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 +2 -2
- package/dist/esm/version.js +2 -2
- 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/graphql/generated/2024.1/schema.graphql +18 -4
- package/src/graphql/generated/2024.1/tada-env.d.ts +1 -1
- package/src/graphql/generated/2024.4/schema.graphql +33 -5
- package/src/graphql/generated/2024.4/tada-env.d.ts +3 -2
- 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/transactions/json-rpc-resolver.ts +1 -1
- package/src/utils/dynamic-fields.ts +30 -0
- package/src/utils/index.ts +14 -1
- package/src/utils/sui-types.ts +2 -2
- package/src/verify/verify.ts +2 -2
- package/src/version.ts +2 -2
- package/src/zklogin/publickey.ts +6 -6
- package/src/zklogin/signature.ts +5 -4
- package/dist/cjs/graphql/generated/2024-01/tada-env.d.js +0 -17
- package/dist/cjs/graphql/generated/2024-01/tada-env.d.js.map +0 -7
- package/dist/esm/graphql/generated/2024-01/tada-env.d.js +0 -1
- package/dist/esm/graphql/generated/2024-01/tada-env.d.js.map +0 -7
- package/src/graphql/generated/2024-01/tada-env.d.ts +0 -202
|
@@ -6395,6 +6395,26 @@ export declare const graphql: import("gql.tada").GraphQLTadaAPI<{
|
|
|
6395
6395
|
kind: "OBJECT";
|
|
6396
6396
|
name: "ServiceConfig";
|
|
6397
6397
|
fields: {
|
|
6398
|
+
"availableVersions": {
|
|
6399
|
+
name: "availableVersions";
|
|
6400
|
+
type: {
|
|
6401
|
+
kind: "NON_NULL";
|
|
6402
|
+
name: never;
|
|
6403
|
+
ofType: {
|
|
6404
|
+
kind: "LIST";
|
|
6405
|
+
name: never;
|
|
6406
|
+
ofType: {
|
|
6407
|
+
kind: "NON_NULL";
|
|
6408
|
+
name: never;
|
|
6409
|
+
ofType: {
|
|
6410
|
+
kind: "SCALAR";
|
|
6411
|
+
name: "String";
|
|
6412
|
+
ofType: null;
|
|
6413
|
+
};
|
|
6414
|
+
};
|
|
6415
|
+
};
|
|
6416
|
+
};
|
|
6417
|
+
};
|
|
6398
6418
|
"defaultPageSize": {
|
|
6399
6419
|
name: "defaultPageSize";
|
|
6400
6420
|
type: {
|
|
@@ -6559,6 +6579,18 @@ export declare const graphql: import("gql.tada").GraphQLTadaAPI<{
|
|
|
6559
6579
|
};
|
|
6560
6580
|
};
|
|
6561
6581
|
};
|
|
6582
|
+
"mutationTimeoutMs": {
|
|
6583
|
+
name: "mutationTimeoutMs";
|
|
6584
|
+
type: {
|
|
6585
|
+
kind: "NON_NULL";
|
|
6586
|
+
name: never;
|
|
6587
|
+
ofType: {
|
|
6588
|
+
kind: "SCALAR";
|
|
6589
|
+
name: "Int";
|
|
6590
|
+
ofType: null;
|
|
6591
|
+
};
|
|
6592
|
+
};
|
|
6593
|
+
};
|
|
6562
6594
|
"requestTimeoutMs": {
|
|
6563
6595
|
name: "requestTimeoutMs";
|
|
6564
6596
|
type: {
|
|
@@ -6399,6 +6399,26 @@ export declare const graphql: import("gql.tada").GraphQLTadaAPI<{
|
|
|
6399
6399
|
kind: "OBJECT";
|
|
6400
6400
|
name: "ServiceConfig";
|
|
6401
6401
|
fields: {
|
|
6402
|
+
"availableVersions": {
|
|
6403
|
+
name: "availableVersions";
|
|
6404
|
+
type: {
|
|
6405
|
+
kind: "NON_NULL";
|
|
6406
|
+
name: never;
|
|
6407
|
+
ofType: {
|
|
6408
|
+
kind: "LIST";
|
|
6409
|
+
name: never;
|
|
6410
|
+
ofType: {
|
|
6411
|
+
kind: "NON_NULL";
|
|
6412
|
+
name: never;
|
|
6413
|
+
ofType: {
|
|
6414
|
+
kind: "SCALAR";
|
|
6415
|
+
name: "String";
|
|
6416
|
+
ofType: null;
|
|
6417
|
+
};
|
|
6418
|
+
};
|
|
6419
|
+
};
|
|
6420
|
+
};
|
|
6421
|
+
};
|
|
6402
6422
|
"defaultPageSize": {
|
|
6403
6423
|
name: "defaultPageSize";
|
|
6404
6424
|
type: {
|
|
@@ -6563,6 +6583,18 @@ export declare const graphql: import("gql.tada").GraphQLTadaAPI<{
|
|
|
6563
6583
|
};
|
|
6564
6584
|
};
|
|
6565
6585
|
};
|
|
6586
|
+
"mutationTimeoutMs": {
|
|
6587
|
+
name: "mutationTimeoutMs";
|
|
6588
|
+
type: {
|
|
6589
|
+
kind: "NON_NULL";
|
|
6590
|
+
name: never;
|
|
6591
|
+
ofType: {
|
|
6592
|
+
kind: "SCALAR";
|
|
6593
|
+
name: "Int";
|
|
6594
|
+
ofType: null;
|
|
6595
|
+
};
|
|
6596
|
+
};
|
|
6597
|
+
};
|
|
6566
6598
|
"requestTimeoutMs": {
|
|
6567
6599
|
name: "requestTimeoutMs";
|
|
6568
6600
|
type: {
|
|
@@ -6637,6 +6669,36 @@ export declare const graphql: import("gql.tada").GraphQLTadaAPI<{
|
|
|
6637
6669
|
};
|
|
6638
6670
|
};
|
|
6639
6671
|
};
|
|
6672
|
+
SharedObjectCancelled: {
|
|
6673
|
+
kind: "OBJECT";
|
|
6674
|
+
name: "SharedObjectCancelled";
|
|
6675
|
+
fields: {
|
|
6676
|
+
"address": {
|
|
6677
|
+
name: "address";
|
|
6678
|
+
type: {
|
|
6679
|
+
kind: "NON_NULL";
|
|
6680
|
+
name: never;
|
|
6681
|
+
ofType: {
|
|
6682
|
+
kind: "SCALAR";
|
|
6683
|
+
name: "SuiAddress";
|
|
6684
|
+
ofType: null;
|
|
6685
|
+
};
|
|
6686
|
+
};
|
|
6687
|
+
};
|
|
6688
|
+
"version": {
|
|
6689
|
+
name: "version";
|
|
6690
|
+
type: {
|
|
6691
|
+
kind: "NON_NULL";
|
|
6692
|
+
name: never;
|
|
6693
|
+
ofType: {
|
|
6694
|
+
kind: "SCALAR";
|
|
6695
|
+
name: "Int";
|
|
6696
|
+
ofType: null;
|
|
6697
|
+
};
|
|
6698
|
+
};
|
|
6699
|
+
};
|
|
6700
|
+
};
|
|
6701
|
+
};
|
|
6640
6702
|
SharedObjectDelete: {
|
|
6641
6703
|
kind: "OBJECT";
|
|
6642
6704
|
name: "SharedObjectDelete";
|
|
@@ -8273,7 +8335,7 @@ export declare const graphql: import("gql.tada").GraphQLTadaAPI<{
|
|
|
8273
8335
|
kind: "UNION";
|
|
8274
8336
|
name: "UnchangedSharedObject";
|
|
8275
8337
|
fields: {};
|
|
8276
|
-
possibleTypes: "SharedObjectDelete" | "SharedObjectRead";
|
|
8338
|
+
possibleTypes: "SharedObjectCancelled" | "SharedObjectDelete" | "SharedObjectRead";
|
|
8277
8339
|
};
|
|
8278
8340
|
UnchangedSharedObjectConnection: {
|
|
8279
8341
|
kind: "OBJECT";
|
|
@@ -46,7 +46,7 @@ const pathRegex = new RegExp("^m(\\/[0-9]+')+$");
|
|
|
46
46
|
const replaceDerive = (val) => val.replace("'", "");
|
|
47
47
|
const getMasterKeyFromSeed = (seed) => {
|
|
48
48
|
const h = import_hmac.hmac.create(import_sha512.sha512, ED25519_CURVE);
|
|
49
|
-
const I = h.update((0, import_bcs.
|
|
49
|
+
const I = h.update((0, import_bcs.fromHex)(seed)).digest();
|
|
50
50
|
const IL = I.slice(0, 32);
|
|
51
51
|
const IR = I.slice(32);
|
|
52
52
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/ed25519/ed25519-hd-key.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This is adapted from https://github.com/alepop/ed25519-hd-key replacing create-hmac\n// with @noble/hashes to be browser compatible.\n\nimport {
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This is adapted from https://github.com/alepop/ed25519-hd-key replacing create-hmac\n// with @noble/hashes to be browser compatible.\n\nimport { fromHex } from '@mysten/bcs';\nimport { hmac } from '@noble/hashes/hmac';\nimport { sha512 } from '@noble/hashes/sha512';\nimport nacl from 'tweetnacl';\n\ntype Hex = string;\ntype Path = string;\n\ntype Keys = {\n\tkey: Uint8Array;\n\tchainCode: Uint8Array;\n};\n\nconst ED25519_CURVE = 'ed25519 seed';\nconst HARDENED_OFFSET = 0x80000000;\n\nexport const pathRegex = new RegExp(\"^m(\\\\/[0-9]+')+$\");\n\nexport const replaceDerive = (val: string): string => val.replace(\"'\", '');\n\nexport const getMasterKeyFromSeed = (seed: Hex): Keys => {\n\tconst h = hmac.create(sha512, ED25519_CURVE);\n\tconst I = h.update(fromHex(seed)).digest();\n\tconst IL = I.slice(0, 32);\n\tconst IR = I.slice(32);\n\treturn {\n\t\tkey: IL,\n\t\tchainCode: IR,\n\t};\n};\n\nconst CKDPriv = ({ key, chainCode }: Keys, index: number): Keys => {\n\tconst indexBuffer = new ArrayBuffer(4);\n\tconst cv = new DataView(indexBuffer);\n\tcv.setUint32(0, index);\n\n\tconst data = new Uint8Array(1 + key.length + indexBuffer.byteLength);\n\tdata.set(new Uint8Array(1).fill(0));\n\tdata.set(key, 1);\n\tdata.set(new Uint8Array(indexBuffer, 0, indexBuffer.byteLength), key.length + 1);\n\n\tconst I = hmac.create(sha512, chainCode).update(data).digest();\n\tconst IL = I.slice(0, 32);\n\tconst IR = I.slice(32);\n\treturn {\n\t\tkey: IL,\n\t\tchainCode: IR,\n\t};\n};\n\nexport const getPublicKey = (privateKey: Uint8Array, withZeroByte = true): Uint8Array => {\n\tconst keyPair = nacl.sign.keyPair.fromSeed(privateKey);\n\tconst signPk = keyPair.secretKey.subarray(32);\n\tconst newArr = new Uint8Array(signPk.length + 1);\n\tnewArr.set([0]);\n\tnewArr.set(signPk, 1);\n\treturn withZeroByte ? newArr : signPk;\n};\n\nexport const isValidPath = (path: string): boolean => {\n\tif (!pathRegex.test(path)) {\n\t\treturn false;\n\t}\n\treturn !path\n\t\t.split('/')\n\t\t.slice(1)\n\t\t.map(replaceDerive)\n\t\t.some(isNaN as any /* ts T_T*/);\n};\n\nexport const derivePath = (path: Path, seed: Hex, offset = HARDENED_OFFSET): Keys => {\n\tif (!isValidPath(path)) {\n\t\tthrow new Error('Invalid derivation path');\n\t}\n\n\tconst { key, chainCode } = getMasterKeyFromSeed(seed);\n\tconst segments = path\n\t\t.split('/')\n\t\t.slice(1)\n\t\t.map(replaceDerive)\n\t\t.map((el) => parseInt(el, 10));\n\n\treturn segments.reduce((parentKeys, segment) => CKDPriv(parentKeys, segment + offset), {\n\t\tkey,\n\t\tchainCode,\n\t});\n};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,iBAAwB;AACxB,kBAAqB;AACrB,oBAAuB;AACvB,uBAAiB;AAUjB,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AAEjB,MAAM,YAAY,IAAI,OAAO,kBAAkB;AAE/C,MAAM,gBAAgB,CAAC,QAAwB,IAAI,QAAQ,KAAK,EAAE;AAElE,MAAM,uBAAuB,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;AAC1B,WAAO;AAAA,EACR;AACA,SAAO,CAAC,KACN,MAAM,GAAG,EACT,MAAM,CAAC,EACP,IAAI,aAAa,EACjB;AAAA,IAAK;AAAA;AAAA,EAAwB;AAChC;AAEO,MAAM,aAAa,CAAC,MAAY,MAAW,SAAS,oBAA0B;AACpF,MAAI,CAAC,YAAY,IAAI,GAAG;AACvB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC1C;AAEA,QAAM,EAAE,KAAK,UAAU,IAAI,qBAAqB,IAAI;AACpD,QAAM,WAAW,KACf,MAAM,GAAG,EACT,MAAM,CAAC,EACP,IAAI,aAAa,EACjB,IAAI,CAAC,OAAO,SAAS,IAAI,EAAE,CAAC;AAE9B,SAAO,SAAS,OAAO,CAAC,YAAY,YAAY,QAAQ,YAAY,UAAU,MAAM,GAAG;AAAA,IACtF;AAAA,IACA;AAAA,EACD,CAAC;AACF;",
|
|
6
6
|
"names": ["nacl"]
|
|
7
7
|
}
|
|
@@ -38,10 +38,10 @@ export declare class Ed25519Keypair extends Keypair {
|
|
|
38
38
|
*
|
|
39
39
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
40
40
|
*
|
|
41
|
-
* @param secretKey secret key byte array
|
|
41
|
+
* @param secretKey secret key as a byte array or Bech32 secret key string
|
|
42
42
|
* @param options: skip secret key validation
|
|
43
43
|
*/
|
|
44
|
-
static fromSecretKey(secretKey: Uint8Array, options?: {
|
|
44
|
+
static fromSecretKey(secretKey: Uint8Array | string, options?: {
|
|
45
45
|
skipValidation?: boolean;
|
|
46
46
|
}): Ed25519Keypair;
|
|
47
47
|
/**
|
|
@@ -72,10 +72,17 @@ class Ed25519Keypair extends import_keypair.Keypair {
|
|
|
72
72
|
*
|
|
73
73
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
74
74
|
*
|
|
75
|
-
* @param secretKey secret key byte array
|
|
75
|
+
* @param secretKey secret key as a byte array or Bech32 secret key string
|
|
76
76
|
* @param options: skip secret key validation
|
|
77
77
|
*/
|
|
78
78
|
static fromSecretKey(secretKey, options) {
|
|
79
|
+
if (typeof secretKey === "string") {
|
|
80
|
+
const decoded = (0, import_keypair.decodeSuiPrivateKey)(secretKey);
|
|
81
|
+
if (decoded.schema !== "ED25519") {
|
|
82
|
+
throw new Error(`Expected a ED25519 keypair, got ${decoded.schema}`);
|
|
83
|
+
}
|
|
84
|
+
return this.fromSecretKey(decoded.secretKey, options);
|
|
85
|
+
}
|
|
79
86
|
const secretKeyLength = secretKey.length;
|
|
80
87
|
if (secretKeyLength !== import_keypair.PRIVATE_KEY_SIZE) {
|
|
81
88
|
throw new Error(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/ed25519/keypair.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport nacl from 'tweetnacl';\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAiB;AAEjB,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport nacl from 'tweetnacl';\n\nimport {\n\tdecodeSuiPrivateKey,\n\tencodeSuiPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport { isValidHardenedPath, mnemonicToSeedHex } from '../../cryptography/mnemonics.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { derivePath } from './ed25519-hd-key.js';\nimport { Ed25519PublicKey } from './publickey.js';\n\nexport const DEFAULT_ED25519_DERIVATION_PATH = \"m/44'/784'/0'/0'/0'\";\n\n/**\n * Ed25519 Keypair data. The publickey is the 32-byte public key and\n * the secretkey is 64-byte, where the first 32 bytes is the secret\n * key and the last 32 bytes is the public key.\n */\nexport interface Ed25519KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Ed25519 Keypair used for signing transactions.\n */\nexport class Ed25519Keypair extends Keypair {\n\tprivate keypair: Ed25519KeypairData;\n\n\t/**\n\t * Create a new Ed25519 keypair instance.\n\t * Generate random keypair if no {@link Ed25519Keypair} is provided.\n\t *\n\t * @param keypair Ed25519 keypair\n\t */\n\tconstructor(keypair?: Ed25519KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tthis.keypair = nacl.sign.keyPair();\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair ED25519\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'ED25519';\n\t}\n\n\t/**\n\t * Generate a new random Ed25519 keypair\n\t */\n\tstatic generate(): Ed25519Keypair {\n\t\treturn new Ed25519Keypair(nacl.sign.keyPair());\n\t}\n\n\t/**\n\t * Create a Ed25519 keypair from a raw secret key byte array, also known as seed.\n\t * This is NOT the private scalar which is result of hashing and bit clamping of\n\t * the raw secret key.\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 as a byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Ed25519Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'ED25519') {\n\t\t\t\tthrow new Error(`Expected a ED25519 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 secretKeyLength = secretKey.length;\n\t\tif (secretKeyLength !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKeyLength}.`,\n\t\t\t);\n\t\t}\n\t\tconst keypair = nacl.sign.keyPair.fromSeed(secretKey);\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 signature = nacl.sign.detached(signData, keypair.secretKey);\n\t\t\tif (!nacl.sign.detached.verify(signData, signature, keypair.publicKey)) {\n\t\t\t\tthrow new Error('provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Ed25519Keypair(keypair);\n\t}\n\n\t/**\n\t * The public key for this Ed25519 keypair\n\t */\n\tgetPublicKey(): Ed25519PublicKey {\n\t\treturn new Ed25519PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Ed25519 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(\n\t\t\tthis.keypair.secretKey.slice(0, PRIVATE_KEY_SIZE),\n\t\t\tthis.getKeyScheme(),\n\t\t);\n\t}\n\n\t/**\n\t * Return the signature for the provided data using Ed25519.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn nacl.sign.detached(data, this.keypair.secretKey);\n\t}\n\n\t/**\n\t * Derive Ed25519 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/44'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst { key } = derivePath(path, mnemonicToSeedHex(mnemonics));\n\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonicSeed and path.\n\t *\n\t * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t */\n\tstatic deriveKeypairFromSeed(seedHex: string, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst { key } = derivePath(path, seedHex);\n\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAiB;AAEjB,qBAKO;AACP,uBAAuD;AAEvD,4BAA2B;AAC3B,uBAAiC;AAE1B,MAAM,kCAAkC;AAexC,MAAM,uBAAuB,uBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS3C,YAAY,SAA8B;AACzC,UAAM;AACN,QAAI,SAAS;AACZ,WAAK,UAAU;AAAA,IAChB,OAAO;AACN,WAAK,UAAU,iBAAAA,QAAK,KAAK,QAAQ;AAAA,IAClC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,WAA2B;AACjC,WAAO,IAAI,eAAe,iBAAAA,QAAK,KAAK,QAAQ,CAAC;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,cACN,WACA,SACiB;AACjB,QAAI,OAAO,cAAc,UAAU;AAClC,YAAM,cAAU,oCAAoB,SAAS;AAE7C,UAAI,QAAQ,WAAW,WAAW;AACjC,cAAM,IAAI,MAAM,mCAAmC,QAAQ,MAAM,EAAE;AAAA,MACpE;AAEA,aA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,CAAC;AAE7D,WAAO,eAAe,cAAc,GAAG;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,sBAAsB,SAAiB,MAA+B;AAC5E,QAAI,QAAQ,MAAM;AACjB,aAAO;AAAA,IACR;AACA,QAAI,KAAC,sCAAoB,IAAI,GAAG;AAC/B,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC1C;AACA,UAAM,EAAE,IAAI,QAAI,kCAAW,MAAM,OAAO;AAExC,WAAO,eAAe,cAAc,GAAG;AAAA,EACxC;AACD;",
|
|
6
6
|
"names": ["nacl"]
|
|
7
7
|
}
|
|
@@ -45,7 +45,7 @@ class Ed25519PublicKey extends import_publickey.PublicKey {
|
|
|
45
45
|
constructor(value) {
|
|
46
46
|
super();
|
|
47
47
|
if (typeof value === "string") {
|
|
48
|
-
this.data = (0, import_bcs.
|
|
48
|
+
this.data = (0, import_bcs.fromBase64)(value);
|
|
49
49
|
} else if (value instanceof Uint8Array) {
|
|
50
50
|
this.data = value;
|
|
51
51
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/ed25519/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport nacl from 'tweetnacl';\n\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { bytesEqual, PublicKey } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../../cryptography/signature.js';\n\nconst PUBLIC_KEY_SIZE = 32;\n\n/**\n * An Ed25519 public key\n */\nexport class Ed25519PublicKey extends PublicKey {\n\tstatic SIZE = PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array;\n\n\t/**\n\t * Create a new Ed25519PublicKey object\n\t * @param value ed25519 public key as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.data = value;\n\t\t} else {\n\t\t\tthis.data = Uint8Array.from(value);\n\t\t}\n\n\t\tif (this.data.length !== PUBLIC_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid public key input. Expected ${PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two Ed25519 public keys are equal\n\t */\n\toverride equals(publicKey: Ed25519PublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the Ed25519 public key\n\t */\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this Ed25519 public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ED25519'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tlet bytes;\n\t\tif (typeof signature === 'string') {\n\t\t\tconst parsed = parseSerializedSignature(signature);\n\t\t\tif (parsed.signatureScheme !== 'ED25519') {\n\t\t\t\tthrow new Error('Invalid signature scheme');\n\t\t\t}\n\n\t\t\tif (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {\n\t\t\t\tthrow new Error('Signature does not match public key');\n\t\t\t}\n\n\t\t\tbytes = parsed.signature;\n\t\t} else {\n\t\t\tbytes = signature;\n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AAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO,iBAAAA,QAAK,KAAK,SAAS,OAAO,SAAS,OAAO,KAAK,WAAW,CAAC;AAAA,EACnE;AACD;AArEa,iBACL,OAAO;",
|
|
6
6
|
"names": ["nacl"]
|
|
7
7
|
}
|
|
@@ -38,10 +38,10 @@ export declare class Secp256k1Keypair extends Keypair {
|
|
|
38
38
|
*
|
|
39
39
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
40
40
|
*
|
|
41
|
-
* @param secretKey secret key byte array
|
|
41
|
+
* @param secretKey secret key byte array or Bech32 secret key string
|
|
42
42
|
* @param options: skip secret key validation
|
|
43
43
|
*/
|
|
44
|
-
static fromSecretKey(secretKey: Uint8Array, options?: {
|
|
44
|
+
static fromSecretKey(secretKey: Uint8Array | string, options?: {
|
|
45
45
|
skipValidation?: boolean;
|
|
46
46
|
}): Secp256k1Keypair;
|
|
47
47
|
/**
|
|
@@ -69,10 +69,17 @@ class Secp256k1Keypair extends import_keypair.Keypair {
|
|
|
69
69
|
*
|
|
70
70
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
71
71
|
*
|
|
72
|
-
* @param secretKey secret key byte array
|
|
72
|
+
* @param secretKey secret key byte array or Bech32 secret key string
|
|
73
73
|
* @param options: skip secret key validation
|
|
74
74
|
*/
|
|
75
75
|
static fromSecretKey(secretKey, options) {
|
|
76
|
+
if (typeof secretKey === "string") {
|
|
77
|
+
const decoded = (0, import_keypair.decodeSuiPrivateKey)(secretKey);
|
|
78
|
+
if (decoded.schema !== "Secp256k1") {
|
|
79
|
+
throw new Error(`Expected a Secp256k1 keypair, got ${decoded.schema}`);
|
|
80
|
+
}
|
|
81
|
+
return this.fromSecretKey(decoded.secretKey, options);
|
|
82
|
+
}
|
|
76
83
|
const publicKey = import_secp256k1.secp256k1.getPublicKey(secretKey, true);
|
|
77
84
|
if (!options || !options.skipValidation) {
|
|
78
85
|
const encoder = new TextEncoder();
|
|
@@ -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 { 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\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256k1Keypair {\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\tlet 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA0B;AAC1B,qBAAwB;AACxB,oBAAuB;AACvB,mBAA2B;AAC3B,mBAAsB;AAEtB,
|
|
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\tlet 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA0B;AAC1B,qBAAwB;AACxB,oBAAuB;AACvB,mBAA2B;AAC3B,mBAAsB;AAEtB,qBAAkE;AAClE,uBAAiD;AAGjD,uBAAmC;AAE5B,MAAM,oCAAoC;AAa1C,MAAM,yBAAyB,uBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,SAAgC;AAC3C,UAAM;AACN,QAAI,SAAS;AACZ,WAAK,UAAU;AAAA,IAChB,OAAO;AACN,YAAM,YAAwB,2BAAU,MAAM,iBAAiB;AAC/D,YAAM,YAAwB,2BAAU,aAAa,WAAW,IAAI;AAEpE,WAAK,UAAU,EAAE,WAAW,UAAU;AAAA,IACvC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,WAA6B;AACnC,WAAO,IAAI,iBAAiB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,cACN,WACA,SACmB;AACnB,QAAI,OAAO,cAAc,UAAU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;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,cAAc,WAAmB,MAAiC;AACxE,QAAI,QAAQ,MAAM;AACjB,aAAO;AAAA,IACR;AACA,QAAI,KAAC,mCAAiB,IAAI,GAAG;AAC5B,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC1C;AACA,UAAM,MAAM,mBAAM,mBAAe,iCAAe,SAAS,CAAC,EAAE,OAAO,IAAI;AACvE,QAAI,IAAI,aAAa,QAAQ,IAAI,cAAc,MAAM;AACpD,YAAM,IAAI,MAAM,aAAa;AAAA,IAC9B;AACA,WAAO,IAAI,iBAAiB;AAAA,MAC3B,WAAW,IAAI;AAAA,MACf,WAAW,IAAI;AAAA,IAChB,CAAC;AAAA,EACF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -36,7 +36,7 @@ class Secp256k1PublicKey extends import_publickey.PublicKey {
|
|
|
36
36
|
constructor(value) {
|
|
37
37
|
super();
|
|
38
38
|
if (typeof value === "string") {
|
|
39
|
-
this.data = (0, import_bcs.
|
|
39
|
+
this.data = (0, import_bcs.fromBase64)(value);
|
|
40
40
|
} else if (value instanceof Uint8Array) {
|
|
41
41
|
this.data = value;
|
|
42
42
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256k1/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { bytesEqual, PublicKey } from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../../cryptography/signature.js';\n\nconst SECP256K1_PUBLIC_KEY_SIZE = 33;\n\n/**\n * A Secp256k1 public key\n */\nexport class Secp256k1PublicKey extends PublicKey {\n\tstatic SIZE = SECP256K1_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array;\n\n\t/**\n\t * Create a new Secp256k1PublicKey object\n\t * @param value secp256k1 public key as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.data = value;\n\t\t} else {\n\t\t\tthis.data = Uint8Array.from(value);\n\t\t}\n\n\t\tif (this.data.length !== SECP256K1_PUBLIC_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid public key input. Expected ${SECP256K1_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two Secp256k1 public keys are equal\n\t */\n\toverride equals(publicKey: Secp256k1PublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the Secp256k1 public key\n\t */\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this Secp256k1 public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['Secp256k1'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tlet bytes;\n\t\tif (typeof signature === 'string') {\n\t\t\tconst parsed = parseSerializedSignature(signature);\n\t\t\tif (parsed.signatureScheme !== 'Secp256k1') {\n\t\t\t\tthrow new Error('Invalid signature scheme');\n\t\t\t}\n\n\t\t\tif (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {\n\t\t\t\tthrow new Error('Signature does not match public key');\n\t\t\t}\n\n\t\t\tbytes = parsed.signature;\n\t\t} else {\n\t\t\tbytes = signature;\n\t\t}\n\n\t\treturn secp256k1.verify(\n\t\t\tsecp256k1.Signature.fromCompact(bytes),\n\t\t\tsha256(message),\n\t\t\tthis.toRawBytes(),\n\t\t);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA2B;AAC3B,uBAA0B;AAC1B,oBAAuB;AAEvB,uBAAsC;AAEtC,8BAAyC;AACzC,uBAAyC;AAEzC,MAAM,4BAA4B;AAK3B,MAAM,2BAA2B,2BAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjD,YAAY,OAA0B;AACrC,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,WAAO,uBAAW,KAAK;AAAA,IAC7B,WAAW,iBAAiB,YAAY;AACvC,WAAK,OAAO;AAAA,IACb,OAAO;AACN,WAAK,OAAO,WAAW,KAAK,KAAK;AAAA,IAClC;AAEA,QAAI,KAAK,KAAK,WAAW,2BAA2B;AACnD,YAAM,IAAI;AAAA,QACT,sCAAsC,yBAAyB,eAAe,KAAK,KAAK,MAAM;AAAA,MAC/F;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKS,OAAO,WAAwC;AACvD,WAAO,MAAM,OAAO,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,aAAyB;AACxB,WAAO,KAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe;AACd,WAAO,iDAAyB,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,SAAqB,WAAkD;AACnF,QAAI;AACJ,QAAI,OAAO,cAAc,UAAU;AAClC,YAAM,aAAS,2CAAyB,SAAS;AACjD,UAAI,OAAO,oBAAoB,aAAa;AAC3C,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC3C;AAEA,UAAI,KAAC,6BAAW,KAAK,WAAW,GAAG,OAAO,SAAS,GAAG;AACrD,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACtD;AAEA,cAAQ,OAAO;AAAA,IAChB,OAAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO,2BAAU;AAAA,MAChB,2BAAU,UAAU,YAAY,KAAK;AAAA,UACrC,sBAAO,OAAO;AAAA,MACd,KAAK,WAAW;AAAA,IACjB;AAAA,EACD;AACD;AAzEa,mBACL,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -38,10 +38,10 @@ export declare class Secp256r1Keypair extends Keypair {
|
|
|
38
38
|
*
|
|
39
39
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
40
40
|
*
|
|
41
|
-
* @param secretKey secret key byte array
|
|
41
|
+
* @param secretKey secret key byte array or Bech32 secret key string
|
|
42
42
|
* @param options: skip secret key validation
|
|
43
43
|
*/
|
|
44
|
-
static fromSecretKey(secretKey: Uint8Array, options?: {
|
|
44
|
+
static fromSecretKey(secretKey: Uint8Array | string, options?: {
|
|
45
45
|
skipValidation?: boolean;
|
|
46
46
|
}): Secp256r1Keypair;
|
|
47
47
|
/**
|
|
@@ -69,10 +69,17 @@ class Secp256r1Keypair extends import_keypair.Keypair {
|
|
|
69
69
|
*
|
|
70
70
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
71
71
|
*
|
|
72
|
-
* @param secretKey secret key byte array
|
|
72
|
+
* @param secretKey secret key byte array or Bech32 secret key string
|
|
73
73
|
* @param options: skip secret key validation
|
|
74
74
|
*/
|
|
75
75
|
static fromSecretKey(secretKey, options) {
|
|
76
|
+
if (typeof secretKey === "string") {
|
|
77
|
+
const decoded = (0, import_keypair.decodeSuiPrivateKey)(secretKey);
|
|
78
|
+
if (decoded.schema !== "Secp256r1") {
|
|
79
|
+
throw new Error(`Expected a Secp256r1 keypair, got ${decoded.schema}`);
|
|
80
|
+
}
|
|
81
|
+
return this.fromSecretKey(decoded.secretKey, options);
|
|
82
|
+
}
|
|
76
83
|
const publicKey = import_p256.secp256r1.getPublicKey(secretKey, true);
|
|
77
84
|
if (!options || !options.skipValidation) {
|
|
78
85
|
const encoder = new TextEncoder();
|
|
@@ -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 { 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\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256r1Keypair {\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\tlet 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,qBAAwB;AACxB,oBAAuB;AACvB,mBAA2B;AAC3B,mBAAsB;AAEtB,
|
|
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\tlet 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,qBAAwB;AACxB,oBAAuB;AACvB,mBAA2B;AAC3B,mBAAsB;AAEtB,qBAAkE;AAClE,uBAAiD;AAGjD,uBAAmC;AAE5B,MAAM,oCAAoC;AAa1C,MAAM,yBAAyB,uBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,SAAgC;AAC3C,UAAM;AACN,QAAI,SAAS;AACZ,WAAK,UAAU;AAAA,IAChB,OAAO;AACN,YAAM,YAAwB,sBAAU,MAAM,iBAAiB;AAC/D,YAAM,YAAwB,sBAAU,aAAa,WAAW,IAAI;AAEpE,WAAK,UAAU,EAAE,WAAW,UAAU;AAAA,IACvC;AAAA,EACD;AAAA;AAAA;AAAA;A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,EAKA,eAAuB;AACtB,eAAO,oCAAoB,KAAK,QAAQ,WAAW,KAAK,aAAa,CAAC;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,MAAkB;AAC5B,UAAM,cAAU,sBAAO,IAAI;AAC3B,UAAM,MAAM,sBAAU,KAAK,SAAS,KAAK,QAAQ,WAAW;AAAA,MAC3D,MAAM;AAAA,IACP,CAAC;AACD,WAAO,IAAI,kBAAkB;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,cAAc,WAAmB,MAAiC;AACxE,QAAI,QAAQ,MAAM;AACjB,aAAO;AAAA,IACR;AACA,QAAI,KAAC,mCAAiB,IAAI,GAAG;AAC5B,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC1C;AAEA,UAAM,aAAa,mBAAM,mBAAe,iCAAe,SAAS,CAAC,EAAE,OAAO,IAAI,EAAE;AAChF,WAAO,iBAAiB,cAAc,UAAW;AAAA,EAClD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -36,7 +36,7 @@ class Secp256r1PublicKey extends import_publickey.PublicKey {
|
|
|
36
36
|
constructor(value) {
|
|
37
37
|
super();
|
|
38
38
|
if (typeof value === "string") {
|
|
39
|
-
this.data = (0, import_bcs.
|
|
39
|
+
this.data = (0, import_bcs.fromBase64)(value);
|
|
40
40
|
} else if (value instanceof Uint8Array) {
|
|
41
41
|
this.data = value;
|
|
42
42
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256r1/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { secp256r1 } from '@noble/curves/p256';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { bytesEqual, PublicKey } from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../../cryptography/signature.js';\n\nconst SECP256R1_PUBLIC_KEY_SIZE = 33;\n\n/**\n * A Secp256r1 public key\n */\nexport class Secp256r1PublicKey extends PublicKey {\n\tstatic SIZE = SECP256R1_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array;\n\n\t/**\n\t * Create a new Secp256r1PublicKey object\n\t * @param value secp256r1 public key as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.data = value;\n\t\t} else {\n\t\t\tthis.data = Uint8Array.from(value);\n\t\t}\n\n\t\tif (this.data.length !== SECP256R1_PUBLIC_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid public key input. Expected ${SECP256R1_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two Secp256r1 public keys are equal\n\t */\n\toverride equals(publicKey: Secp256r1PublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the Secp256r1 public key\n\t */\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this Secp256r1 public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['Secp256r1'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tlet bytes;\n\t\tif (typeof signature === 'string') {\n\t\t\tconst parsed = parseSerializedSignature(signature);\n\t\t\tif (parsed.signatureScheme !== 'Secp256r1') {\n\t\t\t\tthrow new Error('Invalid signature scheme');\n\t\t\t}\n\n\t\t\tif (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {\n\t\t\t\tthrow new Error('Signature does not match public key');\n\t\t\t}\n\n\t\t\tbytes = parsed.signature;\n\t\t} else {\n\t\t\tbytes = signature;\n\t\t}\n\n\t\treturn secp256r1.verify(\n\t\t\tsecp256r1.Signature.fromCompact(bytes),\n\t\t\tsha256(message),\n\t\t\tthis.toRawBytes(),\n\t\t);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA2B;AAC3B,kBAA0B;AAC1B,oBAAuB;AAEvB,uBAAsC;AAEtC,8BAAyC;AACzC,uBAAyC;AAEzC,MAAM,4BAA4B;AAK3B,MAAM,2BAA2B,2BAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjD,YAAY,OAA0B;AACrC,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,WAAO,uBAAW,KAAK;AAAA,IAC7B,WAAW,iBAAiB,YAAY;AACvC,WAAK,OAAO;AAAA,IACb,OAAO;AACN,WAAK,OAAO,WAAW,KAAK,KAAK;AAAA,IAClC;AAEA,QAAI,KAAK,KAAK,WAAW,2BAA2B;AACnD,YAAM,IAAI;AAAA,QACT,sCAAsC,yBAAyB,eAAe,KAAK,KAAK,MAAM;AAAA,MAC/F;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKS,OAAO,WAAwC;AACvD,WAAO,MAAM,OAAO,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,aAAyB;AACxB,WAAO,KAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe;AACd,WAAO,iDAAyB,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,SAAqB,WAAkD;AACnF,QAAI;AACJ,QAAI,OAAO,cAAc,UAAU;AAClC,YAAM,aAAS,2CAAyB,SAAS;AACjD,UAAI,OAAO,oBAAoB,aAAa;AAC3C,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC3C;AAEA,UAAI,KAAC,6BAAW,KAAK,WAAW,GAAG,OAAO,SAAS,GAAG;AACrD,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACtD;AAEA,cAAQ,OAAO;AAAA,IAChB,OAAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO,sBAAU;AAAA,MAChB,sBAAU,UAAU,YAAY,KAAK;AAAA,UACrC,sBAAO,OAAO;AAAA,MACd,KAAK,WAAW;AAAA,IACjB;AAAA,EACD;AACD;AAzEa,mBACL,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -44,7 +44,7 @@ class MultiSigPublicKey extends import_publickey.PublicKey {
|
|
|
44
44
|
constructor(value, options = {}) {
|
|
45
45
|
super();
|
|
46
46
|
if (typeof value === "string") {
|
|
47
|
-
this.rawBytes = (0, import_bcs.
|
|
47
|
+
this.rawBytes = (0, import_bcs.fromBase64)(value);
|
|
48
48
|
this.multisigPublicKey = import_bcs2.bcs.MultiSigPublicKey.parse(this.rawBytes);
|
|
49
49
|
} else if (value instanceof Uint8Array) {
|
|
50
50
|
this.rawBytes = value;
|
|
@@ -220,7 +220,7 @@ class MultiSigPublicKey extends import_publickey.PublicKey {
|
|
|
220
220
|
let tmp = new Uint8Array(bytes.length + 1);
|
|
221
221
|
tmp.set([import_signature_scheme.SIGNATURE_SCHEME_TO_FLAG["MultiSig"]]);
|
|
222
222
|
tmp.set(bytes, 1);
|
|
223
|
-
return (0, import_bcs.
|
|
223
|
+
return (0, import_bcs.toBase64)(tmp);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
function parsePartialSignatures(multisig, options = {}) {
|