UNPKG

@mysten/sui

Version:

Sui TypeScript API(Work in Progress)

25 lines (24 loc) 1.05 kB
import { blake2b } from "@noble/hashes/blake2b"; import { bytesToHex } from "@noble/hashes/utils"; import { SIGNATURE_SCHEME_TO_FLAG } from "../cryptography/signature-scheme.js"; import { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from "../utils/index.js"; import { toBigEndianBytes } from "./utils.js"; function computeZkLoginAddressFromSeed(addressSeed, iss) { const addressSeedBytesBigEndian = toBigEndianBytes(addressSeed, 32); if (iss === "accounts.google.com") { iss = "https://accounts.google.com"; } const addressParamBytes = new TextEncoder().encode(iss); const tmp = new Uint8Array(2 + addressSeedBytesBigEndian.length + addressParamBytes.length); tmp.set([SIGNATURE_SCHEME_TO_FLAG.ZkLogin]); tmp.set([addressParamBytes.length], 1); tmp.set(addressParamBytes, 2); tmp.set(addressSeedBytesBigEndian, 2 + addressParamBytes.length); return normalizeSuiAddress( bytesToHex(blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2) ); } export { computeZkLoginAddressFromSeed }; //# sourceMappingURL=address.js.map