@mysten/zklogin
Advanced tools
Comparing version 0.1.1 to 0.1.2
# @mysten/zklogin | ||
## 0.1.2 | ||
### Patch Changes | ||
- d0750ea0f: rename pin to salt | ||
- a82600f2d: fix nonce calculation | ||
- Updated dependencies [24c21e1f0] | ||
- @mysten/sui.js@0.41.1 | ||
## 0.1.1 | ||
@@ -4,0 +13,0 @@ |
@@ -1,9 +0,9 @@ | ||
export declare function jwtToAddress(jwt: string, userPin: bigint): string; | ||
export declare function jwtToAddress(jwt: string, userSalt: bigint): string; | ||
export interface ComputeZKAddressOptions { | ||
claimName: string; | ||
claimValue: string; | ||
userPin: bigint; | ||
userSalt: bigint; | ||
iss: string; | ||
aud: string; | ||
} | ||
export declare function computeZkAddress({ claimName, claimValue, iss, aud, userPin, }: ComputeZKAddressOptions): string; | ||
export declare function computeZkAddress({ claimName, claimValue, iss, aud, userSalt, }: ComputeZKAddressOptions): string; |
@@ -32,3 +32,3 @@ "use strict"; | ||
var import_utils3 = require("./utils.js"); | ||
function jwtToAddress(jwt, userPin) { | ||
function jwtToAddress(jwt, userSalt) { | ||
const decodedJWT = (0, import_jose.decodeJwt)(jwt); | ||
@@ -42,3 +42,3 @@ if (!decodedJWT.sub || !decodedJWT.iss || !decodedJWT.aud || !decodedJWT.email || typeof decodedJWT.email !== "string") { | ||
return computeZkAddress({ | ||
userPin, | ||
userSalt, | ||
claimName: "sub", | ||
@@ -55,5 +55,5 @@ claimValue: decodedJWT.sub, | ||
aud, | ||
userPin | ||
userSalt | ||
}) { | ||
const addressSeedBytesBigEndian = (0, import_utils3.toBufferBE)((0, import_utils3.genAddressSeed)(userPin, claimName, claimValue), 32); | ||
const addressSeedBytesBigEndian = (0, import_utils3.toBufferBE)((0, import_utils3.genAddressSeed)(userSalt, claimName, claimValue), 32); | ||
const addressParamBytes = import_bcs.zkBcs.ser("AddressParams", { iss, aud }).toBytes(); | ||
@@ -60,0 +60,0 @@ const tmp = new Uint8Array(1 + addressSeedBytesBigEndian.length + addressParamBytes.length); |
@@ -30,3 +30,3 @@ "use strict"; | ||
function generateNonce(publicKey, maxEpoch, randomness) { | ||
const publicKeyBytes = (0, import_bigint_buffer.toBigIntBE)(Buffer.from(publicKey.toRawBytes())); | ||
const publicKeyBytes = (0, import_bigint_buffer.toBigIntBE)(Buffer.from(publicKey.toSuiBytes())); | ||
const eph_public_key_0 = publicKeyBytes / 2n ** 128n; | ||
@@ -33,0 +33,0 @@ const eph_public_key_1 = publicKeyBytes % 2n ** 128n; |
@@ -15,2 +15,2 @@ /// <reference types="node" /> | ||
export declare function hashASCIIStrToField(str: string, maxSize: number): bigint; | ||
export declare function genAddressSeed(pin: bigint, name: string, value: string, max_name_length?: number, max_value_length?: number): bigint; | ||
export declare function genAddressSeed(salt: bigint, name: string, value: string, max_name_length?: number, max_value_length?: number): bigint; |
@@ -68,9 +68,9 @@ "use strict"; | ||
} | ||
function genAddressSeed(pin, name, value, max_name_length = MAX_KEY_CLAIM_NAME_LENGTH, max_value_length = MAX_KEY_CLAIM_VALUE_LENGTH) { | ||
function genAddressSeed(salt, name, value, max_name_length = MAX_KEY_CLAIM_NAME_LENGTH, max_value_length = MAX_KEY_CLAIM_VALUE_LENGTH) { | ||
return (0, import_poseidon.poseidonHash)([ | ||
hashASCIIStrToField(name, max_name_length), | ||
hashASCIIStrToField(value, max_value_length), | ||
(0, import_poseidon.poseidonHash)([pin]) | ||
(0, import_poseidon.poseidonHash)([salt]) | ||
]); | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -1,9 +0,9 @@ | ||
export declare function jwtToAddress(jwt: string, userPin: bigint): string; | ||
export declare function jwtToAddress(jwt: string, userSalt: bigint): string; | ||
export interface ComputeZKAddressOptions { | ||
claimName: string; | ||
claimValue: string; | ||
userPin: bigint; | ||
userSalt: bigint; | ||
iss: string; | ||
aud: string; | ||
} | ||
export declare function computeZkAddress({ claimName, claimValue, iss, aud, userPin, }: ComputeZKAddressOptions): string; | ||
export declare function computeZkAddress({ claimName, claimValue, iss, aud, userSalt, }: ComputeZKAddressOptions): string; |
@@ -8,3 +8,3 @@ import { bytesToHex } from "@noble/hashes/utils"; | ||
import { genAddressSeed, toBufferBE } from "./utils.js"; | ||
function jwtToAddress(jwt, userPin) { | ||
function jwtToAddress(jwt, userSalt) { | ||
const decodedJWT = decodeJwt(jwt); | ||
@@ -18,3 +18,3 @@ if (!decodedJWT.sub || !decodedJWT.iss || !decodedJWT.aud || !decodedJWT.email || typeof decodedJWT.email !== "string") { | ||
return computeZkAddress({ | ||
userPin, | ||
userSalt, | ||
claimName: "sub", | ||
@@ -31,5 +31,5 @@ claimValue: decodedJWT.sub, | ||
aud, | ||
userPin | ||
userSalt | ||
}) { | ||
const addressSeedBytesBigEndian = toBufferBE(genAddressSeed(userPin, claimName, claimValue), 32); | ||
const addressSeedBytesBigEndian = toBufferBE(genAddressSeed(userSalt, claimName, claimValue), 32); | ||
const addressParamBytes = zkBcs.ser("AddressParams", { iss, aud }).toBytes(); | ||
@@ -36,0 +36,0 @@ const tmp = new Uint8Array(1 + addressSeedBytesBigEndian.length + addressParamBytes.length); |
@@ -7,3 +7,3 @@ import { base64url } from "jose"; | ||
function generateNonce(publicKey, maxEpoch, randomness) { | ||
const publicKeyBytes = toBigIntBE(Buffer.from(publicKey.toRawBytes())); | ||
const publicKeyBytes = toBigIntBE(Buffer.from(publicKey.toSuiBytes())); | ||
const eph_public_key_0 = publicKeyBytes / 2n ** 128n; | ||
@@ -10,0 +10,0 @@ const eph_public_key_1 = publicKeyBytes % 2n ** 128n; |
@@ -15,2 +15,2 @@ /// <reference types="node" /> | ||
export declare function hashASCIIStrToField(str: string, maxSize: number): bigint; | ||
export declare function genAddressSeed(pin: bigint, name: string, value: string, max_name_length?: number, max_value_length?: number): bigint; | ||
export declare function genAddressSeed(salt: bigint, name: string, value: string, max_name_length?: number, max_value_length?: number): bigint; |
@@ -41,7 +41,7 @@ import { poseidonHash } from "./poseidon.js"; | ||
} | ||
function genAddressSeed(pin, name, value, max_name_length = MAX_KEY_CLAIM_NAME_LENGTH, max_value_length = MAX_KEY_CLAIM_VALUE_LENGTH) { | ||
function genAddressSeed(salt, name, value, max_name_length = MAX_KEY_CLAIM_NAME_LENGTH, max_value_length = MAX_KEY_CLAIM_VALUE_LENGTH) { | ||
return poseidonHash([ | ||
hashASCIIStrToField(name, max_name_length), | ||
hashASCIIStrToField(value, max_value_length), | ||
poseidonHash([pin]) | ||
poseidonHash([salt]) | ||
]); | ||
@@ -48,0 +48,0 @@ } |
{ | ||
"name": "@mysten/zklogin", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Utilities for interacting with zkLogin in Sui", | ||
@@ -42,3 +42,3 @@ "license": "Apache-2.0", | ||
"@mysten/bcs": "0.7.3", | ||
"@mysten/sui.js": "0.41.0" | ||
"@mysten/sui.js": "0.41.1" | ||
}, | ||
@@ -45,0 +45,0 @@ "scripts": { |
@@ -12,3 +12,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
export function jwtToAddress(jwt: string, userPin: bigint) { | ||
export function jwtToAddress(jwt: string, userSalt: bigint) { | ||
const decodedJWT = decodeJwt(jwt); | ||
@@ -30,3 +30,3 @@ if ( | ||
return computeZkAddress({ | ||
userPin, | ||
userSalt, | ||
claimName: 'sub', | ||
@@ -42,3 +42,3 @@ claimValue: decodedJWT.sub, | ||
claimValue: string; | ||
userPin: bigint; | ||
userSalt: bigint; | ||
iss: string; | ||
@@ -53,5 +53,5 @@ aud: string; | ||
aud, | ||
userPin, | ||
userSalt, | ||
}: ComputeZKAddressOptions) { | ||
const addressSeedBytesBigEndian = toBufferBE(genAddressSeed(userPin, claimName, claimValue), 32); | ||
const addressSeedBytesBigEndian = toBufferBE(genAddressSeed(userSalt, claimName, claimValue), 32); | ||
const addressParamBytes = zkBcs.ser('AddressParams', { iss, aud }).toBytes(); | ||
@@ -58,0 +58,0 @@ |
@@ -13,3 +13,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
export function generateNonce(publicKey: PublicKey, maxEpoch: number, randomness: bigint) { | ||
const publicKeyBytes = toBigIntBE(Buffer.from(publicKey.toRawBytes())); | ||
const publicKeyBytes = toBigIntBE(Buffer.from(publicKey.toSuiBytes())); | ||
const eph_public_key_0 = publicKeyBytes / 2n ** 128n; | ||
@@ -16,0 +16,0 @@ const eph_public_key_1 = publicKeyBytes % 2n ** 128n; |
@@ -73,3 +73,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
export function genAddressSeed( | ||
pin: bigint, | ||
salt: bigint, | ||
name: string, | ||
@@ -83,4 +83,4 @@ value: string, | ||
hashASCIIStrToField(value, max_value_length), | ||
poseidonHash([pin]), | ||
poseidonHash([salt]), | ||
]); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145251
+ Added@mysten/sui.js@0.41.1(transitive)
- Removed@mysten/sui.js@0.41.0(transitive)
Updated@mysten/sui.js@0.41.1