@imtbl/wallet 2.12.7-alpha.1 → 2.12.7-alpha.10
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/README.md +1 -31
- package/dist/browser/index.js +30 -204
- package/dist/node/index.cjs +55 -244
- package/dist/node/index.js +29 -203
- package/dist/types/confirmation/confirmation.d.ts +1 -1
- package/dist/types/connectWallet.d.ts +3 -2
- package/dist/types/constants.d.ts +0 -9
- package/dist/types/index.d.ts +2 -4
- package/dist/types/{network/presets.d.ts → presets.d.ts} +1 -55
- package/dist/types/types.d.ts +0 -12
- package/dist/types/zkEvm/types.d.ts +10 -3
- package/package.json +4 -9
- package/src/confirmation/confirmation.ts +4 -14
- package/src/connectWallet.test.ts +1 -34
- package/src/connectWallet.ts +40 -81
- package/src/constants.ts +0 -13
- package/src/guardian/index.ts +0 -2
- package/src/index.ts +2 -18
- package/src/presets.ts +92 -0
- package/src/types.ts +0 -16
- package/src/zkEvm/types.ts +10 -4
- package/dist/types/network/chainRegistry.d.ts +0 -13
- package/dist/types/sequence/sequenceProvider.d.ts +0 -21
- package/dist/types/sequence/signer/identityInstrumentSigner.d.ts +0 -15
- package/dist/types/sequence/signer/index.d.ts +0 -21
- package/dist/types/sequence/signer/privateKeySigner.d.ts +0 -15
- package/dist/types/sequence/signer/types.d.ts +0 -14
- package/dist/types/sequence/user/index.d.ts +0 -2
- package/dist/types/sequence/user/registerUser.d.ts +0 -18
- package/src/network/chainRegistry.test.ts +0 -64
- package/src/network/chainRegistry.ts +0 -74
- package/src/network/presets.ts +0 -185
- package/src/sequence/sequenceProvider.ts +0 -284
- package/src/sequence/signer/identityInstrumentSigner.ts +0 -195
- package/src/sequence/signer/index.ts +0 -41
- package/src/sequence/signer/privateKeySigner.ts +0 -112
- package/src/sequence/signer/types.ts +0 -24
- package/src/sequence/user/index.ts +0 -2
- package/src/sequence/user/registerUser.ts +0 -101
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { MultiRollupApiClients } from '@imtbl/generated-clients';
|
|
2
|
-
import { Flow } from '@imtbl/metrics';
|
|
3
|
-
import type { PublicClient } from 'viem';
|
|
4
|
-
import { getEip155ChainId } from '../../zkEvm/walletHelpers';
|
|
5
|
-
import { JsonRpcError, RpcErrorCode } from '../../zkEvm/JsonRpcError';
|
|
6
|
-
import { SequenceSigner } from '../signer';
|
|
7
|
-
import { GetUserFunction } from '../../types';
|
|
8
|
-
|
|
9
|
-
export type RegisterUserInput = {
|
|
10
|
-
getUser: GetUserFunction;
|
|
11
|
-
ethSigner: SequenceSigner;
|
|
12
|
-
multiRollupApiClients: MultiRollupApiClients;
|
|
13
|
-
accessToken: string;
|
|
14
|
-
rpcProvider: PublicClient;
|
|
15
|
-
flow: Flow;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Format the signature for the registration API.
|
|
22
|
-
* Converts v value from 27/28 format to 0/1 recovery param format.
|
|
23
|
-
*/
|
|
24
|
-
function formatSignature(signature: string): string {
|
|
25
|
-
const sig = signature.startsWith('0x') ? signature.slice(2) : signature;
|
|
26
|
-
const r = sig.substring(0, 64);
|
|
27
|
-
const s = sig.substring(64, 128);
|
|
28
|
-
const v = sig.substring(128, 130);
|
|
29
|
-
|
|
30
|
-
const vNum = parseInt(v, 16);
|
|
31
|
-
const recoveryParam = vNum >= 27 ? vNum - 27 : vNum;
|
|
32
|
-
const vHex = recoveryParam.toString(16).padStart(2, '0');
|
|
33
|
-
|
|
34
|
-
return `0x${r}${s}${vHex}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Register a user for a non-zkEVM chain (e.g., Arbitrum).
|
|
39
|
-
* Creates a counterfactual address for the user on the specified chain.
|
|
40
|
-
*/
|
|
41
|
-
export async function registerUser({
|
|
42
|
-
getUser,
|
|
43
|
-
ethSigner,
|
|
44
|
-
multiRollupApiClients,
|
|
45
|
-
accessToken,
|
|
46
|
-
rpcProvider,
|
|
47
|
-
flow,
|
|
48
|
-
}: RegisterUserInput): Promise<string> {
|
|
49
|
-
// Parallelize the operations that can happen concurrently
|
|
50
|
-
const getAddressPromise = ethSigner.getAddress();
|
|
51
|
-
getAddressPromise.then(() => flow.addEvent('endGetAddress'));
|
|
52
|
-
|
|
53
|
-
const signMessagePromise = ethSigner.signMessage(MESSAGE_TO_SIGN).then(formatSignature);
|
|
54
|
-
signMessagePromise.then(() => flow.addEvent('endSignRaw'));
|
|
55
|
-
|
|
56
|
-
const detectNetworkPromise = rpcProvider.getChainId();
|
|
57
|
-
detectNetworkPromise.then(() => flow.addEvent('endDetectNetwork'));
|
|
58
|
-
|
|
59
|
-
const listChainsPromise = multiRollupApiClients.chainsApi.listChains();
|
|
60
|
-
listChainsPromise.then(() => flow.addEvent('endListChains'));
|
|
61
|
-
|
|
62
|
-
const [ethereumAddress, ethereumSignature, chainId, chainListResponse] = await Promise.all([
|
|
63
|
-
getAddressPromise,
|
|
64
|
-
signMessagePromise,
|
|
65
|
-
detectNetworkPromise,
|
|
66
|
-
listChainsPromise,
|
|
67
|
-
]);
|
|
68
|
-
|
|
69
|
-
const eipChainId = getEip155ChainId(Number(chainId));
|
|
70
|
-
const chainName = chainListResponse.data?.result?.find((chain) => chain.id === eipChainId)?.name;
|
|
71
|
-
if (!chainName) {
|
|
72
|
-
throw new JsonRpcError(
|
|
73
|
-
RpcErrorCode.INTERNAL_ERROR,
|
|
74
|
-
`Chain name does not exist for chain id ${chainId}`,
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const registrationResponse = await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
|
|
80
|
-
chainName,
|
|
81
|
-
createCounterfactualAddressRequest: {
|
|
82
|
-
ethereum_address: ethereumAddress,
|
|
83
|
-
ethereum_signature: ethereumSignature,
|
|
84
|
-
},
|
|
85
|
-
}, {
|
|
86
|
-
headers: { Authorization: `Bearer ${accessToken}` },
|
|
87
|
-
});
|
|
88
|
-
flow.addEvent('endCreateCounterfactualAddress');
|
|
89
|
-
|
|
90
|
-
// Trigger background refresh to get updated user data with the new chain registration
|
|
91
|
-
getUser(true).catch(() => {});
|
|
92
|
-
|
|
93
|
-
return registrationResponse.data.counterfactual_address;
|
|
94
|
-
} catch (error) {
|
|
95
|
-
flow.addEvent('errorRegisteringUser');
|
|
96
|
-
throw new JsonRpcError(
|
|
97
|
-
RpcErrorCode.INTERNAL_ERROR,
|
|
98
|
-
`Failed to create counterfactual address: ${error}`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|