@mysten/zklogin
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -25,3 +25,3 @@ "use strict"; | ||
generateRandomness: () => import_nonce.generateRandomness, | ||
getZkSignature: () => import_bcs.getZkSignature, | ||
getZkLoginSignature: () => import_zklogin.getZkLoginSignature, | ||
hashASCIIStrToField: () => import_utils.hashASCIIStrToField, | ||
@@ -33,3 +33,3 @@ jwtToAddress: () => import_address.jwtToAddress, | ||
var import_address = require("./address.js"); | ||
var import_bcs = require("./bcs.js"); | ||
var import_zklogin = require("@mysten/sui.js/zklogin"); | ||
var import_poseidon = require("./poseidon.js"); | ||
@@ -36,0 +36,0 @@ var import_nonce = require("./nonce.js"); |
# @mysten/zklogin | ||
## 0.1.5 | ||
### Patch Changes | ||
- 3764c464f: - use new zklogin package from @mysten/sui.js for some of the zklogin functionality | ||
- rename `getZkSignature` to `getZkLoginSignature` | ||
- 71e0a3197: - stop exporting `ZkSignatureInputs` | ||
- use `toBigEndianBytes` instead of `toBufferBE` that was renamed | ||
- Updated dependencies [781d073d9] | ||
- Updated dependencies [3764c464f] | ||
- Updated dependencies [1bc430161] | ||
- Updated dependencies [e4484852b] | ||
- Updated dependencies [e4484852b] | ||
- Updated dependencies [71e0a3197] | ||
- Updated dependencies [1bc430161] | ||
- @mysten/sui.js@0.43.0 | ||
- @mysten/bcs@0.8.0 | ||
## 0.1.4 | ||
@@ -4,0 +22,0 @@ |
@@ -25,8 +25,5 @@ "use strict"; | ||
module.exports = __toCommonJS(address_exports); | ||
var import_utils = require("@noble/hashes/utils"); | ||
var import_blake2b = require("@noble/hashes/blake2b"); | ||
var import_cryptography = require("@mysten/sui.js/cryptography"); | ||
var import_utils2 = require("@mysten/sui.js/utils"); | ||
var import_zklogin = require("@mysten/sui.js/zklogin"); | ||
var import_jose = require("jose"); | ||
var import_utils3 = require("./utils.js"); | ||
var import_utils = require("./utils.js"); | ||
function jwtToAddress(jwt, userSalt) { | ||
@@ -55,16 +52,4 @@ const decodedJWT = (0, import_jose.decodeJwt)(jwt); | ||
}) { | ||
const addressSeedBytesBigEndian = (0, import_utils3.toBufferBE)( | ||
(0, import_utils3.genAddressSeed)(userSalt, claimName, claimValue, aud), | ||
32 | ||
); | ||
const addressParamBytes = Buffer.from(iss); | ||
const tmp = new Uint8Array(2 + addressSeedBytesBigEndian.length + addressParamBytes.length); | ||
tmp.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.Zk]); | ||
tmp.set([addressParamBytes.length], 1); | ||
tmp.set(addressParamBytes, 2); | ||
tmp.set(addressSeedBytesBigEndian, 2 + addressParamBytes.length); | ||
return (0, import_utils2.normalizeSuiAddress)( | ||
(0, import_utils.bytesToHex)((0, import_blake2b.blake2b)(tmp, { dkLen: 32 })).slice(0, import_utils2.SUI_ADDRESS_LENGTH * 2) | ||
); | ||
return (0, import_zklogin.computeZkLoginAddressFromSeed)((0, import_utils.genAddressSeed)(userSalt, claimName, claimValue, aud), iss); | ||
} | ||
//# sourceMappingURL=address.js.map |
export { computeZkAddress, jwtToAddress } from './address.js'; | ||
export type { ComputeZKAddressOptions } from './address.js'; | ||
export { getZkSignature } from './bcs.js'; | ||
export type { ZkSignatureInputs } from './bcs.js'; | ||
export { getZkLoginSignature } from '@mysten/sui.js/zklogin'; | ||
export { poseidonHash } from './poseidon.js'; | ||
export { generateNonce, generateRandomness } from './nonce.js'; | ||
export { hashASCIIStrToField, genAddressSeed } from './utils.js'; |
@@ -25,3 +25,3 @@ "use strict"; | ||
generateRandomness: () => import_nonce.generateRandomness, | ||
getZkSignature: () => import_bcs.getZkSignature, | ||
getZkLoginSignature: () => import_zklogin.getZkLoginSignature, | ||
hashASCIIStrToField: () => import_utils.hashASCIIStrToField, | ||
@@ -33,3 +33,3 @@ jwtToAddress: () => import_address.jwtToAddress, | ||
var import_address = require("./address.js"); | ||
var import_bcs = require("./bcs.js"); | ||
var import_zklogin = require("@mysten/sui.js/zklogin"); | ||
var import_poseidon = require("./poseidon.js"); | ||
@@ -36,0 +36,0 @@ var import_nonce = require("./nonce.js"); |
@@ -25,7 +25,7 @@ "use strict"; | ||
module.exports = __toCommonJS(nonce_exports); | ||
var import_zklogin = require("@mysten/sui.js/zklogin"); | ||
var import_utils = require("@noble/hashes/utils"); | ||
var import_bigint_buffer = require("bigint-buffer"); | ||
var import_jose = require("jose"); | ||
var import_bigint_buffer = require("bigint-buffer"); | ||
var import_utils = require("@noble/hashes/utils"); | ||
var import_poseidon = require("./poseidon.js"); | ||
var import_utils2 = require("./utils.js"); | ||
const NONCE_LENGTH = 27; | ||
@@ -40,3 +40,3 @@ function generateRandomness() { | ||
const bigNum = (0, import_poseidon.poseidonHash)([eph_public_key_0, eph_public_key_1, maxEpoch, randomness]); | ||
const Z = (0, import_utils2.toBufferBE)(bigNum, 20); | ||
const Z = (0, import_zklogin.toBigEndianBytes)(bigNum, 20); | ||
const nonce = import_jose.base64url.encode(Z); | ||
@@ -43,0 +43,0 @@ if (nonce.length !== NONCE_LENGTH) { |
@@ -1,3 +0,1 @@ | ||
/// <reference types="node" /> | ||
export declare function toBufferBE(num: bigint, width: number): Buffer; | ||
/** | ||
@@ -4,0 +2,0 @@ * Splits an array into chunks of size chunk_size. If the array is not evenly |
@@ -23,4 +23,3 @@ "use strict"; | ||
genAddressSeed: () => genAddressSeed, | ||
hashASCIIStrToField: () => hashASCIIStrToField, | ||
toBufferBE: () => toBufferBE | ||
hashASCIIStrToField: () => hashASCIIStrToField | ||
}); | ||
@@ -33,6 +32,2 @@ module.exports = __toCommonJS(utils_exports); | ||
const PACK_WIDTH = 248; | ||
function toBufferBE(num, width) { | ||
const hex = num.toString(16); | ||
return Buffer.from(hex.padStart(width * 2, "0").slice(-width * 2), "hex"); | ||
} | ||
function chunkArray(array, chunk_size) { | ||
@@ -39,0 +34,0 @@ const chunks = Array(Math.ceil(array.length / chunk_size)); |
@@ -1,7 +0,4 @@ | ||
import { bytesToHex } from "@noble/hashes/utils"; | ||
import { blake2b } from "@noble/hashes/blake2b"; | ||
import { SIGNATURE_SCHEME_TO_FLAG } from "@mysten/sui.js/cryptography"; | ||
import { SUI_ADDRESS_LENGTH, normalizeSuiAddress } from "@mysten/sui.js/utils"; | ||
import { computeZkLoginAddressFromSeed } from "@mysten/sui.js/zklogin"; | ||
import { decodeJwt } from "jose"; | ||
import { genAddressSeed, toBufferBE } from "./utils.js"; | ||
import { genAddressSeed } from "./utils.js"; | ||
function jwtToAddress(jwt, userSalt) { | ||
@@ -30,15 +27,3 @@ const decodedJWT = decodeJwt(jwt); | ||
}) { | ||
const addressSeedBytesBigEndian = toBufferBE( | ||
genAddressSeed(userSalt, claimName, claimValue, aud), | ||
32 | ||
); | ||
const addressParamBytes = Buffer.from(iss); | ||
const tmp = new Uint8Array(2 + addressSeedBytesBigEndian.length + addressParamBytes.length); | ||
tmp.set([SIGNATURE_SCHEME_TO_FLAG.Zk]); | ||
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) | ||
); | ||
return computeZkLoginAddressFromSeed(genAddressSeed(userSalt, claimName, claimValue, aud), iss); | ||
} | ||
@@ -45,0 +30,0 @@ export { |
export { computeZkAddress, jwtToAddress } from './address.js'; | ||
export type { ComputeZKAddressOptions } from './address.js'; | ||
export { getZkSignature } from './bcs.js'; | ||
export type { ZkSignatureInputs } from './bcs.js'; | ||
export { getZkLoginSignature } from '@mysten/sui.js/zklogin'; | ||
export { poseidonHash } from './poseidon.js'; | ||
export { generateNonce, generateRandomness } from './nonce.js'; | ||
export { hashASCIIStrToField, genAddressSeed } from './utils.js'; |
import { computeZkAddress, jwtToAddress } from "./address.js"; | ||
import { getZkSignature } from "./bcs.js"; | ||
import { getZkLoginSignature } from "@mysten/sui.js/zklogin"; | ||
import { poseidonHash } from "./poseidon.js"; | ||
@@ -11,3 +11,3 @@ import { generateNonce, generateRandomness } from "./nonce.js"; | ||
generateRandomness, | ||
getZkSignature, | ||
getZkLoginSignature, | ||
hashASCIIStrToField, | ||
@@ -14,0 +14,0 @@ jwtToAddress, |
@@ -0,6 +1,6 @@ | ||
import { toBigEndianBytes } from "@mysten/sui.js/zklogin"; | ||
import { randomBytes } from "@noble/hashes/utils"; | ||
import { toBigIntBE } from "bigint-buffer"; | ||
import { base64url } from "jose"; | ||
import { toBigIntBE } from "bigint-buffer"; | ||
import { randomBytes } from "@noble/hashes/utils"; | ||
import { poseidonHash } from "./poseidon.js"; | ||
import { toBufferBE } from "./utils.js"; | ||
const NONCE_LENGTH = 27; | ||
@@ -15,3 +15,3 @@ function generateRandomness() { | ||
const bigNum = poseidonHash([eph_public_key_0, eph_public_key_1, maxEpoch, randomness]); | ||
const Z = toBufferBE(bigNum, 20); | ||
const Z = toBigEndianBytes(bigNum, 20); | ||
const nonce = base64url.encode(Z); | ||
@@ -18,0 +18,0 @@ if (nonce.length !== NONCE_LENGTH) { |
@@ -1,3 +0,1 @@ | ||
/// <reference types="node" /> | ||
export declare function toBufferBE(num: bigint, width: number): Buffer; | ||
/** | ||
@@ -4,0 +2,0 @@ * Splits an array into chunks of size chunk_size. If the array is not evenly |
@@ -6,6 +6,2 @@ import { poseidonHash } from "./poseidon.js"; | ||
const PACK_WIDTH = 248; | ||
function toBufferBE(num, width) { | ||
const hex = num.toString(16); | ||
return Buffer.from(hex.padStart(width * 2, "0").slice(-width * 2), "hex"); | ||
} | ||
function chunkArray(array, chunk_size) { | ||
@@ -43,5 +39,4 @@ const chunks = Array(Math.ceil(array.length / chunk_size)); | ||
genAddressSeed, | ||
hashASCIIStrToField, | ||
toBufferBE | ||
hashASCIIStrToField | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@mysten/zklogin", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Utilities for interacting with zkLogin in Sui", | ||
@@ -41,4 +41,4 @@ "license": "Apache-2.0", | ||
"tsx": "^3.12.7", | ||
"@mysten/bcs": "0.7.4", | ||
"@mysten/sui.js": "0.42.0" | ||
"@mysten/bcs": "0.8.0", | ||
"@mysten/sui.js": "0.43.0" | ||
}, | ||
@@ -45,0 +45,0 @@ "scripts": { |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { bytesToHex } from '@noble/hashes/utils'; | ||
import { blake2b } from '@noble/hashes/blake2b'; | ||
import { SIGNATURE_SCHEME_TO_FLAG } from '@mysten/sui.js/cryptography'; | ||
import { SUI_ADDRESS_LENGTH, normalizeSuiAddress } from '@mysten/sui.js/utils'; | ||
import { computeZkLoginAddressFromSeed } from '@mysten/sui.js/zklogin'; | ||
import { decodeJwt } from 'jose'; | ||
import { genAddressSeed, toBufferBE } from './utils.js'; | ||
import { genAddressSeed } from './utils.js'; | ||
export function jwtToAddress(jwt: string, userSalt: bigint) { | ||
@@ -45,16 +43,3 @@ const decodedJWT = decodeJwt(jwt); | ||
}: ComputeZKAddressOptions) { | ||
const addressSeedBytesBigEndian = toBufferBE( | ||
genAddressSeed(userSalt, claimName, claimValue, aud), | ||
32, | ||
); | ||
const addressParamBytes = Buffer.from(iss); | ||
const tmp = new Uint8Array(2 + addressSeedBytesBigEndian.length + addressParamBytes.length); | ||
tmp.set([SIGNATURE_SCHEME_TO_FLAG.Zk]); | ||
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), | ||
); | ||
return computeZkLoginAddressFromSeed(genAddressSeed(userSalt, claimName, claimValue, aud), iss); | ||
} |
@@ -7,4 +7,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
export { getZkSignature } from './bcs.js'; | ||
export type { ZkSignatureInputs } from './bcs.js'; | ||
export { getZkLoginSignature } from '@mysten/sui.js/zklogin'; | ||
@@ -11,0 +10,0 @@ export { poseidonHash } from './poseidon.js'; |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { PublicKey } from '@mysten/sui.js/cryptography'; | ||
import { toBigEndianBytes } from '@mysten/sui.js/zklogin'; | ||
import { randomBytes } from '@noble/hashes/utils'; | ||
import { toBigIntBE } from 'bigint-buffer'; | ||
import { base64url } from 'jose'; | ||
import { toBigIntBE } from 'bigint-buffer'; | ||
import { randomBytes } from '@noble/hashes/utils'; | ||
import { PublicKey } from '@mysten/sui.js/cryptography'; | ||
import { poseidonHash } from './poseidon.js'; | ||
import { toBufferBE } from './utils.js'; | ||
@@ -23,3 +24,3 @@ const NONCE_LENGTH = 27; | ||
const bigNum = poseidonHash([eph_public_key_0, eph_public_key_1, maxEpoch, randomness]); | ||
const Z = toBufferBE(bigNum, 20); | ||
const Z = toBigEndianBytes(bigNum, 20); | ||
const nonce = base64url.encode(Z); | ||
@@ -26,0 +27,0 @@ if (nonce.length !== NONCE_LENGTH) { |
@@ -11,8 +11,2 @@ // Copyright (c) Mysten Labs, Inc. | ||
// TODO: We need to rewrite this to not depend on Buffer. | ||
export function toBufferBE(num: bigint, width: number) { | ||
const hex = num.toString(16); | ||
return Buffer.from(hex.padStart(width * 2, '0').slice(-width * 2), 'hex'); | ||
} | ||
/** | ||
@@ -19,0 +13,0 @@ * Splits an array into chunks of size chunk_size. If the array is not evenly |
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
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
130397
44
691
+ Added@mysten/bcs@0.8.0(transitive)
+ Added@mysten/sui.js@0.43.0(transitive)
- Removed@mysten/bcs@0.7.4(transitive)
- Removed@mysten/sui.js@0.42.0(transitive)
Updated@mysten/bcs@0.8.0
Updated@mysten/sui.js@0.43.0