@ocap/tx-protocols 1.30.26 → 1.31.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/esm/execute.d.mts +7 -0
- package/esm/execute.mjs +196 -71
- package/esm/gas-security-guard.d.mts +374 -0
- package/esm/gas-security-guard.mjs +1101 -0
- package/esm/index.d.mts +35 -5
- package/esm/index.mjs +3 -1
- package/esm/pipes/ensure-cost.mjs +314 -58
- package/esm/protocols/account/delegate.mjs +64 -16
- package/esm/protocols/account/migrate.d.mts +3 -0
- package/esm/protocols/account/migrate.mjs +235 -35
- package/esm/protocols/account/revoke-delegate.d.mts +3 -3
- package/esm/protocols/account/revoke-delegate.mjs +70 -38
- package/esm/protocols/asset/acquire-v2.mjs +29 -12
- package/esm/protocols/asset/acquire-v3.mjs +78 -22
- package/esm/protocols/asset/calls/transfer-token.mjs +2 -1
- package/esm/protocols/asset/calls/transfer.mjs +1 -0
- package/esm/protocols/asset/consume.mjs +12 -4
- package/esm/protocols/asset/create.mjs +18 -5
- package/esm/protocols/asset/mint.mjs +23 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +21 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +115 -1
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +14 -8
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +9 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +21 -5
- package/esm/protocols/asset/update.d.mts +13 -2
- package/esm/protocols/asset/update.mjs +133 -14
- package/esm/protocols/factory/create.mjs +14 -6
- package/esm/protocols/governance/claim-stake.mjs +92 -10
- package/esm/protocols/governance/return-stake.mjs +44 -12
- package/esm/protocols/governance/revoke-stake.mjs +17 -5
- package/esm/protocols/governance/slash-stake.mjs +64 -25
- package/esm/protocols/governance/stake.mjs +63 -13
- package/esm/protocols/rollup/claim-reward.mjs +39 -20
- package/esm/protocols/rollup/close.mjs +1 -1
- package/esm/protocols/rollup/create-block.mjs +8 -7
- package/esm/protocols/rollup/create.mjs +17 -6
- package/esm/protocols/rollup/join.mjs +3 -3
- package/esm/protocols/rollup/leave.mjs +1 -1
- package/esm/protocols/rollup/migrate.mjs +7 -4
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +12 -4
- package/esm/protocols/rollup/update.mjs +6 -1
- package/esm/protocols/token/create.mjs +23 -12
- package/esm/protocols/token/deposit-v2.d.mts +5 -1
- package/esm/protocols/token/deposit-v2.mjs +81 -29
- package/esm/protocols/token/withdraw-v2.mjs +33 -16
- package/esm/protocols/token-factory/burn.mjs +43 -10
- package/esm/protocols/token-factory/create.mjs +23 -14
- package/esm/protocols/token-factory/mint.mjs +54 -21
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +1 -1
- package/esm/protocols/token-factory/update.mjs +16 -6
- package/esm/protocols/trade/exchange-v2.d.mts +4 -0
- package/esm/protocols/trade/exchange-v2.mjs +78 -22
- package/esm/protocols/trade/transfer-v2.mjs +44 -13
- package/esm/protocols/trade/transfer-v3.mjs +72 -31
- package/esm/util.d.mts +3 -1
- package/esm/util.mjs +26 -17
- package/lib/execute.cjs +193 -67
- package/lib/execute.d.cts +7 -0
- package/lib/gas-security-guard.cjs +1140 -0
- package/lib/gas-security-guard.d.cts +374 -0
- package/lib/index.cjs +122 -1
- package/lib/index.d.cts +36 -6
- package/lib/pipes/ensure-cost.cjs +313 -57
- package/lib/protocols/account/delegate.cjs +64 -16
- package/lib/protocols/account/migrate.cjs +235 -35
- package/lib/protocols/account/migrate.d.cts +3 -0
- package/lib/protocols/account/revoke-delegate.cjs +71 -39
- package/lib/protocols/account/revoke-delegate.d.cts +3 -3
- package/lib/protocols/asset/acquire-v2.cjs +28 -11
- package/lib/protocols/asset/acquire-v3.cjs +77 -20
- package/lib/protocols/asset/calls/transfer-token.cjs +3 -2
- package/lib/protocols/asset/calls/transfer.cjs +1 -0
- package/lib/protocols/asset/consume.cjs +11 -3
- package/lib/protocols/asset/create.cjs +19 -6
- package/lib/protocols/asset/mint.cjs +23 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +117 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +21 -1
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +14 -9
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +9 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +21 -5
- package/lib/protocols/asset/update.cjs +131 -12
- package/lib/protocols/asset/update.d.cts +13 -2
- package/lib/protocols/factory/create.cjs +14 -6
- package/lib/protocols/governance/claim-stake.cjs +92 -9
- package/lib/protocols/governance/claim-stake.d.cts +1 -1
- package/lib/protocols/governance/return-stake.cjs +44 -11
- package/lib/protocols/governance/return-stake.d.cts +1 -1
- package/lib/protocols/governance/revoke-stake.cjs +17 -5
- package/lib/protocols/governance/revoke-stake.d.cts +1 -1
- package/lib/protocols/governance/slash-stake.cjs +64 -24
- package/lib/protocols/governance/slash-stake.d.cts +1 -1
- package/lib/protocols/governance/stake.cjs +65 -14
- package/lib/protocols/rollup/claim-reward.cjs +39 -20
- package/lib/protocols/rollup/close.cjs +1 -1
- package/lib/protocols/rollup/create-block.cjs +9 -8
- package/lib/protocols/rollup/create-block.d.cts +1 -1
- package/lib/protocols/rollup/create.cjs +18 -7
- package/lib/protocols/rollup/join.cjs +3 -3
- package/lib/protocols/rollup/leave.cjs +1 -1
- package/lib/protocols/rollup/migrate.cjs +7 -4
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +11 -3
- package/lib/protocols/rollup/update.cjs +6 -1
- package/lib/protocols/token/create.cjs +24 -13
- package/lib/protocols/token/deposit-v2.cjs +80 -28
- package/lib/protocols/token/deposit-v2.d.cts +5 -1
- package/lib/protocols/token/withdraw-v2.cjs +32 -15
- package/lib/protocols/token-factory/burn.cjs +42 -9
- package/lib/protocols/token-factory/create.cjs +24 -15
- package/lib/protocols/token-factory/mint.cjs +53 -20
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +1 -1
- package/lib/protocols/token-factory/update.cjs +16 -6
- package/lib/protocols/trade/exchange-v2.cjs +76 -20
- package/lib/protocols/trade/exchange-v2.d.cts +4 -0
- package/lib/protocols/trade/transfer-v2.cjs +45 -14
- package/lib/protocols/trade/transfer-v3.cjs +72 -30
- package/lib/util.cjs +26 -17
- package/lib/util.d.cts +4 -2
- package/package.json +16 -16
|
@@ -3,25 +3,53 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
6
7
|
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
7
8
|
let _ocap_state = require("@ocap/state");
|
|
8
9
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util = require("@ocap/util");
|
|
9
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
-
let
|
|
12
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
11
14
|
let debug = require("debug");
|
|
12
15
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
16
|
let _arcblock_validator = require("@arcblock/validator");
|
|
14
|
-
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
15
17
|
let lodash_flatten = require("lodash/flatten");
|
|
16
18
|
lodash_flatten = require_rolldown_runtime.__toESM(lodash_flatten);
|
|
17
19
|
let lodash_uniq = require("lodash/uniq");
|
|
18
20
|
lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
|
|
19
21
|
|
|
20
22
|
//#region src/protocols/account/migrate.ts
|
|
21
|
-
const { RoleType } = _ocap_mcrypto.types;
|
|
22
23
|
const debug$1 = (0, debug.default)("@ocap/tx-protocols:migrate");
|
|
24
|
+
function decodeAccountData(rawData) {
|
|
25
|
+
if (!rawData || typeof rawData !== "object" || Array.isArray(rawData) || rawData instanceof Uint8Array) return { payload: null };
|
|
26
|
+
const rawObj = rawData;
|
|
27
|
+
if (typeof rawObj.typeUrl === "string" && rawObj.value !== void 0 && (rawObj.value instanceof Uint8Array || typeof rawObj.value === "string" || Buffer.isBuffer(rawObj.value))) {
|
|
28
|
+
const decoded = require_util.decodeAnySafe(rawData);
|
|
29
|
+
if (decoded && typeof decoded === "object" && decoded.value && typeof decoded.value === "object" && !Array.isArray(decoded.value) && !(decoded.value instanceof Uint8Array)) return {
|
|
30
|
+
wrapperTypeUrl: typeof decoded.typeUrl === "string" ? decoded.typeUrl : "json",
|
|
31
|
+
payload: decoded.value
|
|
32
|
+
};
|
|
33
|
+
return { payload: null };
|
|
34
|
+
}
|
|
35
|
+
const extracted = (0, _arcblock_did.extractAccountPreRotationData)(rawData);
|
|
36
|
+
if (!extracted) return { payload: null };
|
|
37
|
+
if (typeof rawObj.typeUrl === "string" && rawObj.value && typeof rawObj.value === "object") return {
|
|
38
|
+
wrapperTypeUrl: rawObj.typeUrl,
|
|
39
|
+
payload: extracted
|
|
40
|
+
};
|
|
41
|
+
if (typeof rawObj.type === "string" && rawObj.value && typeof rawObj.value === "object") return {
|
|
42
|
+
wrapperType: rawObj.type,
|
|
43
|
+
payload: extracted
|
|
44
|
+
};
|
|
45
|
+
return { payload: extracted };
|
|
46
|
+
}
|
|
23
47
|
const runner = new _ocap_tx_pipeline.Runner("account_migrate");
|
|
24
|
-
|
|
48
|
+
const verifyMultiSigOne = _ocap_tx_pipeline.pipes.VerifyMultiSig(1);
|
|
49
|
+
runner.use((context, next) => {
|
|
50
|
+
if (context.tx.delegator) return next(new _ocap_util_lib_error.CustomError("INVALID_DELEGATION", "Account migration cannot be delegated"));
|
|
51
|
+
return next();
|
|
52
|
+
});
|
|
25
53
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
26
54
|
address: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
27
55
|
pk: _arcblock_validator.v.any(),
|
|
@@ -37,7 +65,10 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
|
37
65
|
message: "Receiver pk and address does not match",
|
|
38
66
|
fn: (ctx) => {
|
|
39
67
|
const context = ctx;
|
|
40
|
-
|
|
68
|
+
if (!context.itx.pk || !context.itx.address) return false;
|
|
69
|
+
const pkHex = (0, _arcblock_did.normalizePublicKeyHex)(context.itx.pk);
|
|
70
|
+
if (!pkHex) return false;
|
|
71
|
+
return (0, _arcblock_did.isSameEntity)((0, _arcblock_did.fromPublicKey)(typeof context.itx.pk === "string" ? `0x${pkHex}` : context.itx.pk, (0, _arcblock_did.toTypeInfo)(context.itx.address)), context.itx.address) && !(0, _arcblock_did.isSameEntity)(context.itx.address, context.tx.from);
|
|
41
72
|
}
|
|
42
73
|
}]));
|
|
43
74
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -50,37 +81,121 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
50
81
|
stateKey: "senderState",
|
|
51
82
|
addressKey: "tx.from"
|
|
52
83
|
}));
|
|
53
|
-
runner.use(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
85
|
+
"tx.from",
|
|
86
|
+
"senderState",
|
|
87
|
+
"itx.address"
|
|
88
|
+
] }));
|
|
89
|
+
runner.use((context, next) => {
|
|
90
|
+
const sender = context.senderState;
|
|
91
|
+
const senderAddress = sender?.address || context.tx.from;
|
|
92
|
+
const senderDecoded = decodeAccountData(sender?.data);
|
|
93
|
+
const itxDecoded = decodeAccountData(context.itx.data);
|
|
94
|
+
const senderData = senderDecoded.payload;
|
|
95
|
+
const itxData = itxDecoded.payload;
|
|
96
|
+
const hasActiveSenderCommitment = Boolean(senderData && Object.prototype.hasOwnProperty.call(senderData, "nextKeyCommitment") && senderData.nextKeyCommitment !== null && senderData.nextKeyCommitment !== void 0 && senderData.nextKeyCommitment !== "");
|
|
97
|
+
if (hasActiveSenderCommitment) {
|
|
98
|
+
const activeCommitment = senderData.nextKeyCommitment;
|
|
99
|
+
if (!(0, _arcblock_did.isValidPreRotationCommitment)(activeCommitment) || !(0, _arcblock_did.verifyPreRotationCommitment)({
|
|
100
|
+
commitment: activeCommitment,
|
|
101
|
+
publicKey: context.itx.pk,
|
|
102
|
+
address: context.itx.address
|
|
103
|
+
})) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_KEY", "Receiver public key does not match sender pre-rotation nextKeyCommitment"));
|
|
104
|
+
}
|
|
105
|
+
const hasInlineEvent = Boolean(itxData && Object.prototype.hasOwnProperty.call(itxData, "keyRotationEvent") && itxData.keyRotationEvent !== null && itxData.keyRotationEvent !== void 0);
|
|
106
|
+
let eventNextCommitment;
|
|
107
|
+
if (hasInlineEvent) {
|
|
108
|
+
const genesisDid = sender?.migratedFrom && sender.migratedFrom.length > 0 ? sender.migratedFrom[sender.migratedFrom.length - 1] : senderAddress;
|
|
109
|
+
const expectedSeq = (sender?.migratedFrom?.length ?? 0) + 1;
|
|
110
|
+
const prevLastEvent = senderData?.lastKeyRotationEvent;
|
|
111
|
+
const minRotatedAt = prevLastEvent && typeof prevLastEvent === "object" && typeof prevLastEvent.rotatedAt === "number" ? prevLastEvent.rotatedAt : void 0;
|
|
112
|
+
const evCheck = (0, _arcblock_did.verifySingleKeyRotationEvent)({
|
|
113
|
+
event: itxData.keyRotationEvent,
|
|
114
|
+
senderAddress,
|
|
115
|
+
receiverAddress: context.itx.address,
|
|
116
|
+
receiverPublicKey: context.itx.pk,
|
|
117
|
+
activePreRotationCommitment: hasActiveSenderCommitment && typeof senderData?.nextKeyCommitment === "string" ? senderData.nextKeyCommitment : void 0,
|
|
118
|
+
expectedGenesisDid: genesisDid,
|
|
119
|
+
expectedSeq,
|
|
120
|
+
minRotatedAt
|
|
121
|
+
});
|
|
122
|
+
if (!evCheck.valid) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_KEY", `Invalid KeyRotationEvent in account migration: ${evCheck.reason}`));
|
|
123
|
+
eventNextCommitment = evCheck.nextKeyCommitment;
|
|
62
124
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
125
|
+
const hasExplicitItxCommitment = Boolean(itxData && Object.prototype.hasOwnProperty.call(itxData, "nextKeyCommitment"));
|
|
126
|
+
if (hasInlineEvent && hasExplicitItxCommitment) {
|
|
127
|
+
const rawExplicit = itxData.nextKeyCommitment;
|
|
128
|
+
const isExplicitEmpty = rawExplicit === null || rawExplicit === void 0 || rawExplicit === "";
|
|
129
|
+
if (eventNextCommitment && isExplicitEmpty) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "itx.data.nextKeyCommitment cannot strip keyRotationEvent.nextKeyCommitment"));
|
|
130
|
+
if (!eventNextCommitment && !isExplicitEmpty) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "itx.data.nextKeyCommitment cannot inject an unsigned commitment absent from keyRotationEvent"));
|
|
131
|
+
}
|
|
132
|
+
const rawIncomingCommitment = hasExplicitItxCommitment ? itxData.nextKeyCommitment : eventNextCommitment;
|
|
133
|
+
if (rawIncomingCommitment !== void 0 && rawIncomingCommitment !== null && rawIncomingCommitment !== "") {
|
|
134
|
+
if (!(0, _arcblock_did.isValidPreRotationCommitment)(rawIncomingCommitment)) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "Invalid nextKeyCommitment format in account migration data"));
|
|
135
|
+
const normalizedIncoming = (0, _arcblock_did.normalizePreRotationCommitment)(rawIncomingCommitment);
|
|
136
|
+
if (hasExplicitItxCommitment && eventNextCommitment && normalizedIncoming !== eventNextCommitment) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "itx.data.nextKeyCommitment conflicts with keyRotationEvent.nextKeyCommitment"));
|
|
137
|
+
const receiverKeyType = (0, _arcblock_did.toTypeInfo)(context.itx.address).pk ?? _ocap_mcrypto.types.KeyType.ED25519;
|
|
138
|
+
if (normalizedIncoming === (0, _arcblock_did.normalizePreRotationCommitment)((0, _arcblock_did.createPreRotationCommitment)(context.itx.pk, receiverKeyType))) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "nextKeyCommitment cannot commit to the current receiver key (would deadlock future migration)"));
|
|
139
|
+
const senderPk = sender?.pk || context.tx.pk;
|
|
140
|
+
if (senderPk) {
|
|
141
|
+
if (normalizedIncoming === (0, _arcblock_did.normalizePreRotationCommitment)((0, _arcblock_did.createPreRotationCommitment)(senderPk, (0, _arcblock_did.toTypeInfo)(senderAddress).pk ?? _ocap_mcrypto.types.KeyType.ED25519))) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "nextKeyCommitment cannot commit to an already-retired key"));
|
|
142
|
+
}
|
|
143
|
+
if (typeof senderData?.previousKeyCommitment === "string" && (0, _arcblock_did.isValidPreRotationCommitment)(senderData.previousKeyCommitment) && normalizedIncoming === (0, _arcblock_did.normalizePreRotationCommitment)(senderData.previousKeyCommitment)) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "nextKeyCommitment cannot reuse a consumed historical commitment"));
|
|
144
|
+
if (Array.isArray(senderData?.consumedKeyCommitments)) {
|
|
145
|
+
for (const histCommitment of senderData.consumedKeyCommitments) if ((0, _arcblock_did.isValidPreRotationCommitment)(histCommitment) && normalizedIncoming === (0, _arcblock_did.normalizePreRotationCommitment)(histCommitment)) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "nextKeyCommitment cannot reuse a consumed historical commitment"));
|
|
72
146
|
}
|
|
73
147
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
148
|
+
context.hasVerifiedPreRotationOrEvent = Boolean(hasInlineEvent);
|
|
149
|
+
context.hasActivePreRotationCommitment = Boolean(hasActiveSenderCommitment);
|
|
150
|
+
return next();
|
|
151
|
+
});
|
|
152
|
+
const isPassiveUninitializedAccount = (state) => {
|
|
153
|
+
if (!state) return false;
|
|
154
|
+
const hasPk = Boolean(state.pk && String(state.pk).trim() !== "");
|
|
155
|
+
const hasNonce = Boolean(state.nonce && String(state.nonce) !== "0");
|
|
156
|
+
const hasMigratedFrom = Array.isArray(state.migratedFrom) && state.migratedFrom.length > 0;
|
|
157
|
+
const hasMigratedTo = Array.isArray(state.migratedTo) && state.migratedTo.length > 0;
|
|
158
|
+
return !hasPk && !hasNonce && !hasMigratedFrom && !hasMigratedTo;
|
|
159
|
+
};
|
|
160
|
+
runner.use(async (context, next) => {
|
|
161
|
+
const { statedb, itx } = context;
|
|
162
|
+
const existingReceiver = await statedb.account.get(itx.address, {
|
|
163
|
+
traceMigration: false,
|
|
164
|
+
txn: context.txn
|
|
165
|
+
}) || await statedb.account.get(itx.address, context);
|
|
166
|
+
if (existingReceiver) {
|
|
167
|
+
if (context.hasActivePreRotationCommitment && isPassiveUninitializedAccount(existingReceiver)) {
|
|
168
|
+
context.receiverState = existingReceiver;
|
|
169
|
+
return next();
|
|
170
|
+
}
|
|
171
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_RECEIVER_STATE", "Can not migrate to an existing account"));
|
|
172
|
+
}
|
|
173
|
+
return next();
|
|
174
|
+
});
|
|
175
|
+
runner.use(require_pipes_ensure_gas.default((context) => ({
|
|
176
|
+
create: context.senderState ? 1 : 2,
|
|
177
|
+
update: context.senderState ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(context.senderState).length : 0,
|
|
178
|
+
payment: 0
|
|
179
|
+
})));
|
|
80
180
|
runner.use(require_pipes_ensure_cost.default({
|
|
81
181
|
attachSenderChanges: true,
|
|
82
182
|
throwOnInsufficientFund: false
|
|
83
183
|
}));
|
|
184
|
+
runner.use((context, next) => {
|
|
185
|
+
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(context.tx, "signatures");
|
|
186
|
+
if (signatures.length === 0) {
|
|
187
|
+
if (context.hasVerifiedPreRotationOrEvent) return next();
|
|
188
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Account migration requires receiver ${context.itx.address} multi-signature in tx.signatures`));
|
|
189
|
+
}
|
|
190
|
+
if (signatures.length !== 1) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Expect 1 multi signature but found ${signatures.length}`));
|
|
191
|
+
const [sig] = signatures;
|
|
192
|
+
if (sig.delegator) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "Receiver signature in account_migrate cannot be delegated"));
|
|
193
|
+
if (!sig.signer || !(0, _arcblock_did.isSameEntity)(sig.signer, context.itx.address)) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Expect multisig signer to be ${context.itx.address} but got ${sig.signer}`));
|
|
194
|
+
const sigPkHex = (0, _arcblock_did.normalizePublicKeyHex)(sig.pk);
|
|
195
|
+
const receiverPkHex = (0, _arcblock_did.normalizePublicKeyHex)(context.itx.pk);
|
|
196
|
+
if (!sigPkHex || !receiverPkHex || sigPkHex !== receiverPkHex) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "Multisig public key does not match receiver pk"));
|
|
197
|
+
return verifyMultiSigOne(context, next);
|
|
198
|
+
});
|
|
84
199
|
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
85
200
|
runner.use(async (context, next) => {
|
|
86
201
|
const { statedb, tx, itx, senderUpdates, updateVaults } = context;
|
|
@@ -89,28 +204,113 @@ runner.use(async (context, next) => {
|
|
|
89
204
|
const tokenAddress = context.config.token.address;
|
|
90
205
|
const senderTokens = sender?.tokens || { [tokenAddress]: "0" };
|
|
91
206
|
const senderAddress = sender?.address || tx.from;
|
|
92
|
-
if (receiver) return next(new _ocap_util_lib_error.CustomError("INVALID_RECEIVER_STATE", "Can not migrate to an existing account"));
|
|
93
|
-
const
|
|
207
|
+
if (receiver && !(context.hasActivePreRotationCommitment && isPassiveUninitializedAccount(receiver))) return next(new _ocap_util_lib_error.CustomError("INVALID_RECEIVER_STATE", "Can not migrate to an existing account"));
|
|
208
|
+
const senderDecoded = decodeAccountData(sender?.data);
|
|
209
|
+
const itxDecoded = decodeAccountData(itx.data);
|
|
210
|
+
const senderData = senderDecoded.payload;
|
|
211
|
+
const itxData = itxDecoded.payload;
|
|
212
|
+
const hasSenderPreRotation = Boolean(senderData && (Object.prototype.hasOwnProperty.call(senderData, "nextKeyCommitment") || Object.prototype.hasOwnProperty.call(senderData, "previousKeyCommitment") || Object.prototype.hasOwnProperty.call(senderData, "consumedKeyCommitments") || Object.prototype.hasOwnProperty.call(senderData, "preRotationSeq")));
|
|
213
|
+
const hasIncomingPreRotation = Boolean(itxData && (Object.prototype.hasOwnProperty.call(itxData, "nextKeyCommitment") || Object.prototype.hasOwnProperty.call(itxData, "keyRotationEvent")));
|
|
214
|
+
const rawNextCommitment = Boolean(itxData && Object.prototype.hasOwnProperty.call(itxData, "nextKeyCommitment")) ? itxData.nextKeyCommitment : (itxData?.keyRotationEvent)?.nextKeyCommitment;
|
|
215
|
+
const normalizedNextCommitment = typeof rawNextCommitment === "string" && rawNextCommitment.trim() !== "" ? (0, _arcblock_did.normalizePreRotationCommitment)(rawNextCommitment) : void 0;
|
|
216
|
+
const addresses = sender ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(sender) : [senderAddress];
|
|
217
|
+
const ancestorStates = /* @__PURE__ */ new Map();
|
|
218
|
+
for (const address of addresses) if (address !== senderAddress) {
|
|
219
|
+
const old = await statedb.account.get(address, {
|
|
220
|
+
traceMigration: false,
|
|
221
|
+
txn: context.txn
|
|
222
|
+
});
|
|
223
|
+
if (old) {
|
|
224
|
+
ancestorStates.set(address, old);
|
|
225
|
+
if (normalizedNextCommitment && old.pk) {
|
|
226
|
+
const ancestorKeyType = (0, _arcblock_did.toTypeInfo)(old.address).pk ?? _ocap_mcrypto.types.KeyType.ED25519;
|
|
227
|
+
if (normalizedNextCommitment === (0, _arcblock_did.normalizePreRotationCommitment)((0, _arcblock_did.createPreRotationCommitment)(old.pk, ancestorKeyType))) return next(new _ocap_util_lib_error.CustomError("INVALID_PRE_ROTATION_COMMITMENT", "nextKeyCommitment cannot commit to an already-retired ancestor key"));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
let resolvedNewAccountData = sender?.data;
|
|
232
|
+
if (hasSenderPreRotation || hasIncomingPreRotation) {
|
|
233
|
+
const nextPayload = { ...senderData || {} };
|
|
234
|
+
const consumedSet = new Set(Array.isArray(senderData?.consumedKeyCommitments) ? senderData.consumedKeyCommitments.filter((c) => (0, _arcblock_did.isValidPreRotationCommitment)(c)).map((c) => (0, _arcblock_did.normalizePreRotationCommitment)(c)) : []);
|
|
235
|
+
const effectiveSenderPk = sender?.pk || tx.pk;
|
|
236
|
+
if (effectiveSenderPk) {
|
|
237
|
+
const senderKeyType = (0, _arcblock_did.toTypeInfo)(senderAddress).pk ?? _ocap_mcrypto.types.KeyType.ED25519;
|
|
238
|
+
consumedSet.add((0, _arcblock_did.normalizePreRotationCommitment)((0, _arcblock_did.createPreRotationCommitment)(effectiveSenderPk, senderKeyType)));
|
|
239
|
+
}
|
|
240
|
+
if (senderData && typeof senderData.nextKeyCommitment === "string" && (0, _arcblock_did.isValidPreRotationCommitment)(senderData.nextKeyCommitment)) {
|
|
241
|
+
const normalizedConsumed = (0, _arcblock_did.normalizePreRotationCommitment)(senderData.nextKeyCommitment);
|
|
242
|
+
nextPayload.previousKeyCommitment = normalizedConsumed;
|
|
243
|
+
consumedSet.add(normalizedConsumed);
|
|
244
|
+
nextPayload.preRotationSeq = (typeof nextPayload.preRotationSeq === "number" && Number.isSafeInteger(nextPayload.preRotationSeq) && nextPayload.preRotationSeq >= 0 ? nextPayload.preRotationSeq : 0) + 1;
|
|
245
|
+
}
|
|
246
|
+
if (consumedSet.size > 0) nextPayload.consumedKeyCommitments = Array.from(consumedSet).slice(-_arcblock_did.MAX_ROTATION_CHAIN_LENGTH);
|
|
247
|
+
if (normalizedNextCommitment) nextPayload.nextKeyCommitment = normalizedNextCommitment;
|
|
248
|
+
else delete nextPayload.nextKeyCommitment;
|
|
249
|
+
if (itxData?.keyRotationEvent) nextPayload.lastKeyRotationEvent = itxData.keyRotationEvent;
|
|
250
|
+
if (senderDecoded.wrapperTypeUrl) resolvedNewAccountData = {
|
|
251
|
+
typeUrl: senderDecoded.wrapperTypeUrl,
|
|
252
|
+
value: nextPayload
|
|
253
|
+
};
|
|
254
|
+
else if (senderDecoded.wrapperType) resolvedNewAccountData = {
|
|
255
|
+
type: senderDecoded.wrapperType,
|
|
256
|
+
value: nextPayload
|
|
257
|
+
};
|
|
258
|
+
else if (sender?.data && typeof sender.data === "object") resolvedNewAccountData = nextPayload;
|
|
259
|
+
else if (itxDecoded.wrapperTypeUrl) resolvedNewAccountData = {
|
|
260
|
+
typeUrl: itxDecoded.wrapperTypeUrl,
|
|
261
|
+
value: nextPayload
|
|
262
|
+
};
|
|
263
|
+
else if (itxDecoded.wrapperType) resolvedNewAccountData = {
|
|
264
|
+
type: itxDecoded.wrapperType,
|
|
265
|
+
value: nextPayload
|
|
266
|
+
};
|
|
267
|
+
else resolvedNewAccountData = {
|
|
268
|
+
type: "json",
|
|
269
|
+
value: nextPayload
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const baseSenderState = {
|
|
94
273
|
...sender || { tokens: senderTokens },
|
|
95
|
-
...senderUpdates
|
|
274
|
+
...senderUpdates
|
|
275
|
+
};
|
|
276
|
+
const mergedTokens = {};
|
|
277
|
+
for (const [tokAddr, bal] of Object.entries(baseSenderState.tokens || {})) if (bal && bal !== "0") mergedTokens[tokAddr] = bal;
|
|
278
|
+
const mergedTotalReceived = { ...baseSenderState.totalReceived || {} };
|
|
279
|
+
if (receiver) {
|
|
280
|
+
for (const [tokAddr, bal] of Object.entries(receiver.tokens || {})) {
|
|
281
|
+
const sum = (0, _ocap_util.toBN)(mergedTokens[tokAddr] || "0").add((0, _ocap_util.toBN)(bal || "0")).toString();
|
|
282
|
+
if (sum !== "0") mergedTokens[tokAddr] = sum;
|
|
283
|
+
else delete mergedTokens[tokAddr];
|
|
284
|
+
}
|
|
285
|
+
for (const [tokAddr, rec] of Object.entries(receiver.totalReceived || {})) mergedTotalReceived[tokAddr] = (0, _ocap_util.toBN)(mergedTotalReceived[tokAddr] || "0").add((0, _ocap_util.toBN)(rec || "0")).toString();
|
|
286
|
+
}
|
|
287
|
+
if (Object.keys(mergedTokens).length === 0) mergedTokens[tokenAddress] = "0";
|
|
288
|
+
const newAccountAttrs = {
|
|
289
|
+
...baseSenderState,
|
|
290
|
+
nonce: 0,
|
|
291
|
+
tokens: mergedTokens,
|
|
292
|
+
...Object.keys(mergedTotalReceived).length > 0 ? { totalReceived: mergedTotalReceived } : {},
|
|
293
|
+
...hasSenderPreRotation || hasIncomingPreRotation ? { data: resolvedNewAccountData } : {},
|
|
96
294
|
address: itx.address,
|
|
97
295
|
pk: itx.pk,
|
|
98
296
|
migratedFrom: sender ? (0, lodash_uniq.default)((0, lodash_flatten.default)([sender.address, ...sender.migratedFrom || []])) : [senderAddress]
|
|
99
|
-
}
|
|
297
|
+
};
|
|
298
|
+
const createdAccountState = _ocap_state.account.create(newAccountAttrs, context);
|
|
299
|
+
const newAccount = await statedb.account.updateOrCreate(receiver ?? null, createdAccountState, context);
|
|
100
300
|
debug$1("new account", newAccount);
|
|
101
|
-
const addresses = sender ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(sender) : [senderAddress];
|
|
102
301
|
const states = await Promise.all(addresses.map(async (address) => {
|
|
103
302
|
let state;
|
|
104
303
|
if (address === senderAddress) {
|
|
105
304
|
state = _ocap_state.account.updateOrCreate(sender ?? null, {
|
|
106
305
|
address,
|
|
306
|
+
pk: sender?.pk || tx.pk,
|
|
107
307
|
tokens: senderTokens,
|
|
108
308
|
migratedTo: [itx.address],
|
|
109
309
|
nonce: tx.nonce
|
|
110
310
|
}, context);
|
|
111
311
|
await statedb.account.updateOrCreate(sender ?? null, state, context);
|
|
112
312
|
} else {
|
|
113
|
-
const old = await statedb.account.get(address, {
|
|
313
|
+
const old = ancestorStates.get(address) || await statedb.account.get(address, {
|
|
114
314
|
traceMigration: false,
|
|
115
315
|
txn: context.txn
|
|
116
316
|
});
|
|
@@ -12,6 +12,9 @@ import { Runner } from "@ocap/tx-pipeline";
|
|
|
12
12
|
type Context = IReadyContext<TAccountMigrateTx> & Partial<IWithSender> & {
|
|
13
13
|
/** Receiver state - created during business logic */
|
|
14
14
|
receiverState?: IAccountState;
|
|
15
|
+
/** Whether receiver key was already cryptographically verified via KERI nextKeyCommitment or dual-signed keyRotationEvent */
|
|
16
|
+
hasVerifiedPreRotationOrEvent?: boolean;
|
|
17
|
+
hasActivePreRotationCommitment?: boolean;
|
|
15
18
|
};
|
|
16
19
|
declare const runner: Runner<Context>;
|
|
17
20
|
//#endregion
|
|
@@ -2,22 +2,29 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
4
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
5
6
|
let _ocap_state = require("@ocap/state");
|
|
6
7
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
|
+
let _ocap_util = require("@ocap/util");
|
|
7
9
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
11
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
12
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
13
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
8
14
|
let lodash_get = require("lodash/get");
|
|
9
15
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
10
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
16
|
let debug = require("debug");
|
|
12
17
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
|
-
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
15
|
-
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
16
18
|
let _arcblock_validator = require("@arcblock/validator");
|
|
17
19
|
|
|
18
20
|
//#region src/protocols/account/revoke-delegate.ts
|
|
19
21
|
const debug$1 = (0, debug.default)("@ocap/tx-protocols:delegate");
|
|
20
22
|
const runner = new _ocap_tx_pipeline.Runner("revoke_delegate");
|
|
23
|
+
runner.use((context, next) => {
|
|
24
|
+
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(context.tx, "signatures");
|
|
25
|
+
if (context.tx?.delegator || signatures.some((s) => Boolean(s?.delegator))) return next(new _ocap_util_lib_error.CustomError("INVALID_DELEGATION", "Delegation is not supported for this transaction", { persist: false }));
|
|
26
|
+
return next();
|
|
27
|
+
});
|
|
21
28
|
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
22
29
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
23
30
|
address: (0, _arcblock_validator.vDID)({
|
|
@@ -25,7 +32,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
25
32
|
role: "ROLE_DELEGATION"
|
|
26
33
|
}),
|
|
27
34
|
to: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
28
|
-
typeUrlsList: _arcblock_validator.v.pipe(_arcblock_validator.v.array(_arcblock_validator.v.string()), _arcblock_validator.v.minLength(1)),
|
|
35
|
+
typeUrlsList: _arcblock_validator.v.pipe(_arcblock_validator.v.array(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(256))), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(128), _arcblock_validator.v.check((arr) => new Set(arr).size === arr.length, "typeUrlsList must not contain duplicates")),
|
|
29
36
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
30
37
|
}), (0, _arcblock_validator.vStripUnknown)());
|
|
31
38
|
runner.use((context, next) => {
|
|
@@ -33,39 +40,51 @@ runner.use((context, next) => {
|
|
|
33
40
|
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
34
41
|
return next();
|
|
35
42
|
});
|
|
36
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
37
|
-
{
|
|
38
|
-
error: "OK",
|
|
39
|
-
fn: (ctx) => {
|
|
40
|
-
const context = ctx;
|
|
41
|
-
context.typeUrls = (0, _ocap_util_lib_get_list_field.getListField)(context, "itx.typeUrls");
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
error: "INVALID_TX",
|
|
47
|
-
message: "Delegation address does not match",
|
|
48
|
-
fn: (ctx) => {
|
|
49
|
-
const context = ctx;
|
|
50
|
-
return (0, _arcblock_did_util.toDelegateAddress)(context.tx.from, context.itx.to) === context.itx.address;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
error: "INVALID_DELEGATION_TYPE_URL",
|
|
55
|
-
message: "Delegation type url is not allowed",
|
|
56
|
-
fn: (ctx) => {
|
|
57
|
-
const context = ctx;
|
|
58
|
-
const allowed = (0, lodash_get.default)(context.config, "transaction.delegate.typeUrls", []);
|
|
59
|
-
return (context.typeUrls || []).every((x) => allowed.includes(x));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
]));
|
|
63
43
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
64
|
-
from: "itx.
|
|
65
|
-
to: "
|
|
66
|
-
status: "
|
|
67
|
-
table: "
|
|
44
|
+
from: "itx.to",
|
|
45
|
+
to: "receiverState",
|
|
46
|
+
status: "OK",
|
|
47
|
+
table: "account"
|
|
68
48
|
}));
|
|
49
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
50
|
+
error: "OK",
|
|
51
|
+
fn: (ctx) => {
|
|
52
|
+
const context = ctx;
|
|
53
|
+
context.typeUrls = (0, _ocap_util_lib_get_list_field.getListField)(context, "itx.typeUrls");
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
error: "INVALID_TX",
|
|
58
|
+
message: "Delegation address does not match",
|
|
59
|
+
fn: (ctx) => {
|
|
60
|
+
const context = ctx;
|
|
61
|
+
if ((0, _arcblock_did_util.toDelegateAddress)(context.tx.from, context.itx.to) === context.itx.address) return true;
|
|
62
|
+
if (context.receiverState) return (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(context.receiverState).some((addr) => (0, _arcblock_did_util.toDelegateAddress)(context.tx.from, addr) === context.itx.address);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}]));
|
|
66
|
+
runner.use(async (context, next) => {
|
|
67
|
+
const { statedb, tx, itx, receiverState } = context;
|
|
68
|
+
let delegationState = await statedb.delegation.get(itx.address, context);
|
|
69
|
+
if (!delegationState && receiverState) {
|
|
70
|
+
const related = (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(receiverState);
|
|
71
|
+
for (const addr of related) {
|
|
72
|
+
const candidateAddr = (0, _arcblock_did_util.toDelegateAddress)(tx.from, addr);
|
|
73
|
+
const candidate = await statedb.delegation.get(candidateAddr, context);
|
|
74
|
+
if (candidate) {
|
|
75
|
+
delegationState = candidate;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const allowed = (0, lodash_get.default)(context.config, "transaction.delegate.typeUrls", []);
|
|
81
|
+
const typeUrls = context.typeUrls || [];
|
|
82
|
+
const existingOps = delegationState?.ops || {};
|
|
83
|
+
if (!typeUrls.every((x) => Boolean(existingOps[x]) || (0, _ocap_util.scopeMatchAny)(x, allowed))) return next(new _ocap_util_lib_error.CustomError("INVALID_DELEGATION_TYPE_URL", "Delegation type url is not allowed"));
|
|
84
|
+
if (!delegationState) return next(new _ocap_util_lib_error.CustomError("INVALID_DELEGATION", `Invalid delegation state: ${itx.address}`));
|
|
85
|
+
context.delegationState = delegationState;
|
|
86
|
+
return next();
|
|
87
|
+
});
|
|
69
88
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
70
89
|
from: "tx.from",
|
|
71
90
|
to: "senderState",
|
|
@@ -90,11 +109,24 @@ runner.use(async (context, next) => {
|
|
|
90
109
|
typeUrls
|
|
91
110
|
});
|
|
92
111
|
const newOps = (0, lodash_cloneDeep.default)(delegationState.ops);
|
|
93
|
-
|
|
112
|
+
const deniedSubScopes = [];
|
|
113
|
+
(typeUrls || []).forEach((x) => {
|
|
114
|
+
delete newOps[x];
|
|
115
|
+
});
|
|
116
|
+
const remainingOpKeys = Object.keys(newOps);
|
|
117
|
+
(typeUrls || []).forEach((x) => {
|
|
118
|
+
if (remainingOpKeys.some((k) => (0, _ocap_util.scopeMatch)(x, k))) deniedSubScopes.push(x);
|
|
119
|
+
});
|
|
120
|
+
const newDeny = Array.from(new Set([...delegationState.deny || [], ...deniedSubScopes]));
|
|
121
|
+
const targetDelegationAddress = delegationState.address || itx.address;
|
|
94
122
|
const [newSenderState, newDelegationState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
95
123
|
...senderUpdates,
|
|
96
|
-
nonce: tx.nonce
|
|
97
|
-
|
|
124
|
+
nonce: tx.nonce,
|
|
125
|
+
pk: tx.delegator ? senderState.pk : senderState.pk || tx.pk
|
|
126
|
+
}, context), context), statedb.delegation.update(targetDelegationAddress, _ocap_state.delegation.update(delegationState, {
|
|
127
|
+
ops: newOps,
|
|
128
|
+
deny: newDeny
|
|
129
|
+
}, context), context)]);
|
|
98
130
|
if (updateVaults) await updateVaults();
|
|
99
131
|
context.senderState = newSenderState;
|
|
100
132
|
context.delegationState = newDelegationState;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IReadyContext, IWithDelegation, IWithSender, TRevokeDelegateTx } from "@ocap/types";
|
|
1
|
+
import { IReadyContext, IWithDelegation, IWithReceiver, IWithSender, TRevokeDelegateTx } from "@ocap/types";
|
|
2
2
|
import { Runner } from "@ocap/tx-pipeline";
|
|
3
3
|
|
|
4
4
|
//#region src/protocols/account/revoke-delegate.d.ts
|
|
@@ -6,9 +6,9 @@ import { Runner } from "@ocap/tx-pipeline";
|
|
|
6
6
|
/**
|
|
7
7
|
* Context type for revoke-delegate protocol.
|
|
8
8
|
* Phase: IReadyContext (after TakeStateSnapshot)
|
|
9
|
-
* Mixins: IWithSender (required), IWithDelegation (required)
|
|
9
|
+
* Mixins: IWithSender (required), IWithDelegation (required), Partial<IWithReceiver>
|
|
10
10
|
*/
|
|
11
|
-
type Context = IReadyContext<TRevokeDelegateTx> & IWithSender & IWithDelegation & {
|
|
11
|
+
type Context = IReadyContext<TRevokeDelegateTx> & IWithSender & IWithDelegation & Partial<IWithReceiver> & {
|
|
12
12
|
/** Type URLs to revoke from delegation */
|
|
13
13
|
typeUrls?: string[];
|
|
14
14
|
};
|
|
@@ -12,9 +12,10 @@ const require_protocols_asset_pipes_verify_mint_limit = require('./pipes/verify-
|
|
|
12
12
|
let _ocap_state = require("@ocap/state");
|
|
13
13
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
14
14
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
15
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
16
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
15
17
|
let debug = require("debug");
|
|
16
18
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
17
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
18
19
|
let _arcblock_validator = require("@arcblock/validator");
|
|
19
20
|
let node_util = require("node:util");
|
|
20
21
|
|
|
@@ -77,6 +78,10 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
77
78
|
to: "delegatorState",
|
|
78
79
|
status: "OK"
|
|
79
80
|
}));
|
|
81
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
82
|
+
stateKey: "delegatorState",
|
|
83
|
+
addressKey: "tx.delegator"
|
|
84
|
+
}));
|
|
80
85
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
81
86
|
from: "itx.factory",
|
|
82
87
|
to: "factoryState",
|
|
@@ -92,13 +97,14 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
|
92
97
|
const ctx = context;
|
|
93
98
|
const tokens = ctx.factoryTokens || [];
|
|
94
99
|
const assets = (0, _ocap_util_lib_get_list_field.getListField)(ctx.itx, "assets") || [];
|
|
95
|
-
|
|
100
|
+
const to = ctx.itx?.factory ? [ctx.itx.factory] : [];
|
|
101
|
+
return [...require_protocols_asset_pipes_exec_mint_hook.getMintTokenPayLegs(ctx.factoryState, tokens, ctx.config?.token?.address).map((x) => ({
|
|
96
102
|
type: "token",
|
|
97
|
-
|
|
98
|
-
value: String(x.value)
|
|
103
|
+
...x
|
|
99
104
|
})), ...assets.map((x) => ({
|
|
100
105
|
type: "asset",
|
|
101
|
-
address: x
|
|
106
|
+
address: x,
|
|
107
|
+
to
|
|
102
108
|
}))];
|
|
103
109
|
}
|
|
104
110
|
}));
|
|
@@ -160,7 +166,14 @@ runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
|
160
166
|
runner.use(require_protocols_asset_pipes_verify_mint_limit.default);
|
|
161
167
|
runner.use(require_protocols_asset_pipes_verify_itx_variables.default);
|
|
162
168
|
runner.use(require_protocols_asset_pipes_verify_itx_address.default("acquire-v2"));
|
|
163
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
169
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
170
|
+
"senderState",
|
|
171
|
+
"delegatorState",
|
|
172
|
+
"factoryOwnerState",
|
|
173
|
+
"issuerStates",
|
|
174
|
+
"issuerState",
|
|
175
|
+
"assetOwner"
|
|
176
|
+
] }));
|
|
164
177
|
runner.use(async (context, next) => {
|
|
165
178
|
const { factoryTokens = [], senderState } = context;
|
|
166
179
|
const condition = {
|
|
@@ -177,16 +190,20 @@ runner.use(async (context, next) => {
|
|
|
177
190
|
return next(err);
|
|
178
191
|
}
|
|
179
192
|
});
|
|
180
|
-
runner.use(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
runner.use((context, next) => {
|
|
194
|
+
const ownerKey = context.assetStates?.length && context.senderState && context.assetStates.every((a) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(context.senderState).includes(a.owner)) ? "senderState" : "assetOwner";
|
|
195
|
+
return _ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
196
|
+
assetKey: "assetStates",
|
|
197
|
+
ownerKey
|
|
198
|
+
})(context, next);
|
|
199
|
+
});
|
|
184
200
|
runner.use(require_protocols_asset_pipes_verify_itx_assets.default);
|
|
185
201
|
runner.use(async (context, next) => {
|
|
186
202
|
const { itx, assetOwner, assetStates = [] } = context;
|
|
187
203
|
const consumedAssets = assetStates.map((x) => x.address);
|
|
188
204
|
return next(await (0, _ocap_tx_pipeline.verifyAssetHierarchy)([itx.address], assetOwner?.address, context, void 0, consumedAssets) || void 0);
|
|
189
205
|
});
|
|
206
|
+
runner.use(require_protocols_asset_pipes_exec_mint_hook.verifyMintHook);
|
|
190
207
|
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
191
208
|
const result = {
|
|
192
209
|
create: 1,
|
|
@@ -203,7 +220,7 @@ runner.use(async (context, next) => {
|
|
|
203
220
|
const { tx, itx, txTime, statedb, senderState, assetOwner, factoryState, factoryTokens = [], delegationState, mintedAsset, mintedAddress, senderChange, updateVaults, assetStates = [] } = context;
|
|
204
221
|
const senderUpdates = {
|
|
205
222
|
nonce: tx.nonce,
|
|
206
|
-
pk: tx.pk,
|
|
223
|
+
pk: tx.delegator ? senderState.pk : tx.pk,
|
|
207
224
|
...require_util.applyTokenUpdates(factoryTokens, senderChange ? require_util.applyTokenChange(senderState, senderChange) : senderState, "sub")
|
|
208
225
|
};
|
|
209
226
|
const ownerUpdates = {};
|