kokio-sdk 0.1.4 → 1.0.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.
- package/README.md +185 -1
- package/dist/esm/admin/config-admin.js +85 -0
- package/dist/esm/admin/interface/deviceWalletClass.js +34 -0
- package/dist/esm/admin/interface/deviceWalletFactoryClass.js +57 -0
- package/dist/esm/admin/interface/eSIMWalletClass.js +31 -0
- package/dist/esm/admin/interface/eSIMWalletFactoryClass.js +22 -0
- package/dist/esm/admin/interface/lazyWalletRegistryClass.js +33 -0
- package/dist/esm/admin/interface/registryClass.js +43 -0
- package/dist/esm/config.js +4 -0
- package/dist/esm/interface/deviceWalletClass.js +1 -13
- package/dist/esm/interface/eSIMWalletClass.js +2 -8
- package/dist/esm/interface/eSIMWalletFactoryClass.js +2 -8
- package/dist/esm/interface/lazyWalletRegistryClass.js +2 -11
- package/dist/esm/logic/P256Verifier.js +8 -15
- package/dist/esm/logic/account-kit/createSmartAccount.js +76 -24
- package/dist/esm/logic/admin/deviceWallet.eoa.js +42 -0
- package/dist/esm/logic/admin/deviceWalletFactory.eoa.js +133 -0
- package/dist/esm/logic/admin/eSIMWallet.eoa.js +30 -0
- package/dist/esm/logic/admin/eSIMWalletFactory.eoa.js +43 -0
- package/dist/esm/logic/admin/lazyWalletRegistry.eoa.js +62 -0
- package/dist/esm/logic/admin/reads/deviceWallet.reads.js +45 -0
- package/dist/esm/logic/admin/reads/deviceWalletFactory.reads.js +87 -0
- package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +44 -0
- package/dist/esm/logic/admin/reads/eSIMWalletFactory.reads.js +32 -0
- package/dist/esm/logic/admin/reads/lazyWalletRegistry.reads.js +62 -0
- package/dist/esm/logic/admin/reads/registry.reads.js +136 -0
- package/dist/esm/logic/admin/registry.eoa.js +23 -0
- package/dist/esm/logic/constants.js +31 -71
- package/dist/esm/logic/deviceWallet.js +28 -91
- package/dist/esm/logic/deviceWalletFactory.js +21 -30
- package/dist/esm/logic/eSIMWallet.js +25 -57
- package/dist/esm/logic/eSIMWalletFactory.js +17 -50
- package/dist/esm/logic/errors.js +118 -0
- package/dist/esm/logic/lazyWalletRegistry.js +12 -72
- package/dist/esm/logic/utils.js +3 -3
- package/dist/types/abis/BeaconProxy.d.ts +58 -2
- package/dist/types/abis/DeviceWallet.d.ts +702 -2
- package/dist/types/abis/DeviceWalletFactory.d.ts +634 -2
- package/dist/types/abis/ESIMWallet.d.ts +375 -2
- package/dist/types/abis/ESIMWalletFactory.d.ts +355 -2
- package/dist/types/abis/LazyWalletRegistry.d.ts +565 -2
- package/dist/types/abis/P256Verifier.d.ts +56 -2
- package/dist/types/abis/Registry.d.ts +623 -2
- package/dist/types/abis/RegistryHelper.d.ts +295 -2
- package/dist/types/admin/config-admin.d.ts +55 -0
- package/dist/types/admin/interface/deviceWalletClass.d.ts +17 -0
- package/dist/types/admin/interface/deviceWalletFactoryClass.d.ts +25 -0
- package/dist/types/admin/interface/eSIMWalletClass.d.ts +17 -0
- package/dist/types/admin/interface/eSIMWalletFactoryClass.d.ts +10 -0
- package/dist/types/admin/interface/lazyWalletRegistryClass.d.ts +14 -0
- package/dist/types/admin/interface/registryClass.d.ts +17 -0
- package/dist/types/config.d.ts +2 -0
- package/dist/types/interface/P256VerifierClass.d.ts +2 -1
- package/dist/types/interface/deviceWalletClass.d.ts +24 -28
- package/dist/types/interface/deviceWalletFactoryClass.d.ts +27 -26
- package/dist/types/interface/eSIMWalletClass.d.ts +2 -4
- package/dist/types/interface/eSIMWalletFactoryClass.d.ts +24 -26
- package/dist/types/interface/lazyWalletRegistryClass.d.ts +1 -6
- package/dist/types/interface/smartAccountClass.d.ts +23 -23
- package/dist/types/logic/P256Verifier.d.ts +2 -1
- package/dist/types/logic/account-kit/createSmartAccount.d.ts +38 -1
- package/dist/types/logic/admin/deviceWallet.eoa.d.ts +12 -0
- package/dist/types/logic/admin/deviceWalletFactory.eoa.d.ts +33 -0
- package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +14 -0
- package/dist/types/logic/admin/eSIMWalletFactory.eoa.d.ts +13 -0
- package/dist/types/logic/admin/lazyWalletRegistry.eoa.d.ts +18 -0
- package/dist/types/logic/admin/reads/deviceWallet.reads.d.ts +16 -0
- package/dist/types/logic/admin/reads/deviceWalletFactory.reads.d.ts +26 -0
- package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +15 -0
- package/dist/types/logic/admin/reads/eSIMWalletFactory.reads.d.ts +10 -0
- package/dist/types/logic/admin/reads/lazyWalletRegistry.reads.d.ts +20 -0
- package/dist/types/logic/admin/reads/registry.reads.d.ts +34 -0
- package/dist/types/logic/admin/registry.eoa.d.ts +7 -0
- package/dist/types/logic/deviceWallet.d.ts +1 -5
- package/dist/types/logic/deviceWalletFactory.d.ts +5 -4
- package/dist/types/logic/eSIMWallet.d.ts +1 -3
- package/dist/types/logic/eSIMWalletFactory.d.ts +2 -4
- package/dist/types/logic/errors.d.ts +63 -0
- package/dist/types/logic/lazyWalletRegistry.d.ts +1 -6
- package/dist/types/logic/utils.d.ts +8 -1
- package/dist/types/types.d.ts +1 -1
- package/package.json +12 -3
- package/dist/esm/interface/utilsClass.js +0 -13
- package/dist/types/interface/utilsClass.d.ts +0 -2567
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { encodeFunctionData } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { MissingSmartWalletError } from "./errors.js";
|
|
3
3
|
import { ESIMWallet } from "../abis/index.js";
|
|
4
|
+
// Not exposed on this surface:
|
|
5
|
+
// - populateHistory is `onlyRegistry` - callable only by the registry contract.
|
|
6
|
+
// - transferOwnership is a `pure` override that always reverts
|
|
7
|
+
// ("Use acceptOwnershipTransfer instead."); use requestTransferOwnership /
|
|
8
|
+
// acceptOwnershipTransfer instead.
|
|
9
|
+
// The functions below are `onlyDeviceWallet` (the eSIM wallet's owner IS the device
|
|
10
|
+
// wallet) or otherwise satisfiable by the device-wallet userOp sender, so they succeed.
|
|
4
11
|
export const _setESIMUniqueIdentifier = async (client, address, eSIMUniqueIdentifier) => {
|
|
5
12
|
if (!client.account)
|
|
6
|
-
throw new
|
|
7
|
-
// UserOp
|
|
13
|
+
throw new MissingSmartWalletError();
|
|
14
|
+
// UserOp - `onlyDeviceWallet`.
|
|
8
15
|
return client.sendUserOperation({
|
|
9
16
|
account: client.account,
|
|
10
17
|
uo: {
|
|
@@ -19,56 +26,33 @@ export const _setESIMUniqueIdentifier = async (client, address, eSIMUniqueIdenti
|
|
|
19
26
|
};
|
|
20
27
|
export const _buyDataBundle = async (client, address, dataBundleDetails) => {
|
|
21
28
|
if (!client.account)
|
|
22
|
-
throw new
|
|
23
|
-
// UserOp
|
|
29
|
+
throw new MissingSmartWalletError();
|
|
30
|
+
// UserOp - `onlyDeviceWalletOrESIMWalletAdmin`; the owning device wallet may buy.
|
|
24
31
|
return client.sendUserOperation({
|
|
25
32
|
account: client.account,
|
|
26
33
|
uo: {
|
|
27
34
|
target: address,
|
|
28
35
|
data: encodeFunctionData({
|
|
29
36
|
abi: ESIMWallet,
|
|
30
|
-
functionName: "
|
|
31
|
-
args: [dataBundleDetails]
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
export const _populateHistory = async (client, address, dataBundleDetails) => {
|
|
37
|
-
if (!client.account)
|
|
38
|
-
throw new Error(customErrors.MISSING_SMART_WALLET);
|
|
39
|
-
// UserOp
|
|
40
|
-
return client.sendUserOperation({
|
|
41
|
-
account: client.account,
|
|
42
|
-
uo: {
|
|
43
|
-
target: address,
|
|
44
|
-
data: encodeFunctionData({
|
|
45
|
-
abi: ESIMWallet,
|
|
46
|
-
functionName: "populateHistory",
|
|
37
|
+
functionName: "buyDataBundle",
|
|
47
38
|
args: [dataBundleDetails]
|
|
48
39
|
})
|
|
49
40
|
}
|
|
50
41
|
});
|
|
51
42
|
};
|
|
43
|
+
// `owner()` is a `view` - read it directly instead of spending a userOp.
|
|
52
44
|
export const _owner = async (client, address) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
uo: {
|
|
59
|
-
target: address,
|
|
60
|
-
data: encodeFunctionData({
|
|
61
|
-
abi: ESIMWallet,
|
|
62
|
-
functionName: "owner",
|
|
63
|
-
args: []
|
|
64
|
-
})
|
|
65
|
-
}
|
|
45
|
+
return client.readContract({
|
|
46
|
+
address,
|
|
47
|
+
abi: ESIMWallet,
|
|
48
|
+
functionName: "owner",
|
|
49
|
+
args: []
|
|
66
50
|
});
|
|
67
51
|
};
|
|
68
52
|
export const _requestTransferOwnership = async (client, address, newOwner) => {
|
|
69
53
|
if (!client.account)
|
|
70
|
-
throw new
|
|
71
|
-
// UserOp
|
|
54
|
+
throw new MissingSmartWalletError();
|
|
55
|
+
// UserOp - `onlyDeviceWallet`; the owning device wallet requests the transfer.
|
|
72
56
|
return client.sendUserOperation({
|
|
73
57
|
account: client.account,
|
|
74
58
|
uo: {
|
|
@@ -83,8 +67,8 @@ export const _requestTransferOwnership = async (client, address, newOwner) => {
|
|
|
83
67
|
};
|
|
84
68
|
export const _acceptOwnershipTransfer = async (client, address) => {
|
|
85
69
|
if (!client.account)
|
|
86
|
-
throw new
|
|
87
|
-
// UserOp
|
|
70
|
+
throw new MissingSmartWalletError();
|
|
71
|
+
// UserOp - the caller must be the pending `newRequestedOwner` (the new device wallet).
|
|
88
72
|
return client.sendUserOperation({
|
|
89
73
|
account: client.account,
|
|
90
74
|
uo: {
|
|
@@ -99,8 +83,8 @@ export const _acceptOwnershipTransfer = async (client, address) => {
|
|
|
99
83
|
};
|
|
100
84
|
export const _sendETHToDeviceWallet = async (client, address, amount) => {
|
|
101
85
|
if (!client.account)
|
|
102
|
-
throw new
|
|
103
|
-
// UserOp
|
|
86
|
+
throw new MissingSmartWalletError();
|
|
87
|
+
// UserOp - `onlyDeviceWallet`.
|
|
104
88
|
return client.sendUserOperation({
|
|
105
89
|
account: client.account,
|
|
106
90
|
uo: {
|
|
@@ -113,19 +97,3 @@ export const _sendETHToDeviceWallet = async (client, address, amount) => {
|
|
|
113
97
|
}
|
|
114
98
|
});
|
|
115
99
|
};
|
|
116
|
-
export const _transferOwnership = async (client, address, amount) => {
|
|
117
|
-
if (!client.account)
|
|
118
|
-
throw new Error(customErrors.MISSING_SMART_WALLET);
|
|
119
|
-
// UserOp
|
|
120
|
-
return client.sendUserOperation({
|
|
121
|
-
account: client.account,
|
|
122
|
-
uo: {
|
|
123
|
-
target: address,
|
|
124
|
-
data: encodeFunctionData({
|
|
125
|
-
abi: ESIMWallet,
|
|
126
|
-
functionName: "transferOwnership",
|
|
127
|
-
args: [amount]
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
@@ -1,47 +1,21 @@
|
|
|
1
1
|
import { encodeFunctionData } from "viem";
|
|
2
|
-
import { _getChainSpecificConstants
|
|
2
|
+
import { _getChainSpecificConstants } from "./constants.js";
|
|
3
|
+
import { MissingSmartWalletError } from "./errors.js";
|
|
3
4
|
import { ESIMWalletFactory } from "../abis/index.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return client.sendUserOperation({
|
|
12
|
-
account: client.account,
|
|
13
|
-
uo: {
|
|
14
|
-
target: values.factoryAddresses.ESIM_WALLET_FACTORY,
|
|
15
|
-
data: encodeFunctionData({
|
|
16
|
-
abi: ESIMWalletFactory,
|
|
17
|
-
functionName: "addRegistryAddress",
|
|
18
|
-
args: [registryContractAddress]
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
export const _deployESIMWalletWithEOA = async (client, deviceWalletAddress, salt) => {
|
|
24
|
-
const chainID = await client.getChainId();
|
|
25
|
-
const rpcURL = client.transport.url;
|
|
26
|
-
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
27
|
-
if (!client.account)
|
|
28
|
-
throw new Error(customErrors.MISSING_EOA_WALLET);
|
|
29
|
-
return client.writeContract({
|
|
30
|
-
address: values.factoryAddresses.ESIM_WALLET_FACTORY,
|
|
31
|
-
chain: values.chain,
|
|
32
|
-
account: client.account.address,
|
|
33
|
-
abi: ESIMWalletFactory,
|
|
34
|
-
functionName: 'deployESIMWallet',
|
|
35
|
-
args: [deviceWalletAddress, salt]
|
|
36
|
-
});
|
|
37
|
-
};
|
|
5
|
+
// Not exposed on this surface:
|
|
6
|
+
// - addRegistryAddress is `onlyOwner` (the upgradeManager EOA); exposed on
|
|
7
|
+
// `KokioAdmin.eSIMWalletFactory` instead.
|
|
8
|
+
// - a direct EOA call to `deployESIMWallet` always reverts: the modifier is
|
|
9
|
+
// `onlyRegistryOrDeviceWalletFactoryOrDeviceWallet`, and a bare EOA is none of those.
|
|
10
|
+
// `deployESIMWalletWithUserOp` works because a registered device wallet passes
|
|
11
|
+
// `registry.isDeviceWalletValid(msg.sender)`, so the userOp sender satisfies the modifier.
|
|
38
12
|
export const _deployESIMWalletWithUserOp = async (client, deviceWalletAddress, salt) => {
|
|
39
13
|
const chainID = await client.getChainId();
|
|
40
14
|
const rpcURL = client.transport.url;
|
|
41
15
|
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
42
16
|
if (!client.account)
|
|
43
|
-
throw new
|
|
44
|
-
// UserOp
|
|
17
|
+
throw new MissingSmartWalletError();
|
|
18
|
+
// UserOp - the device-wallet sender is a valid device wallet per the registry.
|
|
45
19
|
return client.sendUserOperation({
|
|
46
20
|
account: client.account,
|
|
47
21
|
uo: {
|
|
@@ -58,18 +32,11 @@ export const _getCurrentESIMWalletImplementation = async (client) => {
|
|
|
58
32
|
const chainID = await client.getChainId();
|
|
59
33
|
const rpcURL = client.transport.url;
|
|
60
34
|
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
target: values.factoryAddresses.ESIM_WALLET_FACTORY,
|
|
68
|
-
data: encodeFunctionData({
|
|
69
|
-
abi: ESIMWalletFactory,
|
|
70
|
-
functionName: "getCurrentESIMWalletImplementation",
|
|
71
|
-
args: []
|
|
72
|
-
})
|
|
73
|
-
}
|
|
35
|
+
// `getCurrentESIMWalletImplementation` is a `view` - read it directly instead of a userOp.
|
|
36
|
+
return client.readContract({
|
|
37
|
+
address: values.factoryAddresses.ESIM_WALLET_FACTORY,
|
|
38
|
+
abi: ESIMWalletFactory,
|
|
39
|
+
functionName: "getCurrentESIMWalletImplementation",
|
|
40
|
+
args: []
|
|
74
41
|
});
|
|
75
42
|
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { decodeErrorResult, isHex } from "viem";
|
|
2
|
+
import { DeviceWallet, DeviceWalletFactory, ESIMWallet, ESIMWalletFactory, LazyWalletRegistry, P256Verifier, Registry, RegistryHelper, } from "../abis/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for every error the Kokio SDK throws deliberately. Consumers can
|
|
5
|
+
* `instanceof KokioError` to distinguish SDK-originated failures from viem /
|
|
6
|
+
* bundler / network errors, and switch on `code` for programmatic handling.
|
|
7
|
+
*/
|
|
8
|
+
export class KokioError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = new.target.name;
|
|
13
|
+
this.code = code;
|
|
14
|
+
// Restore the prototype chain when compiling down to ES5 targets.
|
|
15
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** A required value was null, undefined, or empty. */
|
|
19
|
+
export class NullOrUndefinedValueError extends KokioError {
|
|
20
|
+
constructor(message = "Null or undefined value provided") {
|
|
21
|
+
super("NULL_OR_UNDEFINED_VALUE", message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** The client has no smart-wallet (ERC-4337) account associated. */
|
|
25
|
+
export class MissingSmartWalletError extends KokioError {
|
|
26
|
+
constructor(message = "Client does not have a smart wallet account associated") {
|
|
27
|
+
super("MISSING_SMART_WALLET", message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The client has no EOA account associated. */
|
|
31
|
+
export class MissingEOAWalletError extends KokioError {
|
|
32
|
+
constructor(message = "Client does not have an EOA wallet associated") {
|
|
33
|
+
super("MISSING_EOA_WALLET", message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** No client/signer instance was supplied where one was required. */
|
|
37
|
+
export class InvalidClientError extends KokioError {
|
|
38
|
+
constructor(message = "Invalid Signer or Provider instance") {
|
|
39
|
+
super("INVALID_CLIENT", message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The requested chain id is not known to the SDK at all. */
|
|
43
|
+
export class UnsupportedChainError extends KokioError {
|
|
44
|
+
constructor(chainID) {
|
|
45
|
+
super("UNSUPPORTED_CHAIN", `Unsupported chain id ${chainID}. Kokio SDK has no configuration for this chain.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** The chain is known but its factory address book is still '0x' placeholders. */
|
|
49
|
+
export class UnconfiguredChainError extends KokioError {
|
|
50
|
+
constructor(chainID) {
|
|
51
|
+
super("UNCONFIGURED_CHAIN", `Chain id ${chainID} is not yet configured (factory addresses are '0x' placeholders). ` +
|
|
52
|
+
`Deploy the contracts and populate its address book before using this chain.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The off-chain counterfactual address diverged from the factory's on-chain
|
|
57
|
+
* `getCounterFactualAddress` view - a signal that the pinned BeaconProxy
|
|
58
|
+
* bytecode or CREATE2 encoding has drifted from the deployed contracts.
|
|
59
|
+
*/
|
|
60
|
+
export class CounterfactualMismatchError extends KokioError {
|
|
61
|
+
offChain;
|
|
62
|
+
onChain;
|
|
63
|
+
constructor(offChain, onChain) {
|
|
64
|
+
super("COUNTERFACTUAL_MISMATCH", `Counterfactual address mismatch: SDK computed ${offChain} but the factory ` +
|
|
65
|
+
`returned ${onChain}. The pinned BeaconProxy bytecode or CREATE2 encoding ` +
|
|
66
|
+
`is out of sync with the deployed contracts.`);
|
|
67
|
+
this.offChain = offChain;
|
|
68
|
+
this.onChain = onChain;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Every ABI that can surface a custom error from an on-chain revert. viem's
|
|
72
|
+
// `decodeErrorResult` walks each ABI's `error` fragments to match the 4-byte
|
|
73
|
+
// selector in the revert data.
|
|
74
|
+
const REVERTABLE_ABIS = [
|
|
75
|
+
DeviceWallet,
|
|
76
|
+
DeviceWalletFactory,
|
|
77
|
+
ESIMWallet,
|
|
78
|
+
ESIMWalletFactory,
|
|
79
|
+
LazyWalletRegistry,
|
|
80
|
+
P256Verifier,
|
|
81
|
+
Registry,
|
|
82
|
+
RegistryHelper,
|
|
83
|
+
];
|
|
84
|
+
/**
|
|
85
|
+
* Best-effort decode of raw revert data (the ABI-encoded `Error(string)`,
|
|
86
|
+
* `Panic(uint256)`, or a contract custom error) against the known Kokio ABIs.
|
|
87
|
+
* Returns `null` when the selector matches none of them.
|
|
88
|
+
*/
|
|
89
|
+
export const decodeContractRevert = (data) => {
|
|
90
|
+
if (!isHex(data) || data.length < 10)
|
|
91
|
+
return null;
|
|
92
|
+
for (const abi of REVERTABLE_ABIS) {
|
|
93
|
+
try {
|
|
94
|
+
const decoded = decodeErrorResult({ abi, data });
|
|
95
|
+
return { errorName: decoded.errorName, args: (decoded.args ?? []) };
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Selector not present in this ABI - try the next one.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* A decoded on-chain revert. Carries the raw revert data plus, when the
|
|
105
|
+
* selector was recognised, the decoded custom-error name and args.
|
|
106
|
+
*/
|
|
107
|
+
export class ContractRevertError extends KokioError {
|
|
108
|
+
data;
|
|
109
|
+
decoded;
|
|
110
|
+
constructor(data) {
|
|
111
|
+
const decoded = decodeContractRevert(data);
|
|
112
|
+
super("CONTRACT_REVERT", decoded
|
|
113
|
+
? `Contract reverted with ${decoded.errorName}(${decoded.args.map(String).join(", ")})`
|
|
114
|
+
: `Contract reverted with unrecognised data ${data}`);
|
|
115
|
+
this.data = data;
|
|
116
|
+
this.decoded = decoded;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -1,79 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _getChainSpecificConstants, customErrors } from "./constants.js";
|
|
1
|
+
import { _getChainSpecificConstants } from "./constants.js";
|
|
3
2
|
import { LazyWalletRegistry } from "../abis/index.js";
|
|
3
|
+
// batchPopulateHistory, deployLazyWalletAndSetESIMIdentifier and
|
|
4
|
+
// switchESIMIdentifierToNewDeviceIdentifier are all `onlyESIMWalletAdmin`, so a
|
|
5
|
+
// device-wallet userOp (msg.sender = the device wallet account) always reverts. They
|
|
6
|
+
// are exposed on `KokioAdmin.lazyWalletRegistry` instead. Only the `view` lookup
|
|
7
|
+
// belongs on this surface, exposed as a direct read.
|
|
4
8
|
export const _isLazyWalletDeployed = async (client, deviceUniqueIdentifier) => {
|
|
5
9
|
const chainID = await client.getChainId();
|
|
6
10
|
const rpcURL = client.transport.url;
|
|
7
11
|
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
target: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
15
|
-
data: encodeFunctionData({
|
|
16
|
-
abi: LazyWalletRegistry,
|
|
17
|
-
functionName: "isLazyWalletDeployed",
|
|
18
|
-
args: [deviceUniqueIdentifier]
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
export const _batchPopulateHistory = async (client, deviceUniqueIdentifiers, eSIMUniqueIdentifiers, dataBundleDetails) => {
|
|
24
|
-
const chainID = await client.getChainId();
|
|
25
|
-
const rpcURL = client.transport.url;
|
|
26
|
-
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
27
|
-
if (!client.account)
|
|
28
|
-
throw new Error(customErrors.MISSING_SMART_WALLET);
|
|
29
|
-
// UserOp
|
|
30
|
-
return client.sendUserOperation({
|
|
31
|
-
account: client.account,
|
|
32
|
-
uo: {
|
|
33
|
-
target: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
34
|
-
data: encodeFunctionData({
|
|
35
|
-
abi: LazyWalletRegistry,
|
|
36
|
-
functionName: "batchPopulateHistory",
|
|
37
|
-
args: [deviceUniqueIdentifiers, eSIMUniqueIdentifiers, dataBundleDetails]
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
export const _deployLazyWalletAndSetESIMIdentifier = async (client, deviceOwnerPublicKey, deviceUniqueIdentifier, salt, depositAmount) => {
|
|
43
|
-
const chainID = await client.getChainId();
|
|
44
|
-
const rpcURL = client.transport.url;
|
|
45
|
-
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
46
|
-
if (!client.account)
|
|
47
|
-
throw new Error(customErrors.MISSING_SMART_WALLET);
|
|
48
|
-
// UserOp
|
|
49
|
-
return client.sendUserOperation({
|
|
50
|
-
account: client.account,
|
|
51
|
-
uo: {
|
|
52
|
-
target: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
53
|
-
data: encodeFunctionData({
|
|
54
|
-
abi: LazyWalletRegistry,
|
|
55
|
-
functionName: "deployLazyWalletAndSetESIMIdentifier",
|
|
56
|
-
args: [deviceOwnerPublicKey, deviceUniqueIdentifier, salt, depositAmount]
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
export const _switchESIMIdentifierToNewDeviceIdentifier = async (client, eSIMIdentifier, oldDeviceIdentifier, newDeviceIdentifier) => {
|
|
62
|
-
const chainID = await client.getChainId();
|
|
63
|
-
const rpcURL = client.transport.url;
|
|
64
|
-
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
65
|
-
if (!client.account)
|
|
66
|
-
throw new Error(customErrors.MISSING_SMART_WALLET);
|
|
67
|
-
// UserOp
|
|
68
|
-
return client.sendUserOperation({
|
|
69
|
-
account: client.account,
|
|
70
|
-
uo: {
|
|
71
|
-
target: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
72
|
-
data: encodeFunctionData({
|
|
73
|
-
abi: LazyWalletRegistry,
|
|
74
|
-
functionName: "switchESIMIdentifierToNewDeviceIdentifier",
|
|
75
|
-
args: [eSIMIdentifier, oldDeviceIdentifier, newDeviceIdentifier]
|
|
76
|
-
})
|
|
77
|
-
}
|
|
12
|
+
// `isLazyWalletDeployed` is a `view` - read it directly instead of spending a userOp.
|
|
13
|
+
return client.readContract({
|
|
14
|
+
address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
15
|
+
abi: LazyWalletRegistry,
|
|
16
|
+
functionName: "isLazyWalletDeployed",
|
|
17
|
+
args: [deviceUniqueIdentifier]
|
|
78
18
|
});
|
|
79
19
|
};
|
package/dist/esm/logic/utils.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { isHex, toHex } from "viem";
|
|
2
2
|
import { AsnParser } from "@peculiar/asn1-schema";
|
|
3
3
|
import { ECDSASigValue } from "@peculiar/asn1-ecc";
|
|
4
|
-
import {
|
|
4
|
+
import { NullOrUndefinedValueError } from "./errors.js";
|
|
5
5
|
export const _add0x = (data) => {
|
|
6
6
|
if (!data) {
|
|
7
|
-
throw
|
|
7
|
+
throw new NullOrUndefinedValueError();
|
|
8
8
|
}
|
|
9
9
|
return (data.indexOf('0x') !== -1) ? isHex(data) ? data : `0x${data}` : `0x${data}`;
|
|
10
10
|
};
|
|
11
11
|
export const _remove0x = (data) => {
|
|
12
12
|
if (!data) {
|
|
13
|
-
throw
|
|
13
|
+
throw new NullOrUndefinedValueError();
|
|
14
14
|
}
|
|
15
15
|
return (data.indexOf('0x') !== -1) ? data.slice(2) : data;
|
|
16
16
|
};
|
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const BeaconProxy: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly internalType: "address";
|
|
4
|
+
readonly name: "beacon";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}, {
|
|
7
|
+
readonly internalType: "bytes";
|
|
8
|
+
readonly name: "data";
|
|
9
|
+
readonly type: "bytes";
|
|
10
|
+
}];
|
|
11
|
+
readonly stateMutability: "payable";
|
|
12
|
+
readonly type: "constructor";
|
|
13
|
+
}, {
|
|
14
|
+
readonly inputs: readonly [{
|
|
15
|
+
readonly internalType: "address";
|
|
16
|
+
readonly name: "target";
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
}];
|
|
19
|
+
readonly name: "AddressEmptyCode";
|
|
20
|
+
readonly type: "error";
|
|
21
|
+
}, {
|
|
22
|
+
readonly inputs: readonly [{
|
|
23
|
+
readonly internalType: "address";
|
|
24
|
+
readonly name: "beacon";
|
|
25
|
+
readonly type: "address";
|
|
26
|
+
}];
|
|
27
|
+
readonly name: "ERC1967InvalidBeacon";
|
|
28
|
+
readonly type: "error";
|
|
29
|
+
}, {
|
|
30
|
+
readonly inputs: readonly [{
|
|
31
|
+
readonly internalType: "address";
|
|
32
|
+
readonly name: "implementation";
|
|
33
|
+
readonly type: "address";
|
|
34
|
+
}];
|
|
35
|
+
readonly name: "ERC1967InvalidImplementation";
|
|
36
|
+
readonly type: "error";
|
|
37
|
+
}, {
|
|
38
|
+
readonly inputs: readonly [];
|
|
39
|
+
readonly name: "ERC1967NonPayable";
|
|
40
|
+
readonly type: "error";
|
|
41
|
+
}, {
|
|
42
|
+
readonly inputs: readonly [];
|
|
43
|
+
readonly name: "FailedInnerCall";
|
|
44
|
+
readonly type: "error";
|
|
45
|
+
}, {
|
|
46
|
+
readonly anonymous: false;
|
|
47
|
+
readonly inputs: readonly [{
|
|
48
|
+
readonly indexed: true;
|
|
49
|
+
readonly internalType: "address";
|
|
50
|
+
readonly name: "beacon";
|
|
51
|
+
readonly type: "address";
|
|
52
|
+
}];
|
|
53
|
+
readonly name: "BeaconUpgraded";
|
|
54
|
+
readonly type: "event";
|
|
55
|
+
}, {
|
|
56
|
+
readonly stateMutability: "payable";
|
|
57
|
+
readonly type: "fallback";
|
|
58
|
+
}];
|
|
3
59
|
export default BeaconProxy;
|