catapultar 0.1.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/LICENSE +165 -0
- package/README.md +161 -0
- package/dist/abi/CATValidator.d.ts +174 -0
- package/dist/abi/CATValidator.d.ts.map +1 -0
- package/dist/abi/CATValidator.js +225 -0
- package/dist/abi/CATValidator.js.map +1 -0
- package/dist/abi/catapultarFactoryV0.0.1.d.ts +2 -0
- package/dist/abi/catapultarFactoryV0.0.1.d.ts.map +1 -0
- package/dist/abi/catapultarFactoryV0.0.1.js +1 -0
- package/dist/abi/catapultarFactoryV0.0.1.js.map +1 -0
- package/dist/abi/catapultarFactoryV0.1.0.d.ts +175 -0
- package/dist/abi/catapultarFactoryV0.1.0.d.ts.map +1 -0
- package/dist/abi/catapultarFactoryV0.1.0.js +229 -0
- package/dist/abi/catapultarFactoryV0.1.0.js.map +1 -0
- package/dist/abi/catapultarV0.0.1.d.ts +2 -0
- package/dist/abi/catapultarV0.0.1.d.ts.map +1 -0
- package/dist/abi/catapultarV0.0.1.js +1 -0
- package/dist/abi/catapultarV0.0.1.js.map +1 -0
- package/dist/abi/catapultarV0.1.0.d.ts +409 -0
- package/dist/abi/catapultarV0.1.0.d.ts.map +1 -0
- package/dist/abi/catapultarV0.1.0.js +528 -0
- package/dist/abi/catapultarV0.1.0.js.map +1 -0
- package/dist/abi/mockerc20.d.ts +342 -0
- package/dist/abi/mockerc20.d.ts.map +1 -0
- package/dist/abi/mockerc20.js +443 -0
- package/dist/abi/mockerc20.js.map +1 -0
- package/dist/catapultar/account.d.ts +86 -0
- package/dist/catapultar/account.d.ts.map +1 -0
- package/dist/catapultar/account.js +408 -0
- package/dist/catapultar/account.js.map +1 -0
- package/dist/catapultar/catapultar.d.ts +143 -0
- package/dist/catapultar/catapultar.d.ts.map +1 -0
- package/dist/catapultar/catapultar.js +200 -0
- package/dist/catapultar/catapultar.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +24 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/transaction/constrainedtransaction.d.ts +57 -0
- package/dist/transaction/constrainedtransaction.d.ts.map +1 -0
- package/dist/transaction/constrainedtransaction.js +191 -0
- package/dist/transaction/constrainedtransaction.js.map +1 -0
- package/dist/transaction/transaction.d.ts +88 -0
- package/dist/transaction/transaction.d.ts.map +1 -0
- package/dist/transaction/transaction.js +185 -0
- package/dist/transaction/transaction.js.map +1 -0
- package/dist/types/types.d.ts +144 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +53 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/helpers.d.ts +31 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +65 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/signature.d.ts +3 -0
- package/dist/utils/signature.d.ts.map +1 -0
- package/dist/utils/signature.js +10 -0
- package/dist/utils/signature.js.map +1 -0
- package/dist/utils/viem.d.ts +3 -0
- package/dist/utils/viem.d.ts.map +1 -0
- package/dist/utils/viem.js +10 -0
- package/dist/utils/viem.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { createPublicClient, decodeAbiParameters, encodeAbiParameters, encodeFunctionData, encodePacked, getCreate2Address, http, keccak256, parseAbiParameters, recoverAddress, } from "viem";
|
|
2
|
+
import { AccountPublicKeyType, } from "../types/types.js";
|
|
3
|
+
import { getViemChainId } from "../utils/viem.js";
|
|
4
|
+
import CATAPULTAR_V0_1_0_ABI from "../abi/catapultarV0.1.0.js";
|
|
5
|
+
import CATAPULTAR_FACTORY_V0_1_0_ABI from "../abi/catapultarFactoryV0.1.0.js";
|
|
6
|
+
import { pubkeyAsArray } from "../utils/helpers.js";
|
|
7
|
+
// import { CATAPULTAR_V0_0_1_ABI } from "../abi/catapultarV0.0.1.js";
|
|
8
|
+
import { P256, PublicKey, WebAuthnP256 } from "ox";
|
|
9
|
+
import { fromCompactSignature } from "../utils/signature.js";
|
|
10
|
+
import { _factory } from "../config.js";
|
|
11
|
+
export class CatapultarAccount {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
const { address, accountPublicKeyType = AccountPublicKeyType.ECDSAOrSmartContract, chainId, pubkey, name = "Catapultar", version = "0.1.0", rpc, } = options;
|
|
14
|
+
// Account definition
|
|
15
|
+
this.address = address;
|
|
16
|
+
this.chainId = chainId;
|
|
17
|
+
// Validation
|
|
18
|
+
if (accountPublicKeyType === AccountPublicKeyType.ECDSAOrSmartContract &&
|
|
19
|
+
Array.isArray(pubkey))
|
|
20
|
+
throw new Error(`Only one key allowed for ECDSA or SmartContract: ${pubkey}`);
|
|
21
|
+
if ([AccountPublicKeyType.P256, AccountPublicKeyType.WebAuthnP256].includes(accountPublicKeyType) &&
|
|
22
|
+
!Array.isArray(pubkey))
|
|
23
|
+
throw new Error(`P256 signatures requires the pubkey as exactly 2 points: ${pubkey}`);
|
|
24
|
+
this.pubkey = pubkey;
|
|
25
|
+
this.accountPublicKeyType = accountPublicKeyType;
|
|
26
|
+
this.rpc = rpc;
|
|
27
|
+
// Custom domainSeparator
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.version = version;
|
|
30
|
+
}
|
|
31
|
+
static deploy(options) {
|
|
32
|
+
let callDigest = undefined;
|
|
33
|
+
let isSignature = undefined;
|
|
34
|
+
let derivedAddress;
|
|
35
|
+
const { factory, template } = _factory(options);
|
|
36
|
+
if ("callDigest" in options && "isSignature" in options) {
|
|
37
|
+
callDigest = options.callDigest;
|
|
38
|
+
isSignature = options.isSignature;
|
|
39
|
+
derivedAddress = CatapultarAccount.predict({
|
|
40
|
+
...options,
|
|
41
|
+
factory,
|
|
42
|
+
template,
|
|
43
|
+
callDigest: callDigest,
|
|
44
|
+
isSignature: isSignature,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
derivedAddress = CatapultarAccount.predict({
|
|
49
|
+
...options,
|
|
50
|
+
factory,
|
|
51
|
+
template,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const pubkeyArray = pubkeyAsArray(options);
|
|
55
|
+
const call = {
|
|
56
|
+
to: factory,
|
|
57
|
+
data: callDigest
|
|
58
|
+
? encodeFunctionData({
|
|
59
|
+
abi: CATAPULTAR_FACTORY_V0_1_0_ABI,
|
|
60
|
+
functionName: "deployWithDigest",
|
|
61
|
+
args: [
|
|
62
|
+
options.keyType,
|
|
63
|
+
pubkeyArray,
|
|
64
|
+
options.salt,
|
|
65
|
+
callDigest,
|
|
66
|
+
isSignature,
|
|
67
|
+
],
|
|
68
|
+
})
|
|
69
|
+
: encodeFunctionData({
|
|
70
|
+
abi: CATAPULTAR_FACTORY_V0_1_0_ABI,
|
|
71
|
+
functionName: "deploy",
|
|
72
|
+
args: [options.keyType, pubkeyArray, options.salt],
|
|
73
|
+
}),
|
|
74
|
+
value: 0n,
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
call,
|
|
78
|
+
account: new CatapultarAccount({
|
|
79
|
+
address: derivedAddress,
|
|
80
|
+
accountPublicKeyType: options.keyType,
|
|
81
|
+
pubkey: options.pubkey,
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
static deriveCloneAddress(executor, salt, factory) {
|
|
86
|
+
// https://github.com/Vectorized/solady/blob/90db92ce173856605d24a554969f2c67cadbc7e9/src/utils/LibClone.sol#L366-L368
|
|
87
|
+
const initCode = ("0x602d5f8160095f39f35f5f365f5f37365f73" +
|
|
88
|
+
executor.replace("0x", "") +
|
|
89
|
+
"5af43d5f5f3e6029573d5ffd5b3d5ff3");
|
|
90
|
+
const initCodeHash = keccak256(initCode);
|
|
91
|
+
return getCreate2Address({
|
|
92
|
+
bytecodeHash: initCodeHash,
|
|
93
|
+
salt,
|
|
94
|
+
from: factory,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
static ownerInSalt(opt) {
|
|
98
|
+
const pubkeyArray = pubkeyAsArray(opt);
|
|
99
|
+
const saltPrefix = opt.keyType === AccountPublicKeyType.ECDSAOrSmartContract
|
|
100
|
+
? opt.pubkey
|
|
101
|
+
: keccak256(encodePacked(["bytes32[]"], [pubkeyArray]));
|
|
102
|
+
const saltSlice = opt.salt.slice(0, 20 * 2 + 2);
|
|
103
|
+
return BigInt(saltSlice) === 0n || saltSlice === saltPrefix;
|
|
104
|
+
}
|
|
105
|
+
static predict(opt) {
|
|
106
|
+
if (!CatapultarAccount.ownerInSalt(opt))
|
|
107
|
+
throw new Error(`Pubkey: ${opt.pubkey} not in salt: ${opt.salt}`);
|
|
108
|
+
let { salt } = opt;
|
|
109
|
+
const { factory, template } = _factory(opt);
|
|
110
|
+
// If a digest is used, rehash the hash.
|
|
111
|
+
if ("callDigest" in opt && "isSignature" in opt) {
|
|
112
|
+
const { callDigest, isSignature } = opt;
|
|
113
|
+
salt = keccak256(encodePacked(["bytes32", "bytes32", "uint256"], [salt, callDigest, isSignature ? 2n : 1n]));
|
|
114
|
+
}
|
|
115
|
+
return CatapultarAccount.deriveCloneAddress(template, salt, factory);
|
|
116
|
+
}
|
|
117
|
+
publicClient() {
|
|
118
|
+
const viemChain = getViemChainId(this.chainId);
|
|
119
|
+
return createPublicClient({
|
|
120
|
+
chain: viemChain,
|
|
121
|
+
transport: http(this.rpc),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
abi() {
|
|
125
|
+
return CATAPULTAR_V0_1_0_ABI;
|
|
126
|
+
}
|
|
127
|
+
hasRpc() {
|
|
128
|
+
return typeof this.rpc === "string" && this.rpc.length > 0;
|
|
129
|
+
}
|
|
130
|
+
hasECDSAOrSmartContractKey() {
|
|
131
|
+
return (this.accountPublicKeyType === AccountPublicKeyType.ECDSAOrSmartContract);
|
|
132
|
+
}
|
|
133
|
+
hasP256Key() {
|
|
134
|
+
return this.accountPublicKeyType === AccountPublicKeyType.P256;
|
|
135
|
+
}
|
|
136
|
+
hasWebAuthnP256Key() {
|
|
137
|
+
return this.accountPublicKeyType === AccountPublicKeyType.WebAuthnP256;
|
|
138
|
+
}
|
|
139
|
+
attachRpc(opt) {
|
|
140
|
+
this.rpc = opt.rpc;
|
|
141
|
+
this.chainId = opt.chainId;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
parseSignature(signature) {
|
|
145
|
+
if (this.hasECDSAOrSmartContractKey())
|
|
146
|
+
return signature;
|
|
147
|
+
if (this.hasP256Key()) {
|
|
148
|
+
let rawSignature = signature.replace("0x", "");
|
|
149
|
+
// If the signature is 64 bytes long (default) or 65 (mistake?)
|
|
150
|
+
// then add 0000 to the signature. This indicate an additional SHA256 hash.
|
|
151
|
+
if (rawSignature.length <= 65 * 2) {
|
|
152
|
+
rawSignature = `${rawSignature.padEnd(65 * 2, "0")}${"00"}`;
|
|
153
|
+
}
|
|
154
|
+
return `0x${rawSignature}`;
|
|
155
|
+
}
|
|
156
|
+
if (this.hasWebAuthnP256Key()) {
|
|
157
|
+
const sig = signature;
|
|
158
|
+
// const abiencode the directory.
|
|
159
|
+
const encodedParams = encodeAbiParameters(parseAbiParameters([
|
|
160
|
+
"WebAuthnAuth auth",
|
|
161
|
+
"struct WebAuthnAuth { bytes authenticatorData; string clientDataJSON; uint256 challengeIndex; uint256 typeIndex; uint256 r; uint256 s;}",
|
|
162
|
+
]), [
|
|
163
|
+
{
|
|
164
|
+
...sig,
|
|
165
|
+
typeIndex: BigInt(sig.typeIndex),
|
|
166
|
+
challengeIndex: BigInt(sig.challengeIndex),
|
|
167
|
+
},
|
|
168
|
+
]);
|
|
169
|
+
return `${encodedParams}00`; // Use SHA256 hash.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// --- Writing Functions --- //
|
|
173
|
+
// upgrade(options: {
|
|
174
|
+
// target: `0x${string}`;
|
|
175
|
+
// implementation: `0x${string}`;
|
|
176
|
+
// data?: `0x${string}`;
|
|
177
|
+
// }) {
|
|
178
|
+
// let { data } = options;
|
|
179
|
+
// if (!data) data = `0x`;
|
|
180
|
+
// target.upgradeToAndCall
|
|
181
|
+
// }
|
|
182
|
+
// TransferOwnership
|
|
183
|
+
// spend nonces.
|
|
184
|
+
/**
|
|
185
|
+
* Invalidates a set of nonces. Batches nonces that can be invalidated in a single call.
|
|
186
|
+
* @param nonces Nonces to invalidate
|
|
187
|
+
*/
|
|
188
|
+
async getSpendNoncesCalls(...nonces) {
|
|
189
|
+
const pairs = new Set(nonces.map((n) => n >> 8n));
|
|
190
|
+
const bitMaps = [...pairs].map((wordPos) => {
|
|
191
|
+
const toInvalidate = nonces.filter((n) => n >> 8n === wordPos);
|
|
192
|
+
const bits = toInvalidate.map((v) => v % 256n);
|
|
193
|
+
let mask = 0n;
|
|
194
|
+
for (const bit of bits) {
|
|
195
|
+
mask += 1n << bit;
|
|
196
|
+
}
|
|
197
|
+
return [wordPos, mask];
|
|
198
|
+
});
|
|
199
|
+
return bitMaps.map(([wordPos, mask]) => {
|
|
200
|
+
const data = encodeFunctionData({
|
|
201
|
+
abi: CATAPULTAR_V0_1_0_ABI,
|
|
202
|
+
functionName: "invalidateUnorderedNonces",
|
|
203
|
+
args: [wordPos, mask],
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
to: this.address,
|
|
207
|
+
value: 0n,
|
|
208
|
+
data: data,
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// --- Helper functions for the account --- //
|
|
213
|
+
/**
|
|
214
|
+
* @param nonce Starting nonce.
|
|
215
|
+
* @returns Next valid nonce that has not been spent on-chain yet. If no nonce is found in the given attempts, -1 is returned.
|
|
216
|
+
*/
|
|
217
|
+
async getNextValidNonce(options) {
|
|
218
|
+
const { nonce: startingNonce, attempts = 10 } = options;
|
|
219
|
+
let wordPos = startingNonce >> 8n;
|
|
220
|
+
let bitPos = startingNonce % 256n;
|
|
221
|
+
let found = false;
|
|
222
|
+
for (wordPos; wordPos < (startingNonce >> 8n) + BigInt(attempts); wordPos += 1n) {
|
|
223
|
+
const spentNonces = await this.publicClient().readContract({
|
|
224
|
+
address: this.address,
|
|
225
|
+
abi: this.abi(),
|
|
226
|
+
functionName: "nonceBitmap",
|
|
227
|
+
args: [wordPos],
|
|
228
|
+
});
|
|
229
|
+
for (bitPos; bitPos < 256n; bitPos += 1n) {
|
|
230
|
+
if (!(spentNonces & (1n << bitPos))) {
|
|
231
|
+
found = true;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (found === true)
|
|
236
|
+
break;
|
|
237
|
+
bitPos = 0n;
|
|
238
|
+
}
|
|
239
|
+
if (!found)
|
|
240
|
+
return -1n;
|
|
241
|
+
return (wordPos << 8n) + bitPos;
|
|
242
|
+
}
|
|
243
|
+
async validateNonces(options) {
|
|
244
|
+
const lookups = {};
|
|
245
|
+
for (const nonce of options.nonces) {
|
|
246
|
+
const wordPos = nonce >> 8n;
|
|
247
|
+
const bitPos = nonce & 255n;
|
|
248
|
+
const val = lookups[wordPos.toString(16)];
|
|
249
|
+
if (!val)
|
|
250
|
+
lookups[wordPos.toString(16)] = 0n;
|
|
251
|
+
if (val && val & (1n << bitPos))
|
|
252
|
+
throw new Error(`Duplicate Nonce ${nonce}`);
|
|
253
|
+
lookups[wordPos.toString(16)] |= 1n << bitPos;
|
|
254
|
+
}
|
|
255
|
+
for (const [upper, word] of Object.entries(lookups)) {
|
|
256
|
+
const spentNonces = await this.publicClient().readContract({
|
|
257
|
+
address: this.address,
|
|
258
|
+
abi: this.abi(),
|
|
259
|
+
functionName: "nonceBitmap",
|
|
260
|
+
args: [BigInt(`0x${upper}`)],
|
|
261
|
+
});
|
|
262
|
+
if (spentNonces & word)
|
|
263
|
+
throw new Error(`Nonce collision on ${upper}, words: ${word} and ${spentNonces}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// TODO: P256.
|
|
267
|
+
async getAccountOwner() {
|
|
268
|
+
return this.publicClient().readContract({
|
|
269
|
+
address: this.address,
|
|
270
|
+
abi: this.abi(),
|
|
271
|
+
functionName: "owner",
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
// --- Get Functions --- //
|
|
275
|
+
/**
|
|
276
|
+
* @returns EIP-712 Domain Separator for the account.
|
|
277
|
+
*/
|
|
278
|
+
getDomainSeparator(options = { chain: true }) {
|
|
279
|
+
const { chain } = options;
|
|
280
|
+
if (chain) {
|
|
281
|
+
if (!this.chainId)
|
|
282
|
+
throw new Error(`Chain is not provided, but signing single chain.`);
|
|
283
|
+
return {
|
|
284
|
+
name: this.name,
|
|
285
|
+
version: this.version,
|
|
286
|
+
chainId: this.chainId,
|
|
287
|
+
verifyingContract: this.address,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
return {
|
|
292
|
+
name: this.name,
|
|
293
|
+
version: this.version,
|
|
294
|
+
verifyingContract: this.address,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// --- Statement Functions --- //
|
|
299
|
+
/**
|
|
300
|
+
* Return whether a signature is valid.
|
|
301
|
+
* @dev Does not support P256 signatures
|
|
302
|
+
*/
|
|
303
|
+
async isSignatureValid(options) {
|
|
304
|
+
const { signature, hash } = options;
|
|
305
|
+
if (this.hasECDSAOrSmartContractKey()) {
|
|
306
|
+
// Check ECDSA
|
|
307
|
+
let signer = "0x";
|
|
308
|
+
if (signature && signature.length > 2) {
|
|
309
|
+
signer = (await recoverAddress({
|
|
310
|
+
hash: hash,
|
|
311
|
+
signature: signature.length === 64 * 2 + 2
|
|
312
|
+
? fromCompactSignature(signature)
|
|
313
|
+
: signature,
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
if (this.pubkey === signer)
|
|
317
|
+
return true;
|
|
318
|
+
if (!this.hasRpc())
|
|
319
|
+
return false;
|
|
320
|
+
const publicClient = this.publicClient();
|
|
321
|
+
const result1271 = await publicClient.readContract({
|
|
322
|
+
address: this.pubkey,
|
|
323
|
+
abi: this.abi(),
|
|
324
|
+
functionName: "isValidSignature",
|
|
325
|
+
args: [hash, signature],
|
|
326
|
+
});
|
|
327
|
+
if (result1271 === "0x1626ba7e") {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
// 0.0.1 does not support anymore validations
|
|
333
|
+
if (this.version === "0.0.1")
|
|
334
|
+
return false;
|
|
335
|
+
// Lets run P256 and Webauth. First, lets check the formatting of the signature.
|
|
336
|
+
if (signature.replace("0x", "").length <= 65 * 2) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
const pubkey = this.pubkey;
|
|
340
|
+
const publicKey = PublicKey.from({
|
|
341
|
+
x: BigInt(pubkey[0]),
|
|
342
|
+
y: BigInt(pubkey[1]),
|
|
343
|
+
});
|
|
344
|
+
if (this.hasP256Key()) {
|
|
345
|
+
const r = BigInt("0x" + signature.replace("0x", "").slice(0, 64));
|
|
346
|
+
const s = BigInt("0x" + signature.replace("0x", "").slice(64, 128));
|
|
347
|
+
return await P256.verify({
|
|
348
|
+
payload: hash,
|
|
349
|
+
publicKey,
|
|
350
|
+
signature: { r, s },
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
if (this.hasWebAuthnP256Key()) {
|
|
354
|
+
const unpackedSig = decodeAbiParameters(parseAbiParameters([
|
|
355
|
+
"WebAuthnAuth auth",
|
|
356
|
+
"struct WebAuthnAuth { bytes authenticatorData; string clientDataJSON; uint256 challengeIndex; uint256 typeIndex; uint256 r; uint256 s;}",
|
|
357
|
+
]), signature)[0];
|
|
358
|
+
const metadata = {
|
|
359
|
+
authenticatorData: unpackedSig.authenticatorData,
|
|
360
|
+
clientDataJSON: unpackedSig.clientDataJSON,
|
|
361
|
+
challengeIndex: Number(unpackedSig.challengeIndex),
|
|
362
|
+
typeIndex: Number(unpackedSig.typeIndex),
|
|
363
|
+
};
|
|
364
|
+
return await WebAuthnP256.verify({
|
|
365
|
+
metadata,
|
|
366
|
+
challenge: hash,
|
|
367
|
+
publicKey,
|
|
368
|
+
signature: { r: unpackedSig.r, s: unpackedSig.s },
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
// --- Validation --- //
|
|
374
|
+
async validateOwner() {
|
|
375
|
+
if (this.accountPublicKeyType === AccountPublicKeyType.ECDSAOrSmartContract) {
|
|
376
|
+
const actualAccountOwner = await this.getAccountOwner();
|
|
377
|
+
if (this.pubkey !== actualAccountOwner)
|
|
378
|
+
throw new Error(`Expected pubkey: ${this.pubkey}, actual owner: ${actualAccountOwner}`);
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
const [actualKeyType, actualKey] = await this.publicClient().readContract({
|
|
382
|
+
address: this.address,
|
|
383
|
+
abi: this.abi(),
|
|
384
|
+
functionName: "getPublicKey",
|
|
385
|
+
});
|
|
386
|
+
if (actualKeyType !== this.accountPublicKeyType) {
|
|
387
|
+
throw new Error(`Expected keyType: ${this.accountPublicKeyType}, actual keyType: ${actualKeyType}`);
|
|
388
|
+
}
|
|
389
|
+
const expectedPubkey = this.pubkey;
|
|
390
|
+
const normalizeHex = (value) => value.toLowerCase();
|
|
391
|
+
const [expectedX, expectedY] = expectedPubkey.map(normalizeHex);
|
|
392
|
+
const [actualX, actualY] = actualKey.map(normalizeHex);
|
|
393
|
+
if (expectedX !== actualX || expectedY !== actualY) {
|
|
394
|
+
throw new Error(`Expected pubkey: ${expectedPubkey}, actual pubkey: ${actualKey}`);
|
|
395
|
+
}
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
async validateNonce(options) {
|
|
399
|
+
const { nonce } = options;
|
|
400
|
+
if (nonce === 0n)
|
|
401
|
+
throw new Error("Nonce 0 is not allowed. It cannot be differentiated from an invalid nonce.");
|
|
402
|
+
if (!nonce)
|
|
403
|
+
throw new Error("No nonce has been set");
|
|
404
|
+
await this.validateNonces({ nonces: [nonce] });
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/catapultar/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,IAAI,EACJ,SAAS,EACT,kBAAkB,EAClB,cAAc,GAEf,MAAM,MAAM,CAAC;AACd,OAAO,EAGL,oBAAoB,GAOrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,6BAA6B,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,mEAAmE;AACnE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,OAAO,iBAAiB;IAqB5B,YAAY,OAA8C;QACxD,MAAM,EACJ,OAAO,EACP,oBAAoB,GAAG,oBAAoB,CAAC,oBAA2B,EACvE,OAAO,EACP,MAAM,EACN,IAAI,GAAG,YAAY,EACnB,OAAO,GAAG,OAAO,EACjB,GAAG,GACJ,GAAG,OAAO,CAAC;QAEZ,qBAAqB;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAEL,CAAC;QAEX,aAAa;QACb,IACE,oBAAoB,KAAK,oBAAoB,CAAC,oBAAoB;YAClE,KAAK,CAAC,OAAO,CAAC,MAA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AAK,CACb,oBAAoB,cAAc,oBAAoB,SAAS,EAAE,CAClE,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,aAAa,CAEjB,OAEC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC1B,IAAI,KAAK,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;QACJ,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QACrD,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { AccountPublicKeyType, ExecutionMode, type AccountConstructorParams, type Call, type KeyedSignature, type Version } from "../types/types.js";
|
|
2
|
+
import { CatapultarAccount } from "./account.js";
|
|
3
|
+
import { BaseTransaction } from "../transaction/transaction.js";
|
|
4
|
+
/**
|
|
5
|
+
* A Catapultar transaction wrapper. Is intended to be used to convert a list of calls into a single Catapultar batch.
|
|
6
|
+
* @dev The class is intended to be used through modifiers, meaning each property should be set iteratively on the object:
|
|
7
|
+
* const tx = new CatapultarTx(options).setMode(ExecutionMode.RaiseRevert).setNonce(12n).addCalls(...[]).sign(() => ...).asParameters();
|
|
8
|
+
* To batch batches, multiple sub CatapultarTx can be created and then converted into calls like:
|
|
9
|
+
* calls.push(new CatapultarTx(options).addCalls(...[]).asCall());
|
|
10
|
+
* new CatapultarTx(options).addCalls(...calls).sign(() => ...).asParameters();
|
|
11
|
+
*/
|
|
12
|
+
export declare class CatapultarTx<V extends Version, RPC extends string | undefined = undefined, AKT extends AccountPublicKeyType = AccountPublicKeyType.ECDSAOrSmartContract> extends BaseTransaction {
|
|
13
|
+
account: CatapultarAccount<V, RPC, AKT>;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new Catapultar transaction batch.
|
|
16
|
+
*/
|
|
17
|
+
constructor(options: {
|
|
18
|
+
account: AccountConstructorParams<V, RPC, AKT> | CatapultarAccount<V, RPC, AKT>;
|
|
19
|
+
mode?: ExecutionMode;
|
|
20
|
+
nonce?: bigint;
|
|
21
|
+
calls?: Call[];
|
|
22
|
+
signature?: `0x${string}`;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* @returns Constructor parameters for a new (identical) CatapultarTx
|
|
26
|
+
*/
|
|
27
|
+
export(): ConstructorParameters<typeof CatapultarTx>[0];
|
|
28
|
+
/**
|
|
29
|
+
* Sets a signature along with its type. If non-ecdsa signatures are being set, this provides additional aids with encoding
|
|
30
|
+
*/
|
|
31
|
+
setSignature(signature: KeyedSignature<AKT>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Sign the transaction using a Ethers compatible signer function.
|
|
34
|
+
* @dev The callback function will be called with a typeset compatible with ether.Signer._signTypedData.
|
|
35
|
+
* An alternative way to sign this function is to set it manually as .signature.
|
|
36
|
+
*/
|
|
37
|
+
sign(callback: (options: ReturnType<typeof this.getSignerData>) => Promise<KeyedSignature<AKT>>, options?: {
|
|
38
|
+
ignoreNoCalls?: boolean;
|
|
39
|
+
}): Promise<this>;
|
|
40
|
+
hasValidSignature(options?: {
|
|
41
|
+
noSignatureIsValid?: boolean;
|
|
42
|
+
}): Promise<boolean>;
|
|
43
|
+
validateSignature(options?: {
|
|
44
|
+
noSignatureIsValid?: boolean;
|
|
45
|
+
}): Promise<this>;
|
|
46
|
+
validateUsingProvider(this: CatapultarTx<V, string>): Promise<CatapultarTx<V, string, AccountPublicKeyType.ECDSAOrSmartContract>>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns an Ethers compatible typed dict.
|
|
49
|
+
* @param options.ignoreNoCalls Do not throw an error if no calls have been configured. Default: false
|
|
50
|
+
*/
|
|
51
|
+
getSignerData(options?: {
|
|
52
|
+
ignoreNoCalls?: boolean;
|
|
53
|
+
}): {
|
|
54
|
+
readonly domain: {
|
|
55
|
+
name: string;
|
|
56
|
+
version: V;
|
|
57
|
+
chainId: NonNullable<undefined extends RPC ? number | (RPC & undefined) : number>;
|
|
58
|
+
verifyingContract: `0x${string}`;
|
|
59
|
+
} | {
|
|
60
|
+
name: string;
|
|
61
|
+
version: V;
|
|
62
|
+
verifyingContract: `0x${string}`;
|
|
63
|
+
chainId?: undefined;
|
|
64
|
+
};
|
|
65
|
+
readonly types: {
|
|
66
|
+
readonly Calls: readonly [{
|
|
67
|
+
readonly name: "nonce";
|
|
68
|
+
readonly type: "uint256";
|
|
69
|
+
}, {
|
|
70
|
+
readonly name: "mode";
|
|
71
|
+
readonly type: "bytes32";
|
|
72
|
+
}, {
|
|
73
|
+
readonly name: "calls";
|
|
74
|
+
readonly type: "Call[]";
|
|
75
|
+
}];
|
|
76
|
+
readonly Call: readonly [{
|
|
77
|
+
readonly name: "to";
|
|
78
|
+
readonly type: "address";
|
|
79
|
+
}, {
|
|
80
|
+
readonly name: "value";
|
|
81
|
+
readonly type: "uint256";
|
|
82
|
+
}, {
|
|
83
|
+
readonly name: "data";
|
|
84
|
+
readonly type: "bytes";
|
|
85
|
+
}];
|
|
86
|
+
};
|
|
87
|
+
readonly primaryType: "Calls";
|
|
88
|
+
readonly message: {
|
|
89
|
+
readonly nonce: bigint;
|
|
90
|
+
readonly mode: ExecutionMode;
|
|
91
|
+
readonly calls: Call[];
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
getTypeHashDigest(options?: {
|
|
95
|
+
ignoreNoCalls?: boolean;
|
|
96
|
+
}): `0x${string}`;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the signature as a on-chain compatible signature with an indicator byte.
|
|
99
|
+
* For ECDSA / Smart contracts returns as is.
|
|
100
|
+
* For P256, pads to 65. Then adds 00.
|
|
101
|
+
*
|
|
102
|
+
* @param Signature If provided, will act on the provided signature instead.
|
|
103
|
+
*/
|
|
104
|
+
asCompatibleSignature(signature?: `0x${string}`): `0x${string}`;
|
|
105
|
+
/**
|
|
106
|
+
* @return As a call for further scheduling or manual transaction signing. If used for manual transaction.
|
|
107
|
+
*/
|
|
108
|
+
asCall(): Promise<Call>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* This defines a meta transaction composed of several smaller transactions.
|
|
112
|
+
* Intended usecase: Wrapping multiple transactions (that can later be retried) into a single batch.
|
|
113
|
+
*/
|
|
114
|
+
export declare class MetaCatapultarTx<V extends Version, RPC extends string | undefined = undefined, AKT extends AccountPublicKeyType = AccountPublicKeyType.ECDSAOrSmartContract> {
|
|
115
|
+
mode?: ExecutionMode;
|
|
116
|
+
nonce?: bigint;
|
|
117
|
+
calls: {
|
|
118
|
+
calls: Call[];
|
|
119
|
+
nonce?: bigint;
|
|
120
|
+
mode?: ExecutionMode;
|
|
121
|
+
}[];
|
|
122
|
+
outerNonce: bigint;
|
|
123
|
+
innerNonce: bigint;
|
|
124
|
+
account: CatapultarAccount<V, RPC, AKT>;
|
|
125
|
+
constructor(options: {
|
|
126
|
+
account: AccountConstructorParams<V, RPC, AKT> | CatapultarAccount<V, RPC, AKT>;
|
|
127
|
+
mode?: ExecutionMode;
|
|
128
|
+
nonce?: bigint;
|
|
129
|
+
signature?: `0x${string}`;
|
|
130
|
+
outerNonce?: bigint;
|
|
131
|
+
innerNonce?: bigint;
|
|
132
|
+
});
|
|
133
|
+
setMode(mode: ExecutionMode): this;
|
|
134
|
+
addCalls(...calls: {
|
|
135
|
+
calls: Call[];
|
|
136
|
+
nonce?: bigint;
|
|
137
|
+
mode?: ExecutionMode;
|
|
138
|
+
}[]): this;
|
|
139
|
+
checkNonces(): this;
|
|
140
|
+
getCallsAsTxs(): CatapultarTx<V, RPC, AKT>[];
|
|
141
|
+
asCatapultarTx(): Promise<CatapultarTx<V, RPC, AKT>>;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=catapultar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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