@dynamic-labs/ethereum-aa-zksync 4.14.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.
@@ -0,0 +1,102 @@
1
+ export declare const AAFactoryABI: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly internalType: "bytes32";
4
+ readonly name: "_beaconProxyBytecodeHash";
5
+ readonly type: "bytes32";
6
+ }, {
7
+ readonly internalType: "address";
8
+ readonly name: "_beacon";
9
+ readonly type: "address";
10
+ }];
11
+ readonly stateMutability: "nonpayable";
12
+ readonly type: "constructor";
13
+ }, {
14
+ readonly inputs: readonly [{
15
+ readonly internalType: "address";
16
+ readonly name: "account";
17
+ readonly type: "address";
18
+ }];
19
+ readonly name: "ACCOUNT_ALREADY_EXISTS";
20
+ readonly type: "error";
21
+ }, {
22
+ readonly anonymous: false;
23
+ readonly inputs: readonly [{
24
+ readonly indexed: true;
25
+ readonly internalType: "address";
26
+ readonly name: "accountAddress";
27
+ readonly type: "address";
28
+ }, {
29
+ readonly indexed: false;
30
+ readonly internalType: "bytes32";
31
+ readonly name: "uniqueAccountId";
32
+ readonly type: "bytes32";
33
+ }];
34
+ readonly name: "AccountCreated";
35
+ readonly type: "event";
36
+ }, {
37
+ readonly inputs: readonly [{
38
+ readonly internalType: "bytes32";
39
+ readonly name: "accountId";
40
+ readonly type: "bytes32";
41
+ }];
42
+ readonly name: "accountMappings";
43
+ readonly outputs: readonly [{
44
+ readonly internalType: "address";
45
+ readonly name: "deployedAccount";
46
+ readonly type: "address";
47
+ }];
48
+ readonly stateMutability: "view";
49
+ readonly type: "function";
50
+ }, {
51
+ readonly inputs: readonly [];
52
+ readonly name: "beacon";
53
+ readonly outputs: readonly [{
54
+ readonly internalType: "address";
55
+ readonly name: "";
56
+ readonly type: "address";
57
+ }];
58
+ readonly stateMutability: "view";
59
+ readonly type: "function";
60
+ }, {
61
+ readonly inputs: readonly [];
62
+ readonly name: "beaconProxyBytecodeHash";
63
+ readonly outputs: readonly [{
64
+ readonly internalType: "bytes32";
65
+ readonly name: "";
66
+ readonly type: "bytes32";
67
+ }];
68
+ readonly stateMutability: "view";
69
+ readonly type: "function";
70
+ }, {
71
+ readonly inputs: readonly [{
72
+ readonly internalType: "bytes32";
73
+ readonly name: "uniqueId";
74
+ readonly type: "bytes32";
75
+ }, {
76
+ readonly internalType: "bytes[]";
77
+ readonly name: "initialValidators";
78
+ readonly type: "bytes[]";
79
+ }, {
80
+ readonly internalType: "address[]";
81
+ readonly name: "initialK1Owners";
82
+ readonly type: "address[]";
83
+ }];
84
+ readonly name: "deployProxySsoAccount";
85
+ readonly outputs: readonly [{
86
+ readonly internalType: "address";
87
+ readonly name: "accountAddress";
88
+ readonly type: "address";
89
+ }];
90
+ readonly stateMutability: "nonpayable";
91
+ readonly type: "function";
92
+ }, {
93
+ readonly inputs: readonly [];
94
+ readonly name: "getEncodedBeacon";
95
+ readonly outputs: readonly [{
96
+ readonly internalType: "bytes";
97
+ readonly name: "";
98
+ readonly type: "bytes";
99
+ }];
100
+ readonly stateMutability: "view";
101
+ readonly type: "function";
102
+ }];
@@ -0,0 +1,84 @@
1
+ 'use client'
2
+ const AAFactoryABI = [
3
+ {
4
+ inputs: [
5
+ {
6
+ internalType: 'bytes32',
7
+ name: '_beaconProxyBytecodeHash',
8
+ type: 'bytes32',
9
+ },
10
+ { internalType: 'address', name: '_beacon', type: 'address' },
11
+ ],
12
+ stateMutability: 'nonpayable',
13
+ type: 'constructor',
14
+ },
15
+ {
16
+ inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
17
+ name: 'ACCOUNT_ALREADY_EXISTS',
18
+ type: 'error',
19
+ },
20
+ {
21
+ anonymous: false,
22
+ inputs: [
23
+ {
24
+ indexed: true,
25
+ internalType: 'address',
26
+ name: 'accountAddress',
27
+ type: 'address',
28
+ },
29
+ {
30
+ indexed: false,
31
+ internalType: 'bytes32',
32
+ name: 'uniqueAccountId',
33
+ type: 'bytes32',
34
+ },
35
+ ],
36
+ name: 'AccountCreated',
37
+ type: 'event',
38
+ },
39
+ {
40
+ inputs: [{ internalType: 'bytes32', name: 'accountId', type: 'bytes32' }],
41
+ name: 'accountMappings',
42
+ outputs: [
43
+ { internalType: 'address', name: 'deployedAccount', type: 'address' },
44
+ ],
45
+ stateMutability: 'view',
46
+ type: 'function',
47
+ },
48
+ {
49
+ inputs: [],
50
+ name: 'beacon',
51
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
52
+ stateMutability: 'view',
53
+ type: 'function',
54
+ },
55
+ {
56
+ inputs: [],
57
+ name: 'beaconProxyBytecodeHash',
58
+ outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
59
+ stateMutability: 'view',
60
+ type: 'function',
61
+ },
62
+ {
63
+ inputs: [
64
+ { internalType: 'bytes32', name: 'uniqueId', type: 'bytes32' },
65
+ { internalType: 'bytes[]', name: 'initialValidators', type: 'bytes[]' },
66
+ { internalType: 'address[]', name: 'initialK1Owners', type: 'address[]' },
67
+ ],
68
+ name: 'deployProxySsoAccount',
69
+ outputs: [
70
+ { internalType: 'address', name: 'accountAddress', type: 'address' },
71
+ ],
72
+ stateMutability: 'nonpayable',
73
+ type: 'function',
74
+ },
75
+ {
76
+ inputs: [],
77
+ name: 'getEncodedBeacon',
78
+ outputs: [{ internalType: 'bytes', name: '', type: 'bytes' }],
79
+ stateMutability: 'view',
80
+ type: 'function',
81
+ },
82
+ ];
83
+
84
+ export { AAFactoryABI };
@@ -0,0 +1,97 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var utils = require('zksync-sso/utils');
8
+ var viem = require('viem');
9
+ var abi = require('./abi.cjs');
10
+ var passkeys = require('./passkeys.cjs');
11
+ var getSalt = require('./getSalt.cjs');
12
+
13
+ /**
14
+ * Returns the parameters needed for deploying the smart account
15
+ * @returns Deployment parameters object
16
+ * @testable This method can be overridden in tests
17
+ */
18
+ const getDeploymentParameters = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ eoaAddress, enablePasskeys, passkeyAddress, sessionKeyAddress, saltText, }) {
19
+ const initialValidators = [];
20
+ const initialK1Owners = [eoaAddress];
21
+ // TODO: revisit this logic, maybe we should always add the passkey module data,
22
+ // otherwise if people active passkeys later, old accounts will not be able to use passkey module
23
+ if (enablePasskeys && passkeyAddress) {
24
+ const encodedPasskeyModuleData = yield passkeys.getEncodedPasskeyModuleData({
25
+ passkeyAddress,
26
+ });
27
+ initialValidators.push(encodedPasskeyModuleData);
28
+ }
29
+ if (sessionKeyAddress) {
30
+ const encodedSessionKeyModuleData = utils.encodeModuleData({
31
+ address: sessionKeyAddress,
32
+ parameters: '0x',
33
+ });
34
+ initialValidators.push(encodedSessionKeyModuleData);
35
+ }
36
+ return {
37
+ initialK1Owners,
38
+ initialValidators,
39
+ salt: getSalt.getSalt(saltText),
40
+ };
41
+ });
42
+ /**
43
+ * Simulates the smart account deployment
44
+ * @param publicClient - The public client to use for simulation
45
+ * @param walletClient - The wallet client to use for account information
46
+ * @param params - The deployment parameters
47
+ * @returns The simulation result
48
+ * @throws {ZkSyncConnectorError} If simulation fails
49
+ * @testable This method can be mocked in tests
50
+ */
51
+ const simulateAccountDeployment = (publicClient_1, walletClient_1, params_1, factoryAddress_1, ...args_1) => _tslib.__awaiter(void 0, [publicClient_1, walletClient_1, params_1, factoryAddress_1, ...args_1], void 0, function* (publicClient, walletClient, params, factoryAddress, checkBalance = true) {
52
+ var _b, _c, _d;
53
+ // this is to keep the same salt as calculated on zksync sso package
54
+ const salt = viem.keccak256(viem.toHex(params.salt));
55
+ const gasEstimate = yield publicClient.estimateContractGas({
56
+ abi: abi.AAFactoryABI,
57
+ account: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
58
+ address: factoryAddress,
59
+ args: [salt, params.initialValidators, params.initialK1Owners],
60
+ functionName: 'deployProxySsoAccount',
61
+ });
62
+ if (checkBalance) {
63
+ const balance = yield publicClient.getBalance({
64
+ address: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
65
+ });
66
+ if (balance < gasEstimate) {
67
+ throw new Error('Insufficient balance to deploy account');
68
+ }
69
+ }
70
+ // Simulate the contract call
71
+ return publicClient.simulateContract({
72
+ abi: abi.AAFactoryABI,
73
+ account: (_d = walletClient.account) === null || _d === void 0 ? void 0 : _d.address,
74
+ address: factoryAddress,
75
+ args: [salt, params.initialValidators, params.initialK1Owners],
76
+ functionName: 'deployProxySsoAccount',
77
+ });
78
+ });
79
+ /**
80
+ * Executes the smart account deployment transaction
81
+ * @param walletClient - The wallet client to use for transaction execution
82
+ * @param request - The deployment request object containing transaction parameters
83
+ * @returns Promise that resolves when the deployment transaction is confirmed
84
+ * @throws {DynamicError} If the smart account address is not initialized
85
+ * @throws {Error} If transaction execution or confirmation fails
86
+ */
87
+ const executeAccountDeployment = (walletClient, publicClient, request, smartAccountAddress) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
88
+ if (!smartAccountAddress) {
89
+ throw new Error('Smart account address is not initialized');
90
+ }
91
+ const tx = yield walletClient.writeContract(request);
92
+ yield publicClient.waitForTransactionReceipt({ hash: tx });
93
+ });
94
+
95
+ exports.executeAccountDeployment = executeAccountDeployment;
96
+ exports.getDeploymentParameters = getDeploymentParameters;
97
+ exports.simulateAccountDeployment = simulateAccountDeployment;
@@ -0,0 +1,37 @@
1
+ import { PublicClient, WalletClient } from 'viem';
2
+ export interface DeploymentParams {
3
+ initialK1Owners: `0x${string}`[];
4
+ initialValidators: `0x${string}`[];
5
+ salt: `0x${string}`;
6
+ }
7
+ /**
8
+ * Returns the parameters needed for deploying the smart account
9
+ * @returns Deployment parameters object
10
+ * @testable This method can be overridden in tests
11
+ */
12
+ export declare const getDeploymentParameters: ({ eoaAddress, enablePasskeys, passkeyAddress, sessionKeyAddress, saltText, }: {
13
+ eoaAddress: `0x${string}`;
14
+ enablePasskeys: boolean;
15
+ passkeyAddress: `0x${string}`;
16
+ sessionKeyAddress: `0x${string}`;
17
+ saltText?: string;
18
+ }) => Promise<DeploymentParams>;
19
+ /**
20
+ * Simulates the smart account deployment
21
+ * @param publicClient - The public client to use for simulation
22
+ * @param walletClient - The wallet client to use for account information
23
+ * @param params - The deployment parameters
24
+ * @returns The simulation result
25
+ * @throws {ZkSyncConnectorError} If simulation fails
26
+ * @testable This method can be mocked in tests
27
+ */
28
+ export declare const simulateAccountDeployment: (publicClient: PublicClient, walletClient: WalletClient, params: DeploymentParams, factoryAddress: `0x${string}`, checkBalance?: boolean) => Promise<any>;
29
+ /**
30
+ * Executes the smart account deployment transaction
31
+ * @param walletClient - The wallet client to use for transaction execution
32
+ * @param request - The deployment request object containing transaction parameters
33
+ * @returns Promise that resolves when the deployment transaction is confirmed
34
+ * @throws {DynamicError} If the smart account address is not initialized
35
+ * @throws {Error} If transaction execution or confirmation fails
36
+ */
37
+ export declare const executeAccountDeployment: (walletClient: WalletClient, publicClient: PublicClient, request: any, smartAccountAddress: `0x${string}`) => Promise<void>;
@@ -0,0 +1,91 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { encodeModuleData } from 'zksync-sso/utils';
4
+ import { keccak256, toHex } from 'viem';
5
+ import { AAFactoryABI } from './abi.js';
6
+ import { getEncodedPasskeyModuleData } from './passkeys.js';
7
+ import { getSalt } from './getSalt.js';
8
+
9
+ /**
10
+ * Returns the parameters needed for deploying the smart account
11
+ * @returns Deployment parameters object
12
+ * @testable This method can be overridden in tests
13
+ */
14
+ const getDeploymentParameters = (_a) => __awaiter(void 0, [_a], void 0, function* ({ eoaAddress, enablePasskeys, passkeyAddress, sessionKeyAddress, saltText, }) {
15
+ const initialValidators = [];
16
+ const initialK1Owners = [eoaAddress];
17
+ // TODO: revisit this logic, maybe we should always add the passkey module data,
18
+ // otherwise if people active passkeys later, old accounts will not be able to use passkey module
19
+ if (enablePasskeys && passkeyAddress) {
20
+ const encodedPasskeyModuleData = yield getEncodedPasskeyModuleData({
21
+ passkeyAddress,
22
+ });
23
+ initialValidators.push(encodedPasskeyModuleData);
24
+ }
25
+ if (sessionKeyAddress) {
26
+ const encodedSessionKeyModuleData = encodeModuleData({
27
+ address: sessionKeyAddress,
28
+ parameters: '0x',
29
+ });
30
+ initialValidators.push(encodedSessionKeyModuleData);
31
+ }
32
+ return {
33
+ initialK1Owners,
34
+ initialValidators,
35
+ salt: getSalt(saltText),
36
+ };
37
+ });
38
+ /**
39
+ * Simulates the smart account deployment
40
+ * @param publicClient - The public client to use for simulation
41
+ * @param walletClient - The wallet client to use for account information
42
+ * @param params - The deployment parameters
43
+ * @returns The simulation result
44
+ * @throws {ZkSyncConnectorError} If simulation fails
45
+ * @testable This method can be mocked in tests
46
+ */
47
+ const simulateAccountDeployment = (publicClient_1, walletClient_1, params_1, factoryAddress_1, ...args_1) => __awaiter(void 0, [publicClient_1, walletClient_1, params_1, factoryAddress_1, ...args_1], void 0, function* (publicClient, walletClient, params, factoryAddress, checkBalance = true) {
48
+ var _b, _c, _d;
49
+ // this is to keep the same salt as calculated on zksync sso package
50
+ const salt = keccak256(toHex(params.salt));
51
+ const gasEstimate = yield publicClient.estimateContractGas({
52
+ abi: AAFactoryABI,
53
+ account: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
54
+ address: factoryAddress,
55
+ args: [salt, params.initialValidators, params.initialK1Owners],
56
+ functionName: 'deployProxySsoAccount',
57
+ });
58
+ if (checkBalance) {
59
+ const balance = yield publicClient.getBalance({
60
+ address: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
61
+ });
62
+ if (balance < gasEstimate) {
63
+ throw new Error('Insufficient balance to deploy account');
64
+ }
65
+ }
66
+ // Simulate the contract call
67
+ return publicClient.simulateContract({
68
+ abi: AAFactoryABI,
69
+ account: (_d = walletClient.account) === null || _d === void 0 ? void 0 : _d.address,
70
+ address: factoryAddress,
71
+ args: [salt, params.initialValidators, params.initialK1Owners],
72
+ functionName: 'deployProxySsoAccount',
73
+ });
74
+ });
75
+ /**
76
+ * Executes the smart account deployment transaction
77
+ * @param walletClient - The wallet client to use for transaction execution
78
+ * @param request - The deployment request object containing transaction parameters
79
+ * @returns Promise that resolves when the deployment transaction is confirmed
80
+ * @throws {DynamicError} If the smart account address is not initialized
81
+ * @throws {Error} If transaction execution or confirmation fails
82
+ */
83
+ const executeAccountDeployment = (walletClient, publicClient, request, smartAccountAddress) => __awaiter(void 0, void 0, void 0, function* () {
84
+ if (!smartAccountAddress) {
85
+ throw new Error('Smart account address is not initialized');
86
+ }
87
+ const tx = yield walletClient.writeContract(request);
88
+ yield publicClient.waitForTransactionReceipt({ hash: tx });
89
+ });
90
+
91
+ export { executeAccountDeployment, getDeploymentParameters, simulateAccountDeployment };
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var viem = require('viem');
7
+
8
+ const getSalt = (saltText = 'DynamicLabs') => `0x${Buffer.from(viem.toBytes(saltText, { size: 32 })).toString('hex')}`;
9
+
10
+ exports.getSalt = getSalt;
@@ -0,0 +1 @@
1
+ export declare const getSalt: (saltText?: string) => `0x${string}`;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { toBytes } from 'viem';
3
+
4
+ const getSalt = (saltText = 'DynamicLabs') => `0x${Buffer.from(toBytes(saltText, { size: 32 })).toString('hex')}`;
5
+
6
+ export { getSalt };
@@ -0,0 +1,5 @@
1
+ export * from './getSalt';
2
+ export * from './passkeys';
3
+ export * from './deployment';
4
+ export * from './network';
5
+ export * from './isZKsyncConnector';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isZKsyncConnector = (connector) => (connector === null || connector === void 0 ? void 0 : connector.key) === 'zksync';
7
+
8
+ exports.isZKsyncConnector = isZKsyncConnector;
@@ -0,0 +1,3 @@
1
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ import { ZKsyncConnector } from '../connector';
3
+ export declare const isZKsyncConnector: (connector: ZKsyncConnector | WalletConnector) => connector is ZKsyncConnector;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const isZKsyncConnector = (connector) => (connector === null || connector === void 0 ? void 0 : connector.key) === 'zksync';
3
+
4
+ export { isZKsyncConnector };
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+
8
+ const ensureEoaConnectorNetwork = (eoaConnector, chainId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
9
+ const eoaNetwork = yield eoaConnector.getNetwork();
10
+ if (Number(eoaNetwork) !== chainId) {
11
+ yield eoaConnector.switchNetwork({
12
+ networkChainId: chainId,
13
+ });
14
+ }
15
+ });
16
+
17
+ exports.ensureEoaConnectorNetwork = ensureEoaConnectorNetwork;
@@ -0,0 +1,2 @@
1
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ export declare const ensureEoaConnectorNetwork: (eoaConnector: WalletConnector, chainId: number) => Promise<void>;
@@ -0,0 +1,13 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+
4
+ const ensureEoaConnectorNetwork = (eoaConnector, chainId) => __awaiter(void 0, void 0, void 0, function* () {
5
+ const eoaNetwork = yield eoaConnector.getNetwork();
6
+ if (Number(eoaNetwork) !== chainId) {
7
+ yield eoaConnector.switchNetwork({
8
+ networkChainId: chainId,
9
+ });
10
+ }
11
+ });
12
+
13
+ export { ensureEoaConnectorNetwork };
@@ -0,0 +1,41 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var utils$1 = require('zksync-sso/utils');
8
+ var utils = require('@dynamic-labs/utils');
9
+
10
+ /**
11
+ * Retrieves and encodes passkey module data for smart account deployment
12
+ * @returns Encoded passkey module data as a hex string
13
+ * @throws {Error} If credential public key or ID is not found
14
+ * @private
15
+ */
16
+ const getEncodedPasskeyModuleData = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ passkeyAddress, }) {
17
+ if (!passkeyAddress) {
18
+ throw new Error('Passkey address is not initialized');
19
+ }
20
+ const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
21
+ if (!storedCredentialPublicKey) {
22
+ throw new Error('Credential public key not found');
23
+ }
24
+ const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
25
+ const credentialId = utils.StorageService.getItem('credentialId');
26
+ if (!credentialId) {
27
+ throw new Error('Credential ID not found');
28
+ }
29
+ const passkeyPublicKey = utils$1.getPublicKeyBytesFromPasskeySignature(credentialPublicKey);
30
+ const encodedPasskeyParameters = utils$1.encodePasskeyModuleParameters({
31
+ credentialId: credentialId,
32
+ expectedOrigin: window.location.origin,
33
+ passkeyPublicKey,
34
+ });
35
+ return utils$1.encodeModuleData({
36
+ address: passkeyAddress,
37
+ parameters: encodedPasskeyParameters,
38
+ });
39
+ });
40
+
41
+ exports.getEncodedPasskeyModuleData = getEncodedPasskeyModuleData;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Retrieves and encodes passkey module data for smart account deployment
3
+ * @returns Encoded passkey module data as a hex string
4
+ * @throws {Error} If credential public key or ID is not found
5
+ * @private
6
+ */
7
+ export declare const getEncodedPasskeyModuleData: ({ passkeyAddress, }: {
8
+ passkeyAddress?: `0x${string}`;
9
+ }) => Promise<`0x${string}`>;
@@ -0,0 +1,37 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { getPublicKeyBytesFromPasskeySignature, encodePasskeyModuleParameters, encodeModuleData } from 'zksync-sso/utils';
4
+ import { StorageService } from '@dynamic-labs/utils';
5
+
6
+ /**
7
+ * Retrieves and encodes passkey module data for smart account deployment
8
+ * @returns Encoded passkey module data as a hex string
9
+ * @throws {Error} If credential public key or ID is not found
10
+ * @private
11
+ */
12
+ const getEncodedPasskeyModuleData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ passkeyAddress, }) {
13
+ if (!passkeyAddress) {
14
+ throw new Error('Passkey address is not initialized');
15
+ }
16
+ const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
17
+ if (!storedCredentialPublicKey) {
18
+ throw new Error('Credential public key not found');
19
+ }
20
+ const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
21
+ const credentialId = StorageService.getItem('credentialId');
22
+ if (!credentialId) {
23
+ throw new Error('Credential ID not found');
24
+ }
25
+ const passkeyPublicKey = getPublicKeyBytesFromPasskeySignature(credentialPublicKey);
26
+ const encodedPasskeyParameters = encodePasskeyModuleParameters({
27
+ credentialId: credentialId,
28
+ expectedOrigin: window.location.origin,
29
+ passkeyPublicKey,
30
+ });
31
+ return encodeModuleData({
32
+ address: passkeyAddress,
33
+ parameters: encodedPasskeyParameters,
34
+ });
35
+ });
36
+
37
+ export { getEncodedPasskeyModuleData };