@naculus/connect-appkit-core 0.14.0 → 0.15.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/dist/index.cjs +70 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +70 -15
- package/dist/index.js.map +1 -1
- package/package.json +12 -9
package/dist/index.cjs
CHANGED
|
@@ -1010,8 +1010,21 @@ function createDelegationFrameworkAdapter(options) {
|
|
|
1010
1010
|
execution,
|
|
1011
1011
|
unsigned
|
|
1012
1012
|
};
|
|
1013
|
+
const hex = (value2) => `0x${value2.toString(16)}`;
|
|
1013
1014
|
return {
|
|
1014
1015
|
digest: codec.signingHash(unsigned),
|
|
1016
|
+
// The same redemption as `unsigned`, as a request for the digest check.
|
|
1017
|
+
request: {
|
|
1018
|
+
type: "eip1559",
|
|
1019
|
+
chainId: unsigned.chainId,
|
|
1020
|
+
nonce: hex(unsigned.nonce),
|
|
1021
|
+
to: unsigned.to,
|
|
1022
|
+
value: hex(unsigned.value),
|
|
1023
|
+
data: unsigned.data,
|
|
1024
|
+
gas: hex(unsigned.gas),
|
|
1025
|
+
maxFeePerGas: hex(unsigned.maxFeePerGas),
|
|
1026
|
+
maxPriorityFeePerGas: hex(unsigned.maxPriorityFeePerGas)
|
|
1027
|
+
},
|
|
1015
1028
|
transaction,
|
|
1016
1029
|
payload
|
|
1017
1030
|
};
|
|
@@ -1028,6 +1041,7 @@ function createDelegationFrameworkAdapter(options) {
|
|
|
1028
1041
|
|
|
1029
1042
|
// src/delegation-policy.ts
|
|
1030
1043
|
var import_connect_core16 = require("@naculus/connect-core");
|
|
1044
|
+
var import_signing = require("@naculus/connect-core/signing");
|
|
1031
1045
|
function delegatesToStatelessDeleGator(delegation) {
|
|
1032
1046
|
return delegation.delegated === true && delegation.delegate?.toLowerCase() === import_connect_core16.DELEGATION_FRAMEWORK.eip7702StatelessDeleGator.toLowerCase();
|
|
1033
1047
|
}
|
|
@@ -1303,16 +1317,39 @@ function createDelegationPolicyFlow(deps) {
|
|
|
1303
1317
|
reason
|
|
1304
1318
|
};
|
|
1305
1319
|
};
|
|
1306
|
-
const signVerified = (policyId,
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1320
|
+
const signVerified = (policyId, prepared) => {
|
|
1321
|
+
const { request } = prepared;
|
|
1322
|
+
const computed = `0x${Array.from(
|
|
1323
|
+
(0, import_signing.transactionSigningHash)(request),
|
|
1324
|
+
(byte) => byte.toString(16).padStart(2, "0")
|
|
1325
|
+
).join("")}`;
|
|
1326
|
+
if (computed !== prepared.digest.toLowerCase()) {
|
|
1327
|
+
throw new import_connect_core16.WalletError(
|
|
1328
|
+
"invalid_input",
|
|
1329
|
+
`The prepared digest ${prepared.digest} does not match the signing hash ${computed} of the prepared transaction request.`
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
if (!sameExecutionIntent(prepared.transaction, {
|
|
1333
|
+
to: request.to,
|
|
1334
|
+
value: request.value,
|
|
1335
|
+
data: request.data,
|
|
1336
|
+
chainId: request.chainId
|
|
1337
|
+
})) {
|
|
1338
|
+
throw new import_connect_core16.WalletError(
|
|
1339
|
+
"invalid_input",
|
|
1340
|
+
"The prepared transaction request differs from the prepared transaction checked by the policy."
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
return manager.signTransactionWithVerifiedOffchainAuthorization(
|
|
1344
|
+
policyId,
|
|
1345
|
+
(authoritativePolicy) => buildDelegationPolicyMessage(authoritativePolicy, origin),
|
|
1346
|
+
deps.verifySignature,
|
|
1347
|
+
request
|
|
1348
|
+
);
|
|
1349
|
+
};
|
|
1313
1350
|
const signRedemption = (policyId, prepared) => {
|
|
1314
1351
|
const payload = prepared.payload;
|
|
1315
|
-
if (!payload?.outerTx || !payload.execution) {
|
|
1352
|
+
if (!payload?.outerTx || !payload.execution || !payload.unsigned) {
|
|
1316
1353
|
throw new import_connect_core16.WalletError(
|
|
1317
1354
|
"invalid_input",
|
|
1318
1355
|
"The EIP-7702 adapter did not return a redemption to sign."
|
|
@@ -1336,15 +1373,33 @@ function createDelegationPolicyFlow(deps) {
|
|
|
1336
1373
|
"The EIP-7702 adapter's execution differs from the requested transaction."
|
|
1337
1374
|
);
|
|
1338
1375
|
}
|
|
1339
|
-
|
|
1376
|
+
const { unsigned } = payload;
|
|
1377
|
+
const hex = (value) => `0x${value.toString(16)}`;
|
|
1378
|
+
const tx = {
|
|
1379
|
+
type: "eip1559",
|
|
1380
|
+
chainId: unsigned.chainId,
|
|
1381
|
+
nonce: hex(unsigned.nonce),
|
|
1382
|
+
to: unsigned.to,
|
|
1383
|
+
value: hex(unsigned.value),
|
|
1384
|
+
data: unsigned.data,
|
|
1385
|
+
gas: hex(unsigned.gas),
|
|
1386
|
+
maxFeePerGas: hex(unsigned.maxFeePerGas),
|
|
1387
|
+
maxPriorityFeePerGas: hex(unsigned.maxPriorityFeePerGas)
|
|
1388
|
+
};
|
|
1389
|
+
return manager.signTransactionDelegationRedemption(
|
|
1340
1390
|
policyId,
|
|
1341
|
-
|
|
1342
|
-
payload.outerTx,
|
|
1391
|
+
tx,
|
|
1392
|
+
{ gas: payload.outerTx.gas },
|
|
1343
1393
|
payload.execution
|
|
1344
1394
|
);
|
|
1345
1395
|
};
|
|
1346
|
-
const signPolicyDigest = async (policyId,
|
|
1347
|
-
const preview = await previewPolicyExecution(
|
|
1396
|
+
const signPolicyDigest = async (policyId, prepared) => {
|
|
1397
|
+
const preview = await previewPolicyExecution(
|
|
1398
|
+
policyId,
|
|
1399
|
+
prepared.transaction,
|
|
1400
|
+
1,
|
|
1401
|
+
"any"
|
|
1402
|
+
);
|
|
1348
1403
|
if (preview.policy?.scope.mode === "eip7702") {
|
|
1349
1404
|
throw new import_connect_core16.WalletError(
|
|
1350
1405
|
"method_not_allowed",
|
|
@@ -1354,7 +1409,7 @@ function createDelegationPolicyFlow(deps) {
|
|
|
1354
1409
|
if (!preview.ready) {
|
|
1355
1410
|
throw new import_connect_core16.WalletError("method_not_allowed", preview.reason);
|
|
1356
1411
|
}
|
|
1357
|
-
return signVerified(policyId,
|
|
1412
|
+
return signVerified(policyId, prepared);
|
|
1358
1413
|
};
|
|
1359
1414
|
const executePolicy = async (policyId, tx) => {
|
|
1360
1415
|
const adapter = deps.adapter;
|
|
@@ -1396,7 +1451,7 @@ function createDelegationPolicyFlow(deps) {
|
|
|
1396
1451
|
currentCheck.reason || "The on-chain policy authorization is not ready."
|
|
1397
1452
|
);
|
|
1398
1453
|
}
|
|
1399
|
-
const signature = preview.policy.scope.mode === "eip7702" ? await signRedemption(policyId, prepared) : await signVerified(policyId, prepared
|
|
1454
|
+
const signature = preview.policy.scope.mode === "eip7702" ? await signRedemption(policyId, prepared) : await signVerified(policyId, prepared);
|
|
1400
1455
|
const submission = await adapter.broadcast({
|
|
1401
1456
|
policy: preview.policy,
|
|
1402
1457
|
prepared,
|