@haneullabs/haneul 2.4.0 → 2.5.1
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/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/bcs.mjs +1 -1
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/index.d.mts +4 -4
- package/dist/client/core-resolver.mjs +2 -2
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.mjs +1 -1
- package/dist/client/core.mjs.map +1 -1
- package/dist/cryptography/keypair.d.mts +1 -1
- package/dist/cryptography/keypair.mjs +3 -3
- package/dist/cryptography/keypair.mjs.map +1 -1
- package/dist/cryptography/publickey.d.mts +1 -1
- package/dist/cryptography/publickey.mjs +2 -2
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/system_state.d.mts +2 -2
- package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.client.d.mts +4 -4
- package/dist/jsonRpc/client.d.mts +5 -5
- package/dist/jsonRpc/client.d.mts.map +1 -1
- package/dist/jsonRpc/client.mjs +56 -56
- package/dist/jsonRpc/client.mjs.map +1 -1
- package/dist/jsonRpc/core.mjs +6 -6
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/jsonRpc/index.d.mts +4 -4
- package/dist/jsonRpc/index.mjs +2 -2
- package/dist/jsonRpc/types/generated.d.mts +14 -14
- package/dist/jsonRpc/types/generated.d.mts.map +1 -1
- package/dist/jsonRpc/types/index.d.mts +2 -2
- package/dist/jsonRpc/types/params.d.mts +8 -8
- package/dist/jsonRpc/types/params.d.mts.map +1 -1
- package/dist/multisig/publickey.d.mts +1 -1
- package/dist/multisig/publickey.mjs +1 -1
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/multisig/signer.mjs +2 -2
- package/dist/multisig/signer.mjs.map +1 -1
- package/dist/transactions/Commands.mjs +3 -3
- package/dist/transactions/Commands.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +6 -6
- package/dist/transactions/data/internal.d.mts +109 -109
- package/dist/transactions/data/v1.d.mts +220 -220
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/executor/caching.mjs +1 -1
- package/dist/transactions/executor/caching.mjs.map +1 -1
- package/dist/transactions/executor/parallel.mjs +3 -3
- package/dist/transactions/executor/parallel.mjs.map +1 -1
- package/dist/transactions/executor/serial.mjs +1 -1
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/utils/haneul-types.d.mts +2 -2
- package/dist/utils/haneul-types.d.mts.map +1 -1
- package/dist/utils/haneul-types.mjs +2 -2
- package/dist/utils/haneul-types.mjs.map +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +2 -2
- package/dist/verify/verify.mjs +1 -1
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/bcs.d.mts.map +1 -1
- package/dist/zklogin/publickey.d.mts +1 -1
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/publickey.mjs +9 -9
- package/dist/zklogin/publickey.mjs.map +1 -1
- package/package.json +199 -199
- package/src/bcs/bcs.ts +1 -1
- package/src/client/core-resolver.ts +2 -2
- package/src/client/core.ts +1 -1
- package/src/cryptography/keypair.ts +3 -3
- package/src/cryptography/publickey.ts +2 -2
- package/src/grpc/proto/haneul/rpc/v2/system_state.ts +3 -3
- package/src/jsonRpc/client.ts +57 -57
- package/src/jsonRpc/core.ts +7 -7
- package/src/jsonRpc/index.ts +1 -1
- package/src/jsonRpc/types/generated.ts +13 -13
- package/src/jsonRpc/types/params.ts +7 -7
- package/src/multisig/publickey.ts +1 -1
- package/src/multisig/signer.ts +2 -2
- package/src/transactions/Commands.ts +3 -3
- package/src/transactions/executor/caching.ts +1 -1
- package/src/transactions/executor/parallel.ts +3 -3
- package/src/transactions/executor/serial.ts +1 -1
- package/src/utils/haneul-types.ts +1 -1
- package/src/utils/index.ts +1 -1
- package/src/verify/verify.ts +1 -1
- package/src/version.ts +1 -1
- package/src/zklogin/publickey.ts +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.mjs","names":["#client","#data","#legacyAddress","#toLegacyAddress"],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@haneullabs/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeHaneulAddress, HANEUL_ADDRESS_LENGTH } from '../utils/haneul-types.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array<ArrayBuffer>;\n\t#client?: ClientWithCoreApi;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: ClientWithCoreApi } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.#data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.#data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.#data = Uint8Array.from(value);\n\t\t}\n\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);\n\t\t}\n\t}\n\n\tstatic fromBytes(\n\t\tbytes: Uint8Array,\n\t\t{\n\t\t\tclient,\n\t\t\taddress,\n\t\t\tlegacyAddress,\n\t\t}: { client?: ClientWithCoreApi; address?: string; legacyAddress?: boolean } = {},\n\t) {\n\t\tlet publicKey: ZkLoginPublicIdentifier;\n\n\t\tif (legacyAddress === true) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (legacyAddress === false) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (address) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\n\t\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\t\tclient,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(bytes, {\n\t\t\t\tclient,\n\t\t\t});\n\t\t}\n\n\t\tif (address && publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Public key bytes do not match the provided address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\tstatic fromProof(address: string, proof: ZkLoginSignatureInputs) {\n\t\tconst { issBase64Details, addressSeed } = proof;\n\t\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\n\t\tconst legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: true,\n\t\t});\n\n\t\tif (legacyPublicKey.toSuiAddress() === address) {\n\t\t\treturn legacyPublicKey;\n\t\t}\n\n\t\tconst publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: false,\n\t\t});\n\n\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Proof does not match address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toSuiAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\treturn this.#toLegacyAddress();\n\t\t}\n\n\t\treturn super.toSuiAddress();\n\t}\n\n\t#toLegacyAddress() {\n\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\taddressBytes[0] = this.flag();\n\t\taddressBytes.set(legacyBytes, 1);\n\t\treturn normalizeHaneulAddress(\n\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, HANEUL_ADDRESS_LENGTH * 2),\n\t\t);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Haneul address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(_message: Uint8Array, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PersonalMessage',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TransactionData',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the public key is associated with the provided address\n\t */\n\toverride verifyAddress(address: string): boolean {\n\t\treturn address === super.toSuiAddress() || address === this.#toLegacyAddress();\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions: { client?: ClientWithCoreApi; legacyAddress: boolean },\n): ZkLoginPublicIdentifier {\n\tif (options.legacyAddress === undefined) {\n\t\tthrow new Error('legacyAddress parameter must be specified');\n\t}\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(normalizeZkLoginIssuer(iss));\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress: boolean) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient,\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PersonalMessage' | 'TransactionData';\n\tclient?: ClientWithCoreApi;\n}) {\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'A Haneul Client (GRPC, GraphQL, or JSON RPC) is required to verify zkLogin signatures',\n\t\t);\n\t}\n\tconst resp = await client.core.verifyZkLoginSignature({\n\t\tbytes,\n\t\tsignature,\n\t\tintentScope,\n\t\taddress: address,\n\t});\n\n\treturn resp.success === true && resp.errors.length === 0;\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifier = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\tlegacyAddress: false,\n\t});\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifier.toRawBytes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,0BAAb,MAAa,gCAAgC,UAAU;CACtD;CACA;CACA;;;;;CAMA,YAAY,OAA0B,EAAE,WAA2C,EAAE,EAAE;AACtF,SAAO;AAEP,QAAKA,SAAU;AAEf,MAAI,OAAO,UAAU,SACpB,OAAKC,OAAQ,WAAW,MAAM;WACpB,iBAAiB,WAC3B,OAAKA,OAAQ;MAEb,OAAKA,OAAQ,WAAW,KAAK,MAAM;AAEpC,QAAKC,gBAAiB,MAAKD,KAAM,WAAW,MAAKA,KAAM,KAAK,IAAI;AAEhE,MAAI,MAAKC,cACR,OAAKD,OAAQ,+BAA+B,MAAKA,MAAO,MAAM;;CAIhE,OAAO,UACN,OACA,EACC,QACA,SACA,kBAC8E,EAAE,EAChF;EACD,IAAI;AAEJ,MAAI,kBAAkB,KACrB,aAAY,IAAI,wBAAwB,+BAA+B,OAAO,KAAK,EAAE,EACpF,QACA,CAAC;WACQ,kBAAkB,MAC5B,aAAY,IAAI,wBAAwB,+BAA+B,OAAO,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AG;CACpE,MAAM,YAAY,gBACf,iBAAiB,aAAa,GAAG,GACjC,uBAAuB,aAAa,GAAG;CAC1C,MAAM,OAAO,IAAI,WAAW,gBAAgB,UAAU,OAAO;AAC7D,MAAK,IAAI,MAAM,MAAM,GAAG,cAAc,EAAE,EAAE;AAC1C,MAAK,IAAI,WAAW,cAAc;AAClC,QAAO;;AAGR,eAAe,8BAA8B,EAC5C,SACA,OACA,WACA,aACA,UAOE;AACF,KAAI,CAAC,OACJ,OAAM,IAAI,MACT,wFACA;CAEF,MAAM,OAAO,MAAM,OAAO,KAAK,uBAAuB;EACrD;EACA;EACA;EACS;EACT,CAAC;AAEF,QAAO,KAAK,YAAY,QAAQ,KAAK,OAAO,WAAW;;AAGxD,SAAgB,gCAAgC,WAAgC;CAC/E,MAAM,QAAQ,OAAO,cAAc,WAAW,WAAW,UAAU,GAAG;AAEtE,KAAI,MAAM,OAAO,yBAAyB,QACzC,OAAM,IAAI,MAAM,2BAA2B;CAI5C,MAAM,EAAE,QAAQ,UAAU,kBAAkB,sBADrB,MAAM,MAAM,EAAE,CAC4C;CACjF,MAAM,EAAE,kBAAkB,gBAAgB;CAC1C,MAAM,MAAM,kBAA0B,kBAAkB,MAAM;CAC9D,MAAM,mBAAmB,0BAA0B,OAAO,YAAY,EAAE,KAAK,EAC5E,eAAe,OACf,CAAC;AACF,QAAO;EACN,qBAAqB,SAAS,MAAM;EACpC,iBAAiB;EACjB,SAAS;GACR;GACA;GACA;GACA;GACA,aAAa,OAAO,YAAY;GAChC;EACD,WAAW;EACX,WAAW,iBAAiB,YAAY;EACxC"}
|
|
1
|
+
{"version":3,"file":"publickey.mjs","names":["#client","#data","#legacyAddress","#toLegacyAddress"],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@haneullabs/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeHaneulAddress, HANEUL_ADDRESS_LENGTH } from '../utils/haneul-types.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array<ArrayBuffer>;\n\t#client?: ClientWithCoreApi;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: ClientWithCoreApi } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.#data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.#data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.#data = Uint8Array.from(value);\n\t\t}\n\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);\n\t\t}\n\t}\n\n\tstatic fromBytes(\n\t\tbytes: Uint8Array,\n\t\t{\n\t\t\tclient,\n\t\t\taddress,\n\t\t\tlegacyAddress,\n\t\t}: { client?: ClientWithCoreApi; address?: string; legacyAddress?: boolean } = {},\n\t) {\n\t\tlet publicKey: ZkLoginPublicIdentifier;\n\n\t\tif (legacyAddress === true) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (legacyAddress === false) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (address) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\n\t\t\tif (publicKey.toHaneulAddress() !== address) {\n\t\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\t\tclient,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(bytes, {\n\t\t\t\tclient,\n\t\t\t});\n\t\t}\n\n\t\tif (address && publicKey.toHaneulAddress() !== address) {\n\t\t\tthrow new Error('Public key bytes do not match the provided address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\tstatic fromProof(address: string, proof: ZkLoginSignatureInputs) {\n\t\tconst { issBase64Details, addressSeed } = proof;\n\t\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\n\t\tconst legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: true,\n\t\t});\n\n\t\tif (legacyPublicKey.toHaneulAddress() === address) {\n\t\t\treturn legacyPublicKey;\n\t\t}\n\n\t\tconst publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: false,\n\t\t});\n\n\t\tif (publicKey.toHaneulAddress() !== address) {\n\t\t\tthrow new Error('Proof does not match address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toHaneulAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\treturn this.#toLegacyAddress();\n\t\t}\n\n\t\treturn super.toHaneulAddress();\n\t}\n\n\t#toLegacyAddress() {\n\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\taddressBytes[0] = this.flag();\n\t\taddressBytes.set(legacyBytes, 1);\n\t\treturn normalizeHaneulAddress(\n\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, HANEUL_ADDRESS_LENGTH * 2),\n\t\t);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Haneul 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).toHaneulAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PersonalMessage',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toHaneulAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TransactionData',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the public key is associated with the provided address\n\t */\n\toverride verifyAddress(address: string): boolean {\n\t\treturn address === super.toHaneulAddress() || address === this.#toLegacyAddress();\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions: { client?: ClientWithCoreApi; legacyAddress: boolean },\n): ZkLoginPublicIdentifier {\n\tif (options.legacyAddress === undefined) {\n\t\tthrow new Error('legacyAddress parameter must be specified');\n\t}\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(normalizeZkLoginIssuer(iss));\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress: boolean) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient,\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PersonalMessage' | 'TransactionData';\n\tclient?: ClientWithCoreApi;\n}) {\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'A Haneul Client (GRPC, GraphQL, or JSON RPC) is required to verify zkLogin signatures',\n\t\t);\n\t}\n\tconst resp = await client.core.verifyZkLoginSignature({\n\t\tbytes,\n\t\tsignature,\n\t\tintentScope,\n\t\taddress: address,\n\t});\n\n\treturn resp.success === true && resp.errors.length === 0;\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifier = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\tlegacyAddress: false,\n\t});\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifier.toRawBytes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,0BAAb,MAAa,gCAAgC,UAAU;CACtD;CACA;CACA;;;;;CAMA,YAAY,OAA0B,EAAE,WAA2C,EAAE,EAAE;AACtF,SAAO;AAEP,QAAKA,SAAU;AAEf,MAAI,OAAO,UAAU,SACpB,OAAKC,OAAQ,WAAW,MAAM;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AAO,YAAY,EAAE,KAAK,EAC5E,eAAe,OACf,CAAC;AACF,QAAO;EACN,qBAAqB,SAAS,MAAM;EACpC,iBAAiB;EACjB,SAAS;GACR;GACA;GACA;GACA;GACA,aAAa,OAAO,YAAY;GAChC;EACD,WAAW;EACX,WAAW,iBAAiB,YAAY;EACxC"}
|
package/package.json
CHANGED
|
@@ -1,200 +1,200 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
2
|
+
"name": "@haneullabs/haneul",
|
|
3
|
+
"author": "Haneul Labs <build@haneul-labs.com>",
|
|
4
|
+
"description": "Haneul TypeScript API",
|
|
5
|
+
"homepage": "https://sdk.haneul-labs.com",
|
|
6
|
+
"version": "2.5.1",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"CHANGELOG.md",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"README.md",
|
|
13
|
+
"bcs",
|
|
14
|
+
"builder",
|
|
15
|
+
"client",
|
|
16
|
+
"cryptography",
|
|
17
|
+
"dist",
|
|
18
|
+
"experimental",
|
|
19
|
+
"faucet",
|
|
20
|
+
"graphql",
|
|
21
|
+
"grpc",
|
|
22
|
+
"jsonRpc",
|
|
23
|
+
"keypairs",
|
|
24
|
+
"multisig",
|
|
25
|
+
"src",
|
|
26
|
+
"transactions",
|
|
27
|
+
"utils",
|
|
28
|
+
"verify",
|
|
29
|
+
"zklogin"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22"
|
|
33
|
+
},
|
|
34
|
+
"type": "module",
|
|
35
|
+
"exports": {
|
|
36
|
+
"./bcs": {
|
|
37
|
+
"types": "./dist/bcs/index.d.mts",
|
|
38
|
+
"import": "./dist/bcs/index.mjs",
|
|
39
|
+
"default": "./dist/bcs/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./client": {
|
|
42
|
+
"types": "./dist/client/index.d.mts",
|
|
43
|
+
"import": "./dist/client/index.mjs",
|
|
44
|
+
"default": "./dist/client/index.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./cryptography": {
|
|
47
|
+
"types": "./dist/cryptography/index.d.mts",
|
|
48
|
+
"import": "./dist/cryptography/index.mjs",
|
|
49
|
+
"default": "./dist/cryptography/index.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./faucet": {
|
|
52
|
+
"types": "./dist/faucet/index.d.mts",
|
|
53
|
+
"import": "./dist/faucet/index.mjs",
|
|
54
|
+
"default": "./dist/faucet/index.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./graphql": {
|
|
57
|
+
"types": "./dist/graphql/index.d.mts",
|
|
58
|
+
"import": "./dist/graphql/index.mjs",
|
|
59
|
+
"default": "./dist/graphql/index.mjs"
|
|
60
|
+
},
|
|
61
|
+
"./grpc": {
|
|
62
|
+
"types": "./dist/grpc/index.d.mts",
|
|
63
|
+
"import": "./dist/grpc/index.mjs",
|
|
64
|
+
"default": "./dist/grpc/index.mjs"
|
|
65
|
+
},
|
|
66
|
+
"./jsonRpc": {
|
|
67
|
+
"types": "./dist/jsonRpc/index.d.mts",
|
|
68
|
+
"import": "./dist/jsonRpc/index.mjs",
|
|
69
|
+
"default": "./dist/jsonRpc/index.mjs"
|
|
70
|
+
},
|
|
71
|
+
"./keypairs/ed25519": {
|
|
72
|
+
"types": "./dist/keypairs/ed25519/index.d.mts",
|
|
73
|
+
"import": "./dist/keypairs/ed25519/index.mjs",
|
|
74
|
+
"default": "./dist/keypairs/ed25519/index.mjs"
|
|
75
|
+
},
|
|
76
|
+
"./keypairs/secp256k1": {
|
|
77
|
+
"types": "./dist/keypairs/secp256k1/index.d.mts",
|
|
78
|
+
"import": "./dist/keypairs/secp256k1/index.mjs",
|
|
79
|
+
"default": "./dist/keypairs/secp256k1/index.mjs"
|
|
80
|
+
},
|
|
81
|
+
"./keypairs/secp256r1": {
|
|
82
|
+
"types": "./dist/keypairs/secp256r1/index.d.mts",
|
|
83
|
+
"import": "./dist/keypairs/secp256r1/index.mjs",
|
|
84
|
+
"default": "./dist/keypairs/secp256r1/index.mjs"
|
|
85
|
+
},
|
|
86
|
+
"./keypairs/passkey": {
|
|
87
|
+
"types": "./dist/keypairs/passkey/index.d.mts",
|
|
88
|
+
"import": "./dist/keypairs/passkey/index.mjs",
|
|
89
|
+
"default": "./dist/keypairs/passkey/index.mjs"
|
|
90
|
+
},
|
|
91
|
+
"./multisig": {
|
|
92
|
+
"types": "./dist/multisig/index.d.mts",
|
|
93
|
+
"import": "./dist/multisig/index.mjs",
|
|
94
|
+
"default": "./dist/multisig/index.mjs"
|
|
95
|
+
},
|
|
96
|
+
"./transactions": {
|
|
97
|
+
"types": "./dist/transactions/index.d.mts",
|
|
98
|
+
"import": "./dist/transactions/index.mjs",
|
|
99
|
+
"default": "./dist/transactions/index.mjs"
|
|
100
|
+
},
|
|
101
|
+
"./utils": {
|
|
102
|
+
"types": "./dist/utils/index.d.mts",
|
|
103
|
+
"import": "./dist/utils/index.mjs",
|
|
104
|
+
"default": "./dist/utils/index.mjs"
|
|
105
|
+
},
|
|
106
|
+
"./verify": {
|
|
107
|
+
"types": "./dist/verify/index.d.mts",
|
|
108
|
+
"import": "./dist/verify/index.mjs",
|
|
109
|
+
"default": "./dist/verify/index.mjs"
|
|
110
|
+
},
|
|
111
|
+
"./zklogin": {
|
|
112
|
+
"types": "./dist/zklogin/index.d.mts",
|
|
113
|
+
"import": "./dist/zklogin/index.mjs",
|
|
114
|
+
"default": "./dist/zklogin/index.mjs"
|
|
115
|
+
},
|
|
116
|
+
"./graphql/schema": {
|
|
117
|
+
"types": "./dist/graphql/schema/index.d.mts",
|
|
118
|
+
"import": "./dist/graphql/schema/index.mjs",
|
|
119
|
+
"default": "./dist/graphql/schema/index.mjs"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"scripts": {
|
|
123
|
+
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
124
|
+
"codegen": "pnpm codegen:graphql && pnpm codegen:grpc && pnpm lint:fix",
|
|
125
|
+
"codegen:graphql": "graphql-codegen --config graphql-codegen.ts",
|
|
126
|
+
"codegen:version": "node genversion.mjs",
|
|
127
|
+
"codegen:grpc": "rm -rf src/grpc/proto && mkdir src/grpc/proto && pnpm codegen:grpc-protoc && pnpm codegen:grpc-header && pnpm codegen:grpc-extensions && pnpm codegen:grpc-types",
|
|
128
|
+
"codegen:grpc-types": "tsx scripts/generate-grpc-types.ts",
|
|
129
|
+
"codegen:grpc-protoc": "protoc --ts_out ./src/grpc/proto --ts_opt force_server_none --ts_opt optimize_code_size --ts_opt ts_nocheck -I ../../../haneul-apis/proto -I ../../../haneul-apis/proto ../../../haneul-apis/proto/haneul/rpc/v2/*.proto ../../../haneul-apis/proto/google/*/*.proto",
|
|
130
|
+
"codegen:grpc-header": "find src/grpc/proto -type f -exec sh -c 'echo \"// Copyright (c) Haneul Labs, Inc.\\n// SPDX-License-Identifier: Apache-2.0\\n\" | cat - {} > temp && mv temp {}' \\;",
|
|
131
|
+
"codegen:grpc-extensions": "find src/grpc/proto -name '*.ts' | xargs sed -i '' -E 's/from \"(\\.[^\"]+)\"/from \"\\1.js\"/g'",
|
|
132
|
+
"build": "rm -rf dist && node genversion.mjs && tsc --noEmit && tsdown",
|
|
133
|
+
"vitest": "vitest",
|
|
134
|
+
"test": "pnpm test:typecheck && pnpm test:unit",
|
|
135
|
+
"test:typecheck": "tsc -p ./test",
|
|
136
|
+
"test:unit": "vitest run unit __tests__",
|
|
137
|
+
"test:e2e": "vitest run --config test/e2e/vitest.config.mts",
|
|
138
|
+
"size": "size-limit",
|
|
139
|
+
"analyze": "size-limit --why",
|
|
140
|
+
"prettier:check": "prettier -c --ignore-unknown .",
|
|
141
|
+
"prettier:fix": "prettier -w --ignore-unknown .",
|
|
142
|
+
"oxlint:check": "oxlint .",
|
|
143
|
+
"oxlint:fix": "oxlint --fix",
|
|
144
|
+
"lint": "pnpm run oxlint:check && pnpm run prettier:check",
|
|
145
|
+
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix",
|
|
146
|
+
"update-graphql-schema": "pnpm tsx scripts/update-graphql-schema.ts"
|
|
147
|
+
},
|
|
148
|
+
"repository": {
|
|
149
|
+
"type": "git",
|
|
150
|
+
"url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
|
|
151
|
+
},
|
|
152
|
+
"bugs": {
|
|
153
|
+
"url": "https://github.com/GeunhwaJeong/ts-sdks/issues/new"
|
|
154
|
+
},
|
|
155
|
+
"publishConfig": {
|
|
156
|
+
"access": "public"
|
|
157
|
+
},
|
|
158
|
+
"devDependencies": {
|
|
159
|
+
"@0no-co/graphqlsp": "^1.15.2",
|
|
160
|
+
"@graphql-codegen/add": "^6.0.0",
|
|
161
|
+
"@graphql-codegen/cli": "^6.1.1",
|
|
162
|
+
"@graphql-codegen/typed-document-node": "^6.1.5",
|
|
163
|
+
"@graphql-codegen/typescript": "5.0.7",
|
|
164
|
+
"@graphql-codegen/typescript-document-nodes": "5.0.7",
|
|
165
|
+
"@graphql-codegen/typescript-operations": "^5.0.7",
|
|
166
|
+
"@iarna/toml": "^2.2.5",
|
|
167
|
+
"@parcel/watcher": "^2.5.4",
|
|
168
|
+
"@types/node": "^25.0.8",
|
|
169
|
+
"@types/tmp": "^0.2.6",
|
|
170
|
+
"@types/ws": "^8.18.1",
|
|
171
|
+
"cross-env": "^10.1.0",
|
|
172
|
+
"graphql-config": "^5.1.5",
|
|
173
|
+
"msw": "^2.12.7",
|
|
174
|
+
"tmp": "^0.2.5",
|
|
175
|
+
"ts-retry-promise": "^0.8.1",
|
|
176
|
+
"typescript": "^5.9.3",
|
|
177
|
+
"vite": "^7.3.1",
|
|
178
|
+
"vite-tsconfig-paths": "^6.0.4",
|
|
179
|
+
"vitest": "^4.0.17",
|
|
180
|
+
"wait-on": "^9.0.3",
|
|
181
|
+
"ws": "^8.19.0"
|
|
182
|
+
},
|
|
183
|
+
"dependencies": {
|
|
184
|
+
"@graphql-typed-document-node/core": "^3.2.0",
|
|
185
|
+
"@haneullabs/bcs": "^2.0.2",
|
|
186
|
+
"@haneullabs/utils": "^0.3.1",
|
|
187
|
+
"@noble/curves": "^2.0.1",
|
|
188
|
+
"@noble/hashes": "^2.0.1",
|
|
189
|
+
"@protobuf-ts/grpcweb-transport": "^2.11.1",
|
|
190
|
+
"@protobuf-ts/runtime": "^2.11.1",
|
|
191
|
+
"@protobuf-ts/runtime-rpc": "^2.11.1",
|
|
192
|
+
"@scure/base": "^2.0.0",
|
|
193
|
+
"@scure/bip32": "^2.0.1",
|
|
194
|
+
"@scure/bip39": "^2.0.1",
|
|
195
|
+
"gql.tada": "^1.9.0",
|
|
196
|
+
"graphql": "^16.12.0",
|
|
197
|
+
"poseidon-lite": "0.2.1",
|
|
198
|
+
"valibot": "^1.2.0"
|
|
199
|
+
}
|
|
200
|
+
}
|
package/src/bcs/bcs.ts
CHANGED
|
@@ -360,7 +360,7 @@ export const PasskeyAuthenticator = bcs.struct('PasskeyAuthenticator', {
|
|
|
360
360
|
export const MoveObjectType = bcs.enum('MoveObjectType', {
|
|
361
361
|
Other: StructTag,
|
|
362
362
|
GasCoin: null,
|
|
363
|
-
|
|
363
|
+
StakedHaneul: null,
|
|
364
364
|
Coin: TypeTag,
|
|
365
365
|
AccumulatorBalanceWrapper: null,
|
|
366
366
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { parse } from 'valibot';
|
|
5
5
|
|
|
6
|
-
import { normalizeHaneulAddress,
|
|
6
|
+
import { normalizeHaneulAddress, normalizeHaneulObjectId, HANEUL_TYPE_ARG } from '../utils/index.js';
|
|
7
7
|
import type { ClientWithCoreApi } from './core.js';
|
|
8
8
|
import { ObjectRefSchema } from '../transactions/data/internal.js';
|
|
9
9
|
import type { CallArg, Command } from '../transactions/data/internal.js';
|
|
@@ -227,7 +227,7 @@ async function resolveObjectReferences(
|
|
|
227
227
|
|
|
228
228
|
const dedupedIds = [
|
|
229
229
|
...new Set(
|
|
230
|
-
objectsToResolve.map((input) =>
|
|
230
|
+
objectsToResolve.map((input) => normalizeHaneulObjectId(input.UnresolvedObject.objectId)),
|
|
231
231
|
),
|
|
232
232
|
];
|
|
233
233
|
|
package/src/client/core.ts
CHANGED
|
@@ -253,7 +253,7 @@ export abstract class CoreClient extends BaseClient implements HaneulClientTypes
|
|
|
253
253
|
if (transaction instanceof Uint8Array) {
|
|
254
254
|
transactionBytes = transaction;
|
|
255
255
|
} else {
|
|
256
|
-
transaction.setSenderIfNotSet(signer.
|
|
256
|
+
transaction.setSenderIfNotSet(signer.toHaneulAddress());
|
|
257
257
|
transactionBytes = await transaction.build({ client: this });
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -84,7 +84,7 @@ export abstract class Signer {
|
|
|
84
84
|
}: SignAndExecuteOptions): Promise<
|
|
85
85
|
HaneulClientTypes.TransactionResult<{ transaction: true; effects: true }>
|
|
86
86
|
> {
|
|
87
|
-
transaction.setSenderIfNotSet(this.
|
|
87
|
+
transaction.setSenderIfNotSet(this.toHaneulAddress());
|
|
88
88
|
const bytes = await transaction.build({ client });
|
|
89
89
|
const { signature } = await this.signTransaction(bytes);
|
|
90
90
|
|
|
@@ -95,8 +95,8 @@ export abstract class Signer {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
return this.getPublicKey().
|
|
98
|
+
toHaneulAddress(): string {
|
|
99
|
+
return this.getPublicKey().toHaneulAddress();
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
@@ -98,7 +98,7 @@ export abstract class PublicKey {
|
|
|
98
98
|
* Verifies that the public key is associated with the provided address
|
|
99
99
|
*/
|
|
100
100
|
verifyAddress(address: string): boolean {
|
|
101
|
-
return this.
|
|
101
|
+
return this.toHaneulAddress() === address;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -117,7 +117,7 @@ export abstract class PublicKey {
|
|
|
117
117
|
/**
|
|
118
118
|
* Return the Haneul address associated with this Ed25519 public key
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
toHaneulAddress(): string {
|
|
121
121
|
// Each hex char represents half a byte, hence hex address doubles the length
|
|
122
122
|
return normalizeHaneulAddress(
|
|
123
123
|
bytesToHex(blake2b(this.toSuiBytes(), { dkLen: 32 })).slice(0, HANEUL_ADDRESS_LENGTH * 2),
|
|
@@ -575,7 +575,7 @@ export interface StakingPool {
|
|
|
575
575
|
deactivationEpoch?: bigint;
|
|
576
576
|
/**
|
|
577
577
|
* The total number of HANEUL tokens in this pool, including the HANEUL in the rewards_pool, as well as in all the principal
|
|
578
|
-
* in the `
|
|
578
|
+
* in the `StakedHaneul` object, updated at epoch boundaries.
|
|
579
579
|
*
|
|
580
580
|
* @generated from protobuf field: optional uint64 sui_balance = 4;
|
|
581
581
|
*/
|
|
@@ -615,7 +615,7 @@ export interface StakingPool {
|
|
|
615
615
|
*
|
|
616
616
|
* @generated from protobuf field: optional uint64 pending_total_sui_withdraw = 9;
|
|
617
617
|
*/
|
|
618
|
-
|
|
618
|
+
pendingTotalHaneulWithdraw?: bigint;
|
|
619
619
|
/**
|
|
620
620
|
* Pending pool token withdrawn during the current epoch, emptied at epoch boundaries.
|
|
621
621
|
*
|
|
@@ -1127,7 +1127,7 @@ class StakingPool$Type extends MessageType<StakingPool> {
|
|
|
1127
1127
|
},
|
|
1128
1128
|
{
|
|
1129
1129
|
no: 4,
|
|
1130
|
-
name: '
|
|
1130
|
+
name: 'haneul_balance',
|
|
1131
1131
|
kind: 'scalar',
|
|
1132
1132
|
opt: true,
|
|
1133
1133
|
T: 4 /*ScalarType.UINT64*/,
|