@mysten/sui 1.15.0 → 1.16.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 +40 -0
- package/dist/cjs/bcs/index.d.ts +1 -1
- 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/address.d.ts +16 -1
- package/dist/cjs/zklogin/address.js +55 -3
- package/dist/cjs/zklogin/address.js.map +2 -2
- package/dist/cjs/zklogin/index.d.ts +5 -2
- package/dist/cjs/zklogin/index.js +10 -0
- package/dist/cjs/zklogin/index.js.map +2 -2
- package/dist/cjs/zklogin/nonce.d.ts +4 -0
- package/dist/cjs/zklogin/nonce.js +54 -0
- package/dist/cjs/zklogin/nonce.js.map +7 -0
- package/dist/cjs/zklogin/poseidon.d.ts +2 -0
- package/dist/cjs/zklogin/poseidon.js +63 -0
- package/dist/cjs/zklogin/poseidon.js.map +7 -0
- package/dist/cjs/zklogin/publickey.d.ts +2 -0
- package/dist/cjs/zklogin/publickey.js +33 -3
- package/dist/cjs/zklogin/publickey.js.map +3 -3
- package/dist/cjs/zklogin/utils.d.ts +13 -0
- package/dist/cjs/zklogin/utils.js +44 -0
- package/dist/cjs/zklogin/utils.js.map +2 -2
- package/dist/esm/bcs/index.d.ts +1 -1
- 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/address.d.ts +16 -1
- package/dist/esm/zklogin/address.js +56 -4
- package/dist/esm/zklogin/address.js.map +2 -2
- package/dist/esm/zklogin/index.d.ts +5 -2
- package/dist/esm/zklogin/index.js +18 -2
- package/dist/esm/zklogin/index.js.map +2 -2
- package/dist/esm/zklogin/nonce.d.ts +4 -0
- package/dist/esm/zklogin/nonce.js +34 -0
- package/dist/esm/zklogin/nonce.js.map +7 -0
- package/dist/esm/zklogin/poseidon.d.ts +2 -0
- package/dist/esm/zklogin/poseidon.js +60 -0
- package/dist/esm/zklogin/poseidon.js.map +7 -0
- package/dist/esm/zklogin/publickey.d.ts +2 -0
- package/dist/esm/zklogin/publickey.js +34 -4
- package/dist/esm/zklogin/publickey.js.map +2 -2
- package/dist/esm/zklogin/utils.d.ts +13 -0
- package/dist/esm/zklogin/utils.js +44 -0
- package/dist/esm/zklogin/utils.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/src/version.ts +1 -1
- package/src/zklogin/address.ts +81 -3
- package/src/zklogin/index.ts +11 -2
- package/src/zklogin/nonce.ts +38 -0
- package/src/zklogin/poseidon.ts +64 -0
- package/src/zklogin/publickey.ts +42 -4
- package/src/zklogin/utils.ts +72 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @mysten/sui.js
|
|
2
2
|
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ec2dc7f: Add legacyAddress flag to zklogin methods that generate addresses
|
|
8
|
+
- ec2dc7f: All functionality from `@mysten/zklogin` has been moved to `@mysten/sui/zklogin`
|
|
9
|
+
|
|
10
|
+
For most methods, simply replace the `@mysten/zklogin` import with `@mysten/sui/zklogin`
|
|
11
|
+
|
|
12
|
+
2 Methods require one small additional change:
|
|
13
|
+
|
|
14
|
+
`computeZkLoginAddress` and `jwtToAddress` have new `legacyAddress` flags which must be set to
|
|
15
|
+
true for backwards compatibility:
|
|
16
|
+
|
|
17
|
+
```diff
|
|
18
|
+
- import { computeZkLoginAddress, jwtToAddress } from '@mysten/zklogin';
|
|
19
|
+
+ import { computeZkLoginAddress, jwtToAddress } from '@mysten/sui/zklogin';
|
|
20
|
+
|
|
21
|
+
const address = jwtToAddress(
|
|
22
|
+
jwtAsString,
|
|
23
|
+
salt,
|
|
24
|
+
+ true
|
|
25
|
+
);
|
|
26
|
+
const address = computeZkLoginAddress({
|
|
27
|
+
claimName,
|
|
28
|
+
claimValue,
|
|
29
|
+
iss,
|
|
30
|
+
aud,
|
|
31
|
+
userSalt: BigInt(salt),
|
|
32
|
+
+ legacyAddress: true,
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 1.15.1
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [1dd7713]
|
|
41
|
+
- @mysten/bcs@1.1.1
|
|
42
|
+
|
|
3
43
|
## 1.15.0
|
|
4
44
|
|
|
5
45
|
### Minor Changes
|
package/dist/cjs/bcs/index.d.ts
CHANGED
|
@@ -3111,7 +3111,7 @@ declare const suiBcs: {
|
|
|
3111
3111
|
u256(options?: import("@mysten/bcs").BcsTypeOptions<string, number | bigint | string>): import("@mysten/bcs").BcsType<string, string | number | bigint>;
|
|
3112
3112
|
bool(options?: import("@mysten/bcs").BcsTypeOptions<boolean>): import("@mysten/bcs").BcsType<boolean, boolean>;
|
|
3113
3113
|
uleb128(options?: import("@mysten/bcs").BcsTypeOptions<number>): import("@mysten/bcs").BcsType<number, number>;
|
|
3114
|
-
bytes<T extends number>(size: T, options?: import("@mysten/bcs").BcsTypeOptions<Uint8Array, Iterable<number>>): import("@mysten/bcs").BcsType<Uint8Array,
|
|
3114
|
+
bytes<T extends number>(size: T, options?: import("@mysten/bcs").BcsTypeOptions<Uint8Array, Iterable<number>>): import("@mysten/bcs").BcsType<Uint8Array, Iterable<number>>;
|
|
3115
3115
|
string(options?: import("@mysten/bcs").BcsTypeOptions<string>): import("@mysten/bcs").BcsType<string, string>;
|
|
3116
3116
|
fixedArray<T, Input>(size: number, type: import("@mysten/bcs").BcsType<T, Input>, options?: import("@mysten/bcs").BcsTypeOptions<T[], Iterable<Input> & {
|
|
3117
3117
|
length: number;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "1.
|
|
1
|
+
export declare const PACKAGE_VERSION = "1.16.0";
|
|
2
2
|
export declare const TARGETED_RPC_VERSION = "1.39.0";
|
package/dist/cjs/version.js
CHANGED
|
@@ -22,6 +22,6 @@ __export(version_exports, {
|
|
|
22
22
|
TARGETED_RPC_VERSION: () => TARGETED_RPC_VERSION
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const PACKAGE_VERSION = "1.
|
|
25
|
+
const PACKAGE_VERSION = "1.16.0";
|
|
26
26
|
const TARGETED_RPC_VERSION = "1.39.0";
|
|
27
27
|
//# sourceMappingURL=version.js.map
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.16.0';\nexport const TARGETED_RPC_VERSION = '1.39.0';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
export declare function computeZkLoginAddressFromSeed(addressSeed: bigint, iss: string
|
|
1
|
+
export declare function computeZkLoginAddressFromSeed(addressSeed: bigint, iss: string,
|
|
2
|
+
/** TODO: This default should be changed in the next major release */
|
|
3
|
+
legacyAddress?: boolean): string;
|
|
4
|
+
export declare const MAX_HEADER_LEN_B64 = 248;
|
|
5
|
+
export declare const MAX_PADDED_UNSIGNED_JWT_LEN: number;
|
|
6
|
+
export declare function lengthChecks(jwt: string): void;
|
|
7
|
+
export declare function jwtToAddress(jwt: string, userSalt: string | bigint, legacyAddress?: boolean): string;
|
|
8
|
+
export interface ComputeZkLoginAddressOptions {
|
|
9
|
+
claimName: string;
|
|
10
|
+
claimValue: string;
|
|
11
|
+
userSalt: string | bigint;
|
|
12
|
+
iss: string;
|
|
13
|
+
aud: string;
|
|
14
|
+
legacyAddress?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function computeZkLoginAddress({ claimName, claimValue, iss, aud, userSalt, legacyAddress, }: ComputeZkLoginAddressOptions): string;
|
|
@@ -18,16 +18,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var address_exports = {};
|
|
20
20
|
__export(address_exports, {
|
|
21
|
-
|
|
21
|
+
MAX_HEADER_LEN_B64: () => MAX_HEADER_LEN_B64,
|
|
22
|
+
MAX_PADDED_UNSIGNED_JWT_LEN: () => MAX_PADDED_UNSIGNED_JWT_LEN,
|
|
23
|
+
computeZkLoginAddress: () => computeZkLoginAddress,
|
|
24
|
+
computeZkLoginAddressFromSeed: () => computeZkLoginAddressFromSeed,
|
|
25
|
+
jwtToAddress: () => jwtToAddress,
|
|
26
|
+
lengthChecks: () => lengthChecks
|
|
22
27
|
});
|
|
23
28
|
module.exports = __toCommonJS(address_exports);
|
|
24
29
|
var import_blake2b = require("@noble/hashes/blake2b");
|
|
25
30
|
var import_utils = require("@noble/hashes/utils");
|
|
31
|
+
var import_jose = require("jose");
|
|
26
32
|
var import_signature_scheme = require("../cryptography/signature-scheme.js");
|
|
27
33
|
var import_utils2 = require("../utils/index.js");
|
|
28
34
|
var import_utils3 = require("./utils.js");
|
|
29
|
-
function computeZkLoginAddressFromSeed(addressSeed, iss) {
|
|
30
|
-
const addressSeedBytesBigEndian = (0, import_utils3.toBigEndianBytes)(addressSeed, 32);
|
|
35
|
+
function computeZkLoginAddressFromSeed(addressSeed, iss, legacyAddress = true) {
|
|
36
|
+
const addressSeedBytesBigEndian = legacyAddress ? (0, import_utils3.toBigEndianBytes)(addressSeed, 32) : (0, import_utils3.toPaddedBigEndianBytes)(addressSeed, 32);
|
|
31
37
|
if (iss === "accounts.google.com") {
|
|
32
38
|
iss = "https://accounts.google.com";
|
|
33
39
|
}
|
|
@@ -41,4 +47,50 @@ function computeZkLoginAddressFromSeed(addressSeed, iss) {
|
|
|
41
47
|
(0, import_utils.bytesToHex)((0, import_blake2b.blake2b)(tmp, { dkLen: 32 })).slice(0, import_utils2.SUI_ADDRESS_LENGTH * 2)
|
|
42
48
|
);
|
|
43
49
|
}
|
|
50
|
+
const MAX_HEADER_LEN_B64 = 248;
|
|
51
|
+
const MAX_PADDED_UNSIGNED_JWT_LEN = 64 * 25;
|
|
52
|
+
function lengthChecks(jwt) {
|
|
53
|
+
const [header, payload] = jwt.split(".");
|
|
54
|
+
if (header.length > MAX_HEADER_LEN_B64) {
|
|
55
|
+
throw new Error(`Header is too long`);
|
|
56
|
+
}
|
|
57
|
+
const L = (header.length + 1 + payload.length) * 8;
|
|
58
|
+
const K = (512 + 448 - (L % 512 + 1)) % 512;
|
|
59
|
+
const padded_unsigned_jwt_len = (L + 1 + K + 64) / 8;
|
|
60
|
+
if (padded_unsigned_jwt_len > MAX_PADDED_UNSIGNED_JWT_LEN) {
|
|
61
|
+
throw new Error(`JWT is too long`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function jwtToAddress(jwt, userSalt, legacyAddress = false) {
|
|
65
|
+
lengthChecks(jwt);
|
|
66
|
+
const decodedJWT = (0, import_jose.decodeJwt)(jwt);
|
|
67
|
+
if (!decodedJWT.sub || !decodedJWT.iss || !decodedJWT.aud) {
|
|
68
|
+
throw new Error("Missing jwt data");
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(decodedJWT.aud)) {
|
|
71
|
+
throw new Error("Not supported aud. Aud is an array, string was expected.");
|
|
72
|
+
}
|
|
73
|
+
return computeZkLoginAddress({
|
|
74
|
+
userSalt,
|
|
75
|
+
claimName: "sub",
|
|
76
|
+
claimValue: decodedJWT.sub,
|
|
77
|
+
aud: decodedJWT.aud,
|
|
78
|
+
iss: decodedJWT.iss,
|
|
79
|
+
legacyAddress
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function computeZkLoginAddress({
|
|
83
|
+
claimName,
|
|
84
|
+
claimValue,
|
|
85
|
+
iss,
|
|
86
|
+
aud,
|
|
87
|
+
userSalt,
|
|
88
|
+
legacyAddress = false
|
|
89
|
+
}) {
|
|
90
|
+
return computeZkLoginAddressFromSeed(
|
|
91
|
+
(0, import_utils3.genAddressSeed)(userSalt, claimName, claimValue, aud),
|
|
92
|
+
iss,
|
|
93
|
+
legacyAddress
|
|
94
|
+
);
|
|
95
|
+
}
|
|
44
96
|
//# sourceMappingURL=address.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/zklogin/address.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\n\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/index.js';\nimport { toBigEndianBytes } from './utils.js';\n\nexport function computeZkLoginAddressFromSeed(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AACxB,mBAA2B;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { decodeJwt } from 'jose';\n\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/index.js';\nimport { genAddressSeed, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\n\nexport function computeZkLoginAddressFromSeed(\n\taddressSeed: bigint,\n\tiss: string,\n\t/** TODO: This default should be changed in the next major release */\n\tlegacyAddress = true,\n) {\n\tconst addressSeedBytesBigEndian = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tif (iss === 'accounts.google.com') {\n\t\tiss = 'https://accounts.google.com';\n\t}\n\tconst addressParamBytes = new TextEncoder().encode(iss);\n\tconst tmp = new Uint8Array(2 + addressSeedBytesBigEndian.length + addressParamBytes.length);\n\n\ttmp.set([SIGNATURE_SCHEME_TO_FLAG.ZkLogin]);\n\ttmp.set([addressParamBytes.length], 1);\n\ttmp.set(addressParamBytes, 2);\n\ttmp.set(addressSeedBytesBigEndian, 2 + addressParamBytes.length);\n\n\treturn normalizeSuiAddress(\n\t\tbytesToHex(blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),\n\t);\n}\n\nexport const MAX_HEADER_LEN_B64 = 248;\nexport const MAX_PADDED_UNSIGNED_JWT_LEN = 64 * 25;\n\nexport function lengthChecks(jwt: string) {\n\tconst [header, payload] = jwt.split('.');\n\t/// Is the header small enough\n\tif (header.length > MAX_HEADER_LEN_B64) {\n\t\tthrow new Error(`Header is too long`);\n\t}\n\n\t/// Is the combined length of (header, payload, SHA2 padding) small enough?\n\t// unsigned_jwt = header + '.' + payload;\n\tconst L = (header.length + 1 + payload.length) * 8;\n\tconst K = (512 + 448 - ((L % 512) + 1)) % 512;\n\n\t// The SHA2 padding is 1 followed by K zeros, followed by the length of the message\n\tconst padded_unsigned_jwt_len = (L + 1 + K + 64) / 8;\n\n\t// The padded unsigned JWT must be less than the max_padded_unsigned_jwt_len\n\tif (padded_unsigned_jwt_len > MAX_PADDED_UNSIGNED_JWT_LEN) {\n\t\tthrow new Error(`JWT is too long`);\n\t}\n}\n\nexport function jwtToAddress(jwt: string, userSalt: string | bigint, legacyAddress = false) {\n\tlengthChecks(jwt);\n\n\tconst decodedJWT = decodeJwt(jwt);\n\tif (!decodedJWT.sub || !decodedJWT.iss || !decodedJWT.aud) {\n\t\tthrow new Error('Missing jwt data');\n\t}\n\n\tif (Array.isArray(decodedJWT.aud)) {\n\t\tthrow new Error('Not supported aud. Aud is an array, string was expected.');\n\t}\n\n\treturn computeZkLoginAddress({\n\t\tuserSalt,\n\t\tclaimName: 'sub',\n\t\tclaimValue: decodedJWT.sub,\n\t\taud: decodedJWT.aud,\n\t\tiss: decodedJWT.iss,\n\t\tlegacyAddress,\n\t});\n}\n\nexport interface ComputeZkLoginAddressOptions {\n\tclaimName: string;\n\tclaimValue: string;\n\tuserSalt: string | bigint;\n\tiss: string;\n\taud: string;\n\tlegacyAddress?: boolean;\n}\n\nexport function computeZkLoginAddress({\n\tclaimName,\n\tclaimValue,\n\tiss,\n\taud,\n\tuserSalt,\n\tlegacyAddress = false,\n}: ComputeZkLoginAddressOptions) {\n\treturn computeZkLoginAddressFromSeed(\n\t\tgenAddressSeed(userSalt, claimName, claimValue, aud),\n\t\tiss,\n\t\tlegacyAddress,\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AACxB,mBAA2B;AAC3B,kBAA0B;AAE1B,8BAAyC;AACzC,IAAAA,gBAAwD;AACxD,IAAAA,gBAAyE;AAElE,SAAS,8BACf,aACA,KAEA,gBAAgB,MACf;AACD,QAAM,4BAA4B,oBAC/B,gCAAiB,aAAa,EAAE,QAChC,sCAAuB,aAAa,EAAE;AACzC,MAAI,QAAQ,uBAAuB;AAClC,UAAM;AAAA,EACP;AACA,QAAM,oBAAoB,IAAI,YAAY,EAAE,OAAO,GAAG;AACtD,QAAM,MAAM,IAAI,WAAW,IAAI,0BAA0B,SAAS,kBAAkB,MAAM;AAE1F,MAAI,IAAI,CAAC,iDAAyB,OAAO,CAAC;AAC1C,MAAI,IAAI,CAAC,kBAAkB,MAAM,GAAG,CAAC;AACrC,MAAI,IAAI,mBAAmB,CAAC;AAC5B,MAAI,IAAI,2BAA2B,IAAI,kBAAkB,MAAM;AAE/D,aAAO;AAAA,QACN,6BAAW,wBAAQ,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,mCAAqB,CAAC;AAAA,EACxE;AACD;AAEO,MAAM,qBAAqB;AAC3B,MAAM,8BAA8B,KAAK;AAEzC,SAAS,aAAa,KAAa;AACzC,QAAM,CAAC,QAAQ,OAAO,IAAI,IAAI,MAAM,GAAG;AAEvC,MAAI,OAAO,SAAS,oBAAoB;AACvC,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AAIA,QAAM,KAAK,OAAO,SAAS,IAAI,QAAQ,UAAU;AACjD,QAAM,KAAK,MAAM,OAAQ,IAAI,MAAO,MAAM;AAG1C,QAAM,2BAA2B,IAAI,IAAI,IAAI,MAAM;AAGnD,MAAI,0BAA0B,6BAA6B;AAC1D,UAAM,IAAI,MAAM,iBAAiB;AAAA,EAClC;AACD;AAEO,SAAS,aAAa,KAAa,UAA2B,gBAAgB,OAAO;AAC3F,eAAa,GAAG;AAEhB,QAAM,iBAAa,uBAAU,GAAG;AAChC,MAAI,CAAC,WAAW,OAAO,CAAC,WAAW,OAAO,CAAC,WAAW,KAAK;AAC1D,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACnC;AAEA,MAAI,MAAM,QAAQ,WAAW,GAAG,GAAG;AAClC,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC3E;AAEA,SAAO,sBAAsB;AAAA,IAC5B;AAAA,IACA,WAAW;AAAA,IACX,YAAY,WAAW;AAAA,IACvB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AAAA,IAChB;AAAA,EACD,CAAC;AACF;AAWO,SAAS,sBAAsB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AACjB,GAAiC;AAChC,SAAO;AAAA,QACN,8BAAe,UAAU,WAAW,YAAY,GAAG;AAAA,IACnD;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { getZkLoginSignature, parseZkLoginSignature } from './signature.js';
|
|
2
|
-
export { toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';
|
|
3
|
-
export { computeZkLoginAddressFromSeed } from './address.js';
|
|
2
|
+
export { toBigEndianBytes, toPaddedBigEndianBytes, hashASCIIStrToField, genAddressSeed, getExtendedEphemeralPublicKey, } from './utils.js';
|
|
3
|
+
export { computeZkLoginAddressFromSeed, computeZkLoginAddress, jwtToAddress } from './address.js';
|
|
4
|
+
export type { ComputeZkLoginAddressOptions } from './address.js';
|
|
4
5
|
export { toZkLoginPublicIdentifier, ZkLoginPublicIdentifier } from './publickey.js';
|
|
5
6
|
export type { ZkLoginSignatureInputs } from './bcs.js';
|
|
7
|
+
export { poseidonHash } from './poseidon.js';
|
|
8
|
+
export { generateNonce, generateRandomness } from './nonce.js';
|
|
@@ -19,9 +19,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var zklogin_exports = {};
|
|
20
20
|
__export(zklogin_exports, {
|
|
21
21
|
ZkLoginPublicIdentifier: () => import_publickey.ZkLoginPublicIdentifier,
|
|
22
|
+
computeZkLoginAddress: () => import_address.computeZkLoginAddress,
|
|
22
23
|
computeZkLoginAddressFromSeed: () => import_address.computeZkLoginAddressFromSeed,
|
|
24
|
+
genAddressSeed: () => import_utils.genAddressSeed,
|
|
25
|
+
generateNonce: () => import_nonce.generateNonce,
|
|
26
|
+
generateRandomness: () => import_nonce.generateRandomness,
|
|
27
|
+
getExtendedEphemeralPublicKey: () => import_utils.getExtendedEphemeralPublicKey,
|
|
23
28
|
getZkLoginSignature: () => import_signature.getZkLoginSignature,
|
|
29
|
+
hashASCIIStrToField: () => import_utils.hashASCIIStrToField,
|
|
30
|
+
jwtToAddress: () => import_address.jwtToAddress,
|
|
24
31
|
parseZkLoginSignature: () => import_signature.parseZkLoginSignature,
|
|
32
|
+
poseidonHash: () => import_poseidon.poseidonHash,
|
|
25
33
|
toBigEndianBytes: () => import_utils.toBigEndianBytes,
|
|
26
34
|
toPaddedBigEndianBytes: () => import_utils.toPaddedBigEndianBytes,
|
|
27
35
|
toZkLoginPublicIdentifier: () => import_publickey.toZkLoginPublicIdentifier
|
|
@@ -31,4 +39,6 @@ var import_signature = require("./signature.js");
|
|
|
31
39
|
var import_utils = require("./utils.js");
|
|
32
40
|
var import_address = require("./address.js");
|
|
33
41
|
var import_publickey = require("./publickey.js");
|
|
42
|
+
var import_poseidon = require("./poseidon.js");
|
|
43
|
+
var import_nonce = require("./nonce.js");
|
|
34
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/zklogin/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { getZkLoginSignature, parseZkLoginSignature } from './signature.js';\nexport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA2D;AAC3D,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { getZkLoginSignature, parseZkLoginSignature } from './signature.js';\nexport {\n\ttoBigEndianBytes,\n\ttoPaddedBigEndianBytes,\n\thashASCIIStrToField,\n\tgenAddressSeed,\n\tgetExtendedEphemeralPublicKey,\n} from './utils.js';\nexport { computeZkLoginAddressFromSeed, computeZkLoginAddress, jwtToAddress } from './address.js';\nexport type { ComputeZkLoginAddressOptions } from './address.js';\nexport { toZkLoginPublicIdentifier, ZkLoginPublicIdentifier } from './publickey.js';\nexport type { ZkLoginSignatureInputs } from './bcs.js';\nexport { poseidonHash } from './poseidon.js';\nexport { generateNonce, generateRandomness } from './nonce.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA2D;AAC3D,mBAMO;AACP,qBAAmF;AAEnF,uBAAmE;AAEnE,sBAA6B;AAC7B,mBAAkD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PublicKey } from '../cryptography/publickey.js';
|
|
2
|
+
export declare const NONCE_LENGTH = 27;
|
|
3
|
+
export declare function generateRandomness(): string;
|
|
4
|
+
export declare function generateNonce(publicKey: PublicKey, maxEpoch: number, randomness: bigint | string): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var nonce_exports = {};
|
|
20
|
+
__export(nonce_exports, {
|
|
21
|
+
NONCE_LENGTH: () => NONCE_LENGTH,
|
|
22
|
+
generateNonce: () => generateNonce,
|
|
23
|
+
generateRandomness: () => generateRandomness
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(nonce_exports);
|
|
26
|
+
var import_bcs = require("@mysten/bcs");
|
|
27
|
+
var import_utils = require("@noble/hashes/utils");
|
|
28
|
+
var import_jose = require("jose");
|
|
29
|
+
var import_poseidon = require("./poseidon.js");
|
|
30
|
+
var import_utils2 = require("./utils.js");
|
|
31
|
+
const NONCE_LENGTH = 27;
|
|
32
|
+
function toBigIntBE(bytes) {
|
|
33
|
+
const hex = (0, import_bcs.toHex)(bytes);
|
|
34
|
+
if (hex.length === 0) {
|
|
35
|
+
return BigInt(0);
|
|
36
|
+
}
|
|
37
|
+
return BigInt(`0x${hex}`);
|
|
38
|
+
}
|
|
39
|
+
function generateRandomness() {
|
|
40
|
+
return String(toBigIntBE((0, import_utils.randomBytes)(16)));
|
|
41
|
+
}
|
|
42
|
+
function generateNonce(publicKey, maxEpoch, randomness) {
|
|
43
|
+
const publicKeyBytes = toBigIntBE(publicKey.toSuiBytes());
|
|
44
|
+
const eph_public_key_0 = publicKeyBytes / 2n ** 128n;
|
|
45
|
+
const eph_public_key_1 = publicKeyBytes % 2n ** 128n;
|
|
46
|
+
const bigNum = (0, import_poseidon.poseidonHash)([eph_public_key_0, eph_public_key_1, maxEpoch, BigInt(randomness)]);
|
|
47
|
+
const Z = (0, import_utils2.toPaddedBigEndianBytes)(bigNum, 20);
|
|
48
|
+
const nonce = import_jose.base64url.encode(Z);
|
|
49
|
+
if (nonce.length !== NONCE_LENGTH) {
|
|
50
|
+
throw new Error(`Length of nonce ${nonce} (${nonce.length}) is not equal to ${NONCE_LENGTH}`);
|
|
51
|
+
}
|
|
52
|
+
return nonce;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=nonce.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/zklogin/nonce.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@mysten/bcs';\nimport { randomBytes } from '@noble/hashes/utils';\nimport { base64url } from 'jose';\n\nimport type { PublicKey } from '../cryptography/publickey.js';\nimport { poseidonHash } from './poseidon.js';\nimport { toPaddedBigEndianBytes } from './utils.js';\n\nexport const NONCE_LENGTH = 27;\n\nfunction toBigIntBE(bytes: Uint8Array) {\n\tconst hex = toHex(bytes);\n\tif (hex.length === 0) {\n\t\treturn BigInt(0);\n\t}\n\treturn BigInt(`0x${hex}`);\n}\n\nexport function generateRandomness() {\n\t// Once Node 20 enters LTS, we can just use crypto.getRandomValues(new Uint8Array(16)), but until then we use `randomBytes` to improve compatibility:\n\treturn String(toBigIntBE(randomBytes(16)));\n}\n\nexport function generateNonce(publicKey: PublicKey, maxEpoch: number, randomness: bigint | string) {\n\tconst publicKeyBytes = toBigIntBE(publicKey.toSuiBytes());\n\tconst eph_public_key_0 = publicKeyBytes / 2n ** 128n;\n\tconst eph_public_key_1 = publicKeyBytes % 2n ** 128n;\n\tconst bigNum = poseidonHash([eph_public_key_0, eph_public_key_1, maxEpoch, BigInt(randomness)]);\n\tconst Z = toPaddedBigEndianBytes(bigNum, 20);\n\tconst nonce = base64url.encode(Z);\n\tif (nonce.length !== NONCE_LENGTH) {\n\t\tthrow new Error(`Length of nonce ${nonce} (${nonce.length}) is not equal to ${NONCE_LENGTH}`);\n\t}\n\treturn nonce;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsB;AACtB,mBAA4B;AAC5B,kBAA0B;AAG1B,sBAA6B;AAC7B,IAAAA,gBAAuC;AAEhC,MAAM,eAAe;AAE5B,SAAS,WAAW,OAAmB;AACtC,QAAM,UAAM,kBAAM,KAAK;AACvB,MAAI,IAAI,WAAW,GAAG;AACrB,WAAO,OAAO,CAAC;AAAA,EAChB;AACA,SAAO,OAAO,KAAK,GAAG,EAAE;AACzB;AAEO,SAAS,qBAAqB;AAEpC,SAAO,OAAO,eAAW,0BAAY,EAAE,CAAC,CAAC;AAC1C;AAEO,SAAS,cAAc,WAAsB,UAAkB,YAA6B;AAClG,QAAM,iBAAiB,WAAW,UAAU,WAAW,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM;AAChD,QAAM,mBAAmB,iBAAiB,MAAM;AAChD,QAAM,aAAS,8BAAa,CAAC,kBAAkB,kBAAkB,UAAU,OAAO,UAAU,CAAC,CAAC;AAC9F,QAAM,QAAI,sCAAuB,QAAQ,EAAE;AAC3C,QAAM,QAAQ,sBAAU,OAAO,CAAC;AAChC,MAAI,MAAM,WAAW,cAAc;AAClC,UAAM,IAAI,MAAM,mBAAmB,KAAK,KAAK,MAAM,MAAM,qBAAqB,YAAY,EAAE;AAAA,EAC7F;AACA,SAAO;AACR;",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var poseidon_exports = {};
|
|
20
|
+
__export(poseidon_exports, {
|
|
21
|
+
BN254_FIELD_SIZE: () => BN254_FIELD_SIZE,
|
|
22
|
+
poseidonHash: () => poseidonHash
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(poseidon_exports);
|
|
25
|
+
var import_poseidon_lite = require("poseidon-lite");
|
|
26
|
+
const poseidonNumToHashFN = [
|
|
27
|
+
import_poseidon_lite.poseidon1,
|
|
28
|
+
import_poseidon_lite.poseidon2,
|
|
29
|
+
import_poseidon_lite.poseidon3,
|
|
30
|
+
import_poseidon_lite.poseidon4,
|
|
31
|
+
import_poseidon_lite.poseidon5,
|
|
32
|
+
import_poseidon_lite.poseidon6,
|
|
33
|
+
import_poseidon_lite.poseidon7,
|
|
34
|
+
import_poseidon_lite.poseidon8,
|
|
35
|
+
import_poseidon_lite.poseidon9,
|
|
36
|
+
import_poseidon_lite.poseidon10,
|
|
37
|
+
import_poseidon_lite.poseidon11,
|
|
38
|
+
import_poseidon_lite.poseidon12,
|
|
39
|
+
import_poseidon_lite.poseidon13,
|
|
40
|
+
import_poseidon_lite.poseidon14,
|
|
41
|
+
import_poseidon_lite.poseidon15,
|
|
42
|
+
import_poseidon_lite.poseidon16
|
|
43
|
+
];
|
|
44
|
+
const BN254_FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
45
|
+
function poseidonHash(inputs) {
|
|
46
|
+
inputs.forEach((x) => {
|
|
47
|
+
const b = BigInt(x);
|
|
48
|
+
if (b < 0 || b >= BN254_FIELD_SIZE) {
|
|
49
|
+
throw new Error(`Element ${b} not in the BN254 field`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const hashFN = poseidonNumToHashFN[inputs.length - 1];
|
|
53
|
+
if (hashFN) {
|
|
54
|
+
return hashFN(inputs);
|
|
55
|
+
} else if (inputs.length <= 32) {
|
|
56
|
+
const hash1 = poseidonHash(inputs.slice(0, 16));
|
|
57
|
+
const hash2 = poseidonHash(inputs.slice(16));
|
|
58
|
+
return poseidonHash([hash1, hash2]);
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error(`Yet to implement: Unable to hash a vector of length ${inputs.length}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=poseidon.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/zklogin/poseidon.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n\tposeidon1,\n\tposeidon2,\n\tposeidon3,\n\tposeidon4,\n\tposeidon5,\n\tposeidon6,\n\tposeidon7,\n\tposeidon8,\n\tposeidon9,\n\tposeidon10,\n\tposeidon11,\n\tposeidon12,\n\tposeidon13,\n\tposeidon14,\n\tposeidon15,\n\tposeidon16,\n} from 'poseidon-lite';\n\nconst poseidonNumToHashFN = [\n\tposeidon1,\n\tposeidon2,\n\tposeidon3,\n\tposeidon4,\n\tposeidon5,\n\tposeidon6,\n\tposeidon7,\n\tposeidon8,\n\tposeidon9,\n\tposeidon10,\n\tposeidon11,\n\tposeidon12,\n\tposeidon13,\n\tposeidon14,\n\tposeidon15,\n\tposeidon16,\n];\n\nexport const BN254_FIELD_SIZE =\n\t21888242871839275222246405745257275088548364400416034343698204186575808495617n;\n\nexport function poseidonHash(inputs: (number | bigint | string)[]): bigint {\n\tinputs.forEach((x) => {\n\t\tconst b = BigInt(x);\n\t\tif (b < 0 || b >= BN254_FIELD_SIZE) {\n\t\t\tthrow new Error(`Element ${b} not in the BN254 field`);\n\t\t}\n\t});\n\n\tconst hashFN = poseidonNumToHashFN[inputs.length - 1];\n\n\tif (hashFN) {\n\t\treturn hashFN(inputs);\n\t} else if (inputs.length <= 32) {\n\t\tconst hash1 = poseidonHash(inputs.slice(0, 16));\n\t\tconst hash2 = poseidonHash(inputs.slice(16));\n\t\treturn poseidonHash([hash1, hash2]);\n\t} else {\n\t\tthrow new Error(`Yet to implement: Unable to hash a vector of length ${inputs.length}`);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAiBO;AAEP,MAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,mBACZ;AAEM,SAAS,aAAa,QAA8C;AAC1E,SAAO,QAAQ,CAAC,MAAM;AACrB,UAAM,IAAI,OAAO,CAAC;AAClB,QAAI,IAAI,KAAK,KAAK,kBAAkB;AACnC,YAAM,IAAI,MAAM,WAAW,CAAC,yBAAyB;AAAA,IACtD;AAAA,EACD,CAAC;AAED,QAAM,SAAS,oBAAoB,OAAO,SAAS,CAAC;AAEpD,MAAI,QAAQ;AACX,WAAO,OAAO,MAAM;AAAA,EACrB,WAAW,OAAO,UAAU,IAAI;AAC/B,UAAM,QAAQ,aAAa,OAAO,MAAM,GAAG,EAAE,CAAC;AAC9C,UAAM,QAAQ,aAAa,OAAO,MAAM,EAAE,CAAC;AAC3C,WAAO,aAAa,CAAC,OAAO,KAAK,CAAC;AAAA,EACnC,OAAO;AACN,UAAM,IAAI,MAAM,uDAAuD,OAAO,MAAM,EAAE;AAAA,EACvF;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -17,6 +17,7 @@ export declare class ZkLoginPublicIdentifier extends PublicKey {
|
|
|
17
17
|
* Checks if two zkLogin public identifiers are equal
|
|
18
18
|
*/
|
|
19
19
|
equals(publicKey: ZkLoginPublicIdentifier): boolean;
|
|
20
|
+
toSuiAddress(): string;
|
|
20
21
|
/**
|
|
21
22
|
* Return the byte array representation of the zkLogin public identifier
|
|
22
23
|
*/
|
|
@@ -40,6 +41,7 @@ export declare class ZkLoginPublicIdentifier extends PublicKey {
|
|
|
40
41
|
}
|
|
41
42
|
export declare function toZkLoginPublicIdentifier(addressSeed: bigint, iss: string, options?: {
|
|
42
43
|
client?: SuiGraphQLClient;
|
|
44
|
+
legacyAddress?: boolean;
|
|
43
45
|
}): ZkLoginPublicIdentifier;
|
|
44
46
|
export declare function parseSerializedZkLoginSignature(signature: Uint8Array | string): {
|
|
45
47
|
serializedSignature: string;
|
|
@@ -31,14 +31,17 @@ __export(publickey_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(publickey_exports);
|
|
33
33
|
var import_bcs = require("@mysten/bcs");
|
|
34
|
+
var import_blake2b = require("@noble/hashes/blake2b");
|
|
35
|
+
var import_utils = require("@noble/hashes/utils");
|
|
34
36
|
var import_publickey = require("../cryptography/publickey.js");
|
|
35
37
|
var import_signature_scheme = require("../cryptography/signature-scheme.js");
|
|
36
38
|
var import_client = require("../graphql/client.js");
|
|
37
39
|
var import__ = require("../graphql/schemas/2024.4/index.js");
|
|
40
|
+
var import_sui_types = require("../utils/sui-types.js");
|
|
38
41
|
var import_jwt_utils = require("./jwt-utils.js");
|
|
39
42
|
var import_signature = require("./signature.js");
|
|
40
|
-
var
|
|
41
|
-
var _data, _client;
|
|
43
|
+
var import_utils2 = require("./utils.js");
|
|
44
|
+
var _data, _client, _legacyAddress;
|
|
42
45
|
const _ZkLoginPublicIdentifier = class _ZkLoginPublicIdentifier extends import_publickey.PublicKey {
|
|
43
46
|
/**
|
|
44
47
|
* Create a new ZkLoginPublicIdentifier object
|
|
@@ -48,6 +51,7 @@ const _ZkLoginPublicIdentifier = class _ZkLoginPublicIdentifier extends import_p
|
|
|
48
51
|
super();
|
|
49
52
|
__privateAdd(this, _data);
|
|
50
53
|
__privateAdd(this, _client);
|
|
54
|
+
__privateAdd(this, _legacyAddress);
|
|
51
55
|
__privateSet(this, _client, client);
|
|
52
56
|
if (typeof value === "string") {
|
|
53
57
|
__privateSet(this, _data, (0, import_bcs.fromBase64)(value));
|
|
@@ -56,6 +60,10 @@ const _ZkLoginPublicIdentifier = class _ZkLoginPublicIdentifier extends import_p
|
|
|
56
60
|
} else {
|
|
57
61
|
__privateSet(this, _data, Uint8Array.from(value));
|
|
58
62
|
}
|
|
63
|
+
__privateSet(this, _legacyAddress, __privateGet(this, _data).length !== __privateGet(this, _data)[0] + 1 + 32);
|
|
64
|
+
if (__privateGet(this, _legacyAddress)) {
|
|
65
|
+
__privateSet(this, _data, normalizeZkLoginPublicKeyBytes(__privateGet(this, _data)));
|
|
66
|
+
}
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
61
69
|
* Checks if two zkLogin public identifiers are equal
|
|
@@ -63,6 +71,18 @@ const _ZkLoginPublicIdentifier = class _ZkLoginPublicIdentifier extends import_p
|
|
|
63
71
|
equals(publicKey) {
|
|
64
72
|
return super.equals(publicKey);
|
|
65
73
|
}
|
|
74
|
+
toSuiAddress() {
|
|
75
|
+
if (__privateGet(this, _legacyAddress)) {
|
|
76
|
+
const legacyBytes = normalizeZkLoginPublicKeyBytes(__privateGet(this, _data), true);
|
|
77
|
+
const addressBytes = new Uint8Array(legacyBytes.length + 1);
|
|
78
|
+
addressBytes[0] = this.flag();
|
|
79
|
+
addressBytes.set(legacyBytes, 1);
|
|
80
|
+
return (0, import_sui_types.normalizeSuiAddress)(
|
|
81
|
+
(0, import_utils.bytesToHex)((0, import_blake2b.blake2b)(addressBytes, { dkLen: 32 })).slice(0, import_sui_types.SUI_ADDRESS_LENGTH * 2)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return super.toSuiAddress();
|
|
85
|
+
}
|
|
66
86
|
/**
|
|
67
87
|
* Return the byte array representation of the zkLogin public identifier
|
|
68
88
|
*/
|
|
@@ -112,9 +132,10 @@ const _ZkLoginPublicIdentifier = class _ZkLoginPublicIdentifier extends import_p
|
|
|
112
132
|
};
|
|
113
133
|
_data = new WeakMap();
|
|
114
134
|
_client = new WeakMap();
|
|
135
|
+
_legacyAddress = new WeakMap();
|
|
115
136
|
let ZkLoginPublicIdentifier = _ZkLoginPublicIdentifier;
|
|
116
137
|
function toZkLoginPublicIdentifier(addressSeed, iss, options) {
|
|
117
|
-
const addressSeedBytesBigEndian = (0,
|
|
138
|
+
const addressSeedBytesBigEndian = options?.legacyAddress ? (0, import_utils2.toBigEndianBytes)(addressSeed, 32) : (0, import_utils2.toPaddedBigEndianBytes)(addressSeed, 32);
|
|
118
139
|
const issBytes = new TextEncoder().encode(iss);
|
|
119
140
|
const tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);
|
|
120
141
|
tmp.set([issBytes.length], 0);
|
|
@@ -140,6 +161,15 @@ const VerifyZkLoginSignatureQuery = (0, import__.graphql)(`
|
|
|
140
161
|
}
|
|
141
162
|
}
|
|
142
163
|
`);
|
|
164
|
+
function normalizeZkLoginPublicKeyBytes(bytes, legacyAddress = false) {
|
|
165
|
+
const issByteLength = bytes[0] + 1;
|
|
166
|
+
const addressSeed = BigInt(`0x${(0, import_bcs.toHex)(bytes.slice(issByteLength))}`);
|
|
167
|
+
const seedBytes = legacyAddress ? (0, import_utils2.toBigEndianBytes)(addressSeed, 32) : (0, import_utils2.toPaddedBigEndianBytes)(addressSeed, 32);
|
|
168
|
+
const data = new Uint8Array(issByteLength + seedBytes.length);
|
|
169
|
+
data.set(bytes.slice(0, issByteLength), 0);
|
|
170
|
+
data.set(seedBytes, issByteLength);
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
143
173
|
async function graphqlVerifyZkLoginSignature({
|
|
144
174
|
address,
|
|
145
175
|
bytes,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/zklogin/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { SuiGraphQLClient } from '../graphql/client.js';\nimport { graphql } from '../graphql/schemas/2024.4/index.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { toPaddedBigEndianBytes } from './utils.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array;\n\t#client?: SuiGraphQLClient;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: SuiGraphQLClient } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.#data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.#data = value;\n\t\t} else {\n\t\t\tthis.#data = Uint8Array.from(value);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(_message: Uint8Array, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PERSONAL_MESSAGE',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TRANSACTION_DATA',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions?: { client?: SuiGraphQLClient },\n): ZkLoginPublicIdentifier {\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = toPaddedBigEndianBytes(addressSeed, 32);\n\tconst issBytes = new TextEncoder().encode(iss);\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nconst VerifyZkLoginSignatureQuery = graphql(`\n\tquery Zklogin(\n\t\t$bytes: Base64!\n\t\t$signature: Base64!\n\t\t$intentScope: ZkLoginIntentScope!\n\t\t$author: SuiAddress!\n\t) {\n\t\tverifyZkloginSignature(\n\t\t\tbytes: $bytes\n\t\t\tsignature: $signature\n\t\t\tintentScope: $intentScope\n\t\t\tauthor: $author\n\t\t) {\n\t\t\tsuccess\n\t\t\terrors\n\t\t}\n\t}\n`);\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient = new SuiGraphQLClient({\n\t\turl: 'https://sui-mainnet.mystenlabs.com/graphql',\n\t}),\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PERSONAL_MESSAGE' | 'TRANSACTION_DATA';\n\tclient?: SuiGraphQLClient;\n}) {\n\tconst resp = await client.query({\n\t\tquery: VerifyZkLoginSignatureQuery,\n\t\tvariables: {\n\t\t\tbytes,\n\t\t\tsignature,\n\t\t\tintentScope,\n\t\t\tauthor: address,\n\t\t},\n\t});\n\n\treturn (\n\t\tresp.data?.verifyZkloginSignature.success === true &&\n\t\tresp.data?.verifyZkloginSignature.errors.length === 0\n\t);\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifer = toZkLoginPublicIdentifier(BigInt(addressSeed), iss);\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifer.toRawBytes(),\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { SuiGraphQLClient } from '../graphql/client.js';\nimport { graphql } from '../graphql/schemas/2024.4/index.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array;\n\t#client?: SuiGraphQLClient;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: SuiGraphQLClient } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.#data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.#data = value;\n\t\t} else {\n\t\t\tthis.#data = Uint8Array.from(value);\n\t\t}\n\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toSuiAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\t\taddressBytes[0] = this.flag();\n\t\t\taddressBytes.set(legacyBytes, 1);\n\t\t\treturn normalizeSuiAddress(\n\t\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),\n\t\t\t);\n\t\t}\n\n\t\treturn super.toSuiAddress();\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(_message: Uint8Array, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PERSONAL_MESSAGE',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TRANSACTION_DATA',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions?: { client?: SuiGraphQLClient; legacyAddress?: boolean },\n): ZkLoginPublicIdentifier {\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options?.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(iss);\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nconst VerifyZkLoginSignatureQuery = graphql(`\n\tquery Zklogin(\n\t\t$bytes: Base64!\n\t\t$signature: Base64!\n\t\t$intentScope: ZkLoginIntentScope!\n\t\t$author: SuiAddress!\n\t) {\n\t\tverifyZkloginSignature(\n\t\t\tbytes: $bytes\n\t\t\tsignature: $signature\n\t\t\tintentScope: $intentScope\n\t\t\tauthor: $author\n\t\t) {\n\t\t\tsuccess\n\t\t\terrors\n\t\t}\n\t}\n`);\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress = false) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient = new SuiGraphQLClient({\n\t\turl: 'https://sui-mainnet.mystenlabs.com/graphql',\n\t}),\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PERSONAL_MESSAGE' | 'TRANSACTION_DATA';\n\tclient?: SuiGraphQLClient;\n}) {\n\tconst resp = await client.query({\n\t\tquery: VerifyZkLoginSignatureQuery,\n\t\tvariables: {\n\t\t\tbytes,\n\t\t\tsignature,\n\t\t\tintentScope,\n\t\t\tauthor: address,\n\t\t},\n\t});\n\n\treturn (\n\t\tresp.data?.verifyZkloginSignature.success === true &&\n\t\tresp.data?.verifyZkloginSignature.errors.length === 0\n\t);\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifer = toZkLoginPublicIdentifier(BigInt(addressSeed), iss);\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifer.toRawBytes(),\n\t};\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
+
import type { PublicKey } from '../cryptography/publickey.js';
|
|
1
2
|
export declare function toPaddedBigEndianBytes(num: bigint, width: number): Uint8Array;
|
|
2
3
|
export declare function toBigEndianBytes(num: bigint, width: number): Uint8Array;
|
|
4
|
+
export declare function getExtendedEphemeralPublicKey(publicKey: PublicKey): string;
|
|
5
|
+
/**
|
|
6
|
+
* Splits an array into chunks of size chunk_size. If the array is not evenly
|
|
7
|
+
* divisible by chunk_size, the first chunk will be smaller than chunk_size.
|
|
8
|
+
*
|
|
9
|
+
* E.g., arrayChunk([1, 2, 3, 4, 5], 2) => [[1], [2, 3], [4, 5]]
|
|
10
|
+
*
|
|
11
|
+
* Note: Can be made more efficient by avoiding the reverse() calls.
|
|
12
|
+
*/
|
|
13
|
+
export declare function chunkArray<T>(array: T[], chunk_size: number): T[][];
|
|
14
|
+
export declare function hashASCIIStrToField(str: string, maxSize: number): bigint;
|
|
15
|
+
export declare function genAddressSeed(salt: string | bigint, name: string, value: string, aud: string, max_name_length?: number, max_value_length?: number, max_aud_length?: number): bigint;
|