ox 0.14.26 → 0.14.28

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/tempo/MultisigConfig.js +127 -0
  3. package/_cjs/tempo/MultisigConfig.js.map +1 -0
  4. package/_cjs/tempo/ReceivePolicyReceipt.js +80 -0
  5. package/_cjs/tempo/ReceivePolicyReceipt.js.map +1 -0
  6. package/_cjs/tempo/SignatureEnvelope.js +107 -6
  7. package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
  8. package/_cjs/tempo/index.js +3 -1
  9. package/_cjs/tempo/index.js.map +1 -1
  10. package/_cjs/version.js +1 -1
  11. package/_esm/tempo/MultisigConfig.js +312 -0
  12. package/_esm/tempo/MultisigConfig.js.map +1 -0
  13. package/_esm/tempo/ReceivePolicyReceipt.js +176 -0
  14. package/_esm/tempo/ReceivePolicyReceipt.js.map +1 -0
  15. package/_esm/tempo/SignatureEnvelope.js +170 -6
  16. package/_esm/tempo/SignatureEnvelope.js.map +1 -1
  17. package/_esm/tempo/index.js +48 -0
  18. package/_esm/tempo/index.js.map +1 -1
  19. package/_esm/version.js +1 -1
  20. package/_types/tempo/MultisigConfig.d.ts +270 -0
  21. package/_types/tempo/MultisigConfig.d.ts.map +1 -0
  22. package/_types/tempo/ReceivePolicyReceipt.d.ts +168 -0
  23. package/_types/tempo/ReceivePolicyReceipt.d.ts.map +1 -0
  24. package/_types/tempo/SignatureEnvelope.d.ts +106 -6
  25. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
  26. package/_types/tempo/index.d.ts +48 -0
  27. package/_types/tempo/index.d.ts.map +1 -1
  28. package/_types/version.d.ts +1 -1
  29. package/package.json +11 -1
  30. package/tempo/MultisigConfig/package.json +6 -0
  31. package/tempo/MultisigConfig.test.ts +227 -0
  32. package/tempo/MultisigConfig.ts +423 -0
  33. package/tempo/ReceivePolicyReceipt/package.json +6 -0
  34. package/tempo/ReceivePolicyReceipt.test.ts +198 -0
  35. package/tempo/ReceivePolicyReceipt.ts +263 -0
  36. package/tempo/SignatureEnvelope.test.ts +213 -2
  37. package/tempo/SignatureEnvelope.ts +257 -9
  38. package/tempo/e2e.test.ts +217 -0
  39. package/tempo/index.ts +48 -0
  40. package/version.ts +1 -1
@@ -0,0 +1,312 @@
1
+ import * as Address from '../core/Address.js';
2
+ import * as Errors from '../core/Errors.js';
3
+ import * as Hash from '../core/Hash.js';
4
+ import * as Hex from '../core/Hex.js';
5
+ /** Maximum number of owners allowed in a native multisig config. */
6
+ export const maxOwners = 10;
7
+ /** Maximum encoded byte length for one primitive owner approval. */
8
+ export const maxOwnerSignatureBytes = 2049;
9
+ /** Tempo signature type byte for native multisig signatures. */
10
+ export const signatureTypeByte = '0x05';
11
+ /** Zero 32-byte salt (the default when no salt is provided). */
12
+ export const zeroSalt = `0x${'00'.repeat(32)}`;
13
+ /** Domain prefix for the native multisig account address derivation. */
14
+ const accountDomain = 'tempo:multisig:account';
15
+ /** Domain prefix for the native multisig config ID derivation. */
16
+ const configDomain = 'tempo:multisig:config';
17
+ /** Domain prefix for native multisig owner approvals. */
18
+ const signatureDomain = 'tempo:multisig:signature';
19
+ /**
20
+ * Asserts that a native multisig {@link ox#MultisigConfig.Config} is valid.
21
+ *
22
+ * Mirrors the Tempo `validate_multisig_config` rules: owners non-empty and
23
+ * `<= maxOwners`, strictly ascending unique nonzero owner addresses, nonzero
24
+ * owner weights, `threshold >= 1`, total weight `<= u32::MAX`, and
25
+ * `threshold <= total weight`.
26
+ *
27
+ * @example
28
+ * ```ts twoslash
29
+ * import { MultisigConfig } from 'ox/tempo'
30
+ *
31
+ * MultisigConfig.assert({
32
+ * threshold: 1,
33
+ * owners: [
34
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
35
+ * ],
36
+ * })
37
+ * ```
38
+ *
39
+ * @param config - The multisig config.
40
+ */
41
+ export function assert(config) {
42
+ const { salt, threshold, owners } = config;
43
+ if (typeof salt !== 'undefined' && Hex.size(salt) !== 32)
44
+ throw new InvalidConfigError({ reason: 'salt must be 32 bytes' });
45
+ if (owners.length === 0)
46
+ throw new InvalidConfigError({ reason: 'owners cannot be empty' });
47
+ if (owners.length > maxOwners)
48
+ throw new InvalidConfigError({ reason: 'too many owners' });
49
+ if (Number(threshold) < 1)
50
+ throw new InvalidConfigError({ reason: 'threshold cannot be zero' });
51
+ let totalWeight = 0;
52
+ let previous;
53
+ for (const owner of owners) {
54
+ if (!Address.validate(owner.owner) || Hex.toBigInt(owner.owner) === 0n)
55
+ throw new InvalidConfigError({ reason: 'owner cannot be zero' });
56
+ if (Number(owner.weight) < 1)
57
+ throw new InvalidConfigError({ reason: 'owner weight cannot be zero' });
58
+ const current = Hex.toBigInt(owner.owner);
59
+ if (typeof previous !== 'undefined' && previous >= current)
60
+ throw new InvalidConfigError({
61
+ reason: 'owners must be strictly ascending',
62
+ });
63
+ previous = current;
64
+ totalWeight += Number(owner.weight);
65
+ }
66
+ if (totalWeight > 0xffffffff)
67
+ throw new InvalidConfigError({
68
+ reason: 'total owner weight exceeds u32 max',
69
+ });
70
+ if (Number(threshold) > totalWeight)
71
+ throw new InvalidConfigError({
72
+ reason: 'threshold exceeds total owner weight',
73
+ });
74
+ }
75
+ /**
76
+ * Normalizes a native multisig {@link ox#MultisigConfig.Config}.
77
+ *
78
+ * Sorts owners into strictly ascending `owner` address order (the canonical
79
+ * form required for config ID derivation) and asserts the config is valid.
80
+ *
81
+ * @example
82
+ * ```ts twoslash
83
+ * import { MultisigConfig } from 'ox/tempo'
84
+ *
85
+ * const config = MultisigConfig.from({
86
+ * threshold: 2,
87
+ * owners: [
88
+ * { owner: '0x2222222222222222222222222222222222222222', weight: 1 },
89
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
90
+ * ],
91
+ * })
92
+ * // owners are now sorted ascending by address
93
+ * ```
94
+ *
95
+ * @param config - The multisig config.
96
+ * @returns The normalized multisig config.
97
+ */
98
+ export function from(config) {
99
+ const owners = [...config.owners].sort((a, b) => Hex.toBigInt(a.owner) < Hex.toBigInt(b.owner) ? -1 : 1);
100
+ const normalized = {
101
+ salt: config.salt ? Hex.padLeft(config.salt, 32) : zeroSalt,
102
+ threshold: config.threshold,
103
+ owners,
104
+ };
105
+ assert(normalized);
106
+ return normalized;
107
+ }
108
+ /**
109
+ * Converts an RLP {@link ox#MultisigConfig.Tuple} back to a
110
+ * {@link ox#MultisigConfig.Config}.
111
+ *
112
+ * @example
113
+ * ```ts twoslash
114
+ * import { MultisigConfig } from 'ox/tempo'
115
+ *
116
+ * const config = MultisigConfig.fromTuple([
117
+ * `0x${'00'.repeat(32)}`,
118
+ * '0x01',
119
+ * [['0x1111111111111111111111111111111111111111', '0x01']],
120
+ * ])
121
+ * ```
122
+ *
123
+ * @param tuple - The RLP tuple.
124
+ * @returns The multisig config.
125
+ */
126
+ export function fromTuple(tuple) {
127
+ const [salt, threshold, owners] = tuple;
128
+ return {
129
+ salt: salt && salt !== '0x' ? Hex.padLeft(salt, 32) : zeroSalt,
130
+ threshold: threshold === '0x' ? 0 : Hex.toNumber(threshold),
131
+ owners: owners.map((owner) => {
132
+ const [ownerAddress, weight] = owner;
133
+ return {
134
+ owner: ownerAddress,
135
+ weight: !weight || weight === '0x' ? 0 : Hex.toNumber(weight),
136
+ };
137
+ }),
138
+ };
139
+ }
140
+ /**
141
+ * Derives the stable native multisig account address.
142
+ *
143
+ * `keccak256("tempo:multisig:account" || config_id)[12:32]`.
144
+ *
145
+ * @example
146
+ * ```ts twoslash
147
+ * import { MultisigConfig } from 'ox/tempo'
148
+ *
149
+ * const config = MultisigConfig.from({
150
+ * threshold: 1,
151
+ * owners: [
152
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
153
+ * ],
154
+ * })
155
+ *
156
+ * const address = MultisigConfig.getAddress({ config })
157
+ * ```
158
+ *
159
+ * @param value - The config or config ID to derive the address from.
160
+ * @returns The multisig account address.
161
+ */
162
+ export function getAddress(value) {
163
+ const id = 'configId' in value ? value.configId : toId(value.config);
164
+ const hash = Hash.keccak256(Hex.concat(Hex.fromString(accountDomain), id));
165
+ return Address.from(Hex.slice(hash, 12, 32));
166
+ }
167
+ /**
168
+ * Computes the digest a native multisig owner approves (signs).
169
+ *
170
+ * `keccak256("tempo:multisig:signature" || inner_digest || account || config_id)`,
171
+ * where `inner_digest` is the transaction sign payload
172
+ * ({@link ox#TxEnvelopeTempo.(getSignPayload:function)}).
173
+ *
174
+ * @example
175
+ * ```ts twoslash
176
+ * import { MultisigConfig, TxEnvelopeTempo } from 'ox/tempo'
177
+ *
178
+ * const config = MultisigConfig.from({
179
+ * threshold: 1,
180
+ * owners: [
181
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
182
+ * ],
183
+ * })
184
+ * const configId = MultisigConfig.toId(config)
185
+ * const account = MultisigConfig.getAddress({ configId })
186
+ *
187
+ * const envelope = TxEnvelopeTempo.from({
188
+ * chainId: 1,
189
+ * calls: [],
190
+ * })
191
+ *
192
+ * const digest = MultisigConfig.getSignPayload({
193
+ * payload: TxEnvelopeTempo.getSignPayload(envelope),
194
+ * account,
195
+ * configId,
196
+ * })
197
+ * ```
198
+ *
199
+ * @param value - The digest derivation parameters.
200
+ * @returns The owner approval digest.
201
+ */
202
+ export function getSignPayload(value) {
203
+ const { payload, account, configId } = value;
204
+ return Hash.keccak256(Hex.concat(Hex.fromString(signatureDomain), Hex.from(payload), account, configId));
205
+ }
206
+ /**
207
+ * Derives the permanent config ID for a native multisig
208
+ * {@link ox#MultisigConfig.Config}.
209
+ *
210
+ * Preimage (fixed-width big-endian, **not** RLP):
211
+ * `keccak256("tempo:multisig:config" || salt || be_u32(threshold) || be_u32(owners.length) || (owner || be_u32(weight)) for each owner)`.
212
+ *
213
+ * @example
214
+ * ```ts twoslash
215
+ * import { MultisigConfig } from 'ox/tempo'
216
+ *
217
+ * const config = MultisigConfig.from({
218
+ * threshold: 1,
219
+ * owners: [
220
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
221
+ * ],
222
+ * })
223
+ *
224
+ * const configId = MultisigConfig.toId(config)
225
+ * ```
226
+ *
227
+ * @param config - The multisig config.
228
+ * @returns The 32-byte config ID.
229
+ */
230
+ export function toId(config) {
231
+ assert(config);
232
+ const id = Hash.keccak256(Hex.concat(Hex.fromString(configDomain), Hex.padLeft(config.salt ?? zeroSalt, 32), Hex.fromNumber(config.threshold, { size: 4 }), Hex.fromNumber(config.owners.length, { size: 4 }), ...config.owners.flatMap((owner) => [
233
+ owner.owner,
234
+ Hex.fromNumber(owner.weight, { size: 4 }),
235
+ ])));
236
+ if (Hex.toBigInt(id) === 0n)
237
+ throw new InvalidConfigError({ reason: 'config ID cannot be zero' });
238
+ return id;
239
+ }
240
+ /**
241
+ * Converts a {@link ox#MultisigConfig.Config} to its RLP tuple form (carried
242
+ * by the multisig signature `init`).
243
+ *
244
+ * Tuple shape: `[salt, threshold, [[owner, weight], ...]]`. The
245
+ * 32-byte `salt` encodes as a full fixed-width string; other integers use
246
+ * canonical RLP encoding (zero values encode as `0x`).
247
+ *
248
+ * @example
249
+ * ```ts twoslash
250
+ * import { MultisigConfig } from 'ox/tempo'
251
+ *
252
+ * const tuple = MultisigConfig.toTuple({
253
+ * threshold: 1,
254
+ * owners: [
255
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
256
+ * ],
257
+ * })
258
+ * ```
259
+ *
260
+ * @param config - The multisig config.
261
+ * @returns The RLP tuple.
262
+ */
263
+ export function toTuple(config) {
264
+ assert(config);
265
+ const owners = config.owners.map((owner) => [owner.owner, Hex.fromNumber(owner.weight)]);
266
+ // `salt` is a fixed 32-byte value: it RLP-encodes as a full 32-byte string
267
+ // (including the zero salt), never trimmed like an integer.
268
+ const salt = config.salt ? Hex.padLeft(config.salt, 32) : zeroSalt;
269
+ return [salt, Hex.fromNumber(config.threshold), owners];
270
+ }
271
+ /**
272
+ * Validates a native multisig {@link ox#MultisigConfig.Config}. Returns `true`
273
+ * if valid, `false` otherwise.
274
+ *
275
+ * @example
276
+ * ```ts twoslash
277
+ * import { MultisigConfig } from 'ox/tempo'
278
+ *
279
+ * const valid = MultisigConfig.validate({
280
+ * threshold: 1,
281
+ * owners: [
282
+ * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
283
+ * ],
284
+ * })
285
+ * // @log: true
286
+ * ```
287
+ *
288
+ * @param config - The multisig config.
289
+ * @returns Whether the config is valid.
290
+ */
291
+ export function validate(config) {
292
+ try {
293
+ assert(config);
294
+ return true;
295
+ }
296
+ catch {
297
+ return false;
298
+ }
299
+ }
300
+ /** Thrown when a native multisig config is invalid. */
301
+ export class InvalidConfigError extends Errors.BaseError {
302
+ constructor({ reason }) {
303
+ super(`Invalid native multisig config: ${reason}.`);
304
+ Object.defineProperty(this, "name", {
305
+ enumerable: true,
306
+ configurable: true,
307
+ writable: true,
308
+ value: 'MultisigConfig.InvalidConfigError'
309
+ });
310
+ }
311
+ }
312
+ //# sourceMappingURL=MultisigConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultisigConfig.js","sourceRoot":"","sources":["../../tempo/MultisigConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAE7C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAGrC,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAA;AAE3B,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAA;AAE1C,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAe,CAAA;AAEhD,gEAAgE;AAChE,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAW,CAAA;AAEvD,wEAAwE;AACxE,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AAE,0BAA0B,EAAE,CAAC,CAAA;IACtE,OAAO,EAAE,CAAA;AACX,CAAC;AAYD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,OAAO,CAAC,MAAc;IACpC,MAAM,CAAC,MAAM,CAAC,CAAA;IACd,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAC9B,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAc,CACpE,CAAA;IACD,2EAA2E;IAC3E,4DAA4D;IAC5D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;IAClE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAU,CAAA;AAClE,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,IAAI,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAA;QACd,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED,uDAAuD;AACvD,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,SAAS;IAEtD,YAAY,EAAE,MAAM,EAAsB;QACxC,KAAK,CAAC,mCAAmC,MAAM,GAAG,CAAC,CAAA;QAFnC;;;;mBAAO,mCAAmC;WAAA;IAG5D,CAAC;CACF"}
@@ -0,0 +1,176 @@
1
+ import * as AbiEvent from '../core/AbiEvent.js';
2
+ import * as AbiParameters from '../core/AbiParameters.js';
3
+ /** @internal */
4
+ const blockedReasons = ['none', 'tokenFilter', 'receivePolicy'];
5
+ /** @internal */
6
+ const kinds = ['transfer', 'mint'];
7
+ /** @internal ABI parameters for the `ClaimReceiptV1` witness. */
8
+ const parameters = [
9
+ {
10
+ type: 'tuple',
11
+ components: [
12
+ { name: 'version', type: 'uint8' },
13
+ { name: 'token', type: 'address' },
14
+ { name: 'recoveryAuthority', type: 'address' },
15
+ { name: 'originator', type: 'address' },
16
+ { name: 'recipient', type: 'address' },
17
+ { name: 'blockedAt', type: 'uint64' },
18
+ { name: 'blockedNonce', type: 'uint64' },
19
+ { name: 'blockedReason', type: 'uint8' },
20
+ { name: 'kind', type: 'uint8' },
21
+ { name: 'memo', type: 'bytes32' },
22
+ ],
23
+ },
24
+ ];
25
+ /** @internal `TransferBlocked` event emitted by the `ReceivePolicyGuard`. */
26
+ const transferBlocked = AbiEvent.from('event TransferBlocked(address indexed token, address indexed receiver, uint64 indexed blockedNonce, uint256 amount, uint8 receiptVersion, bytes receipt)');
27
+ /**
28
+ * Decodes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} (ABI-encoded
29
+ * `ClaimReceiptV1` witness) into its fields.
30
+ *
31
+ * [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
32
+ *
33
+ * @example
34
+ * ```ts twoslash
35
+ * import { ReceivePolicyReceipt } from 'ox/tempo'
36
+ *
37
+ * const decoded = ReceivePolicyReceipt.decode('0x...')
38
+ * ```
39
+ *
40
+ * @param receipt - The receive-policy receipt.
41
+ * @returns The decoded fields.
42
+ */
43
+ export function decode(receipt) {
44
+ const [decoded] = AbiParameters.decode(parameters, receipt);
45
+ return {
46
+ version: decoded.version,
47
+ token: decoded.token,
48
+ recoveryAuthority: decoded.recoveryAuthority,
49
+ originator: decoded.originator,
50
+ recipient: decoded.recipient,
51
+ blockedAt: decoded.blockedAt,
52
+ blockedNonce: decoded.blockedNonce,
53
+ blockedReason: blockedReasons[decoded.blockedReason] ?? 'none',
54
+ kind: kinds[decoded.kind] ?? 'transfer',
55
+ memo: decoded.memo,
56
+ };
57
+ }
58
+ /**
59
+ * Encodes decoded fields into a
60
+ * {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt}. Inverse of `decode`.
61
+ *
62
+ * [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
63
+ *
64
+ * @example
65
+ * ```ts twoslash
66
+ * // @noErrors
67
+ * import { ReceivePolicyReceipt } from 'ox/tempo'
68
+ *
69
+ * const decoded = ReceivePolicyReceipt.decode('0x...')
70
+ * const receipt = ReceivePolicyReceipt.encode(decoded)
71
+ * ```
72
+ *
73
+ * @param decoded - The decoded fields.
74
+ * @returns The receive-policy receipt.
75
+ */
76
+ export function encode(decoded) {
77
+ return AbiParameters.encode(parameters, [
78
+ {
79
+ version: decoded.version,
80
+ token: decoded.token,
81
+ recoveryAuthority: decoded.recoveryAuthority,
82
+ originator: decoded.originator,
83
+ recipient: decoded.recipient,
84
+ blockedAt: decoded.blockedAt,
85
+ blockedNonce: decoded.blockedNonce,
86
+ blockedReason: blockedReasons.indexOf(decoded.blockedReason),
87
+ kind: kinds.indexOf(decoded.kind),
88
+ memo: decoded.memo,
89
+ },
90
+ ]);
91
+ }
92
+ /**
93
+ * Normalizes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from either
94
+ * an encoded receipt (passthrough) or decoded fields.
95
+ *
96
+ * [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
97
+ *
98
+ * @example
99
+ * ```ts twoslash
100
+ * // @noErrors
101
+ * import { ReceivePolicyReceipt } from 'ox/tempo'
102
+ *
103
+ * // From an encoded receipt (passthrough).
104
+ * const a = ReceivePolicyReceipt.from('0x...')
105
+ *
106
+ * // From decoded fields.
107
+ * const b = ReceivePolicyReceipt.from(ReceivePolicyReceipt.decode('0x...'))
108
+ * ```
109
+ *
110
+ * @param value - An encoded receipt or decoded fields.
111
+ * @returns The receive-policy receipt.
112
+ */
113
+ export function from(value) {
114
+ if (typeof value === 'string')
115
+ return value;
116
+ return encode(value);
117
+ }
118
+ /**
119
+ * Extracts the {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
120
+ * `ReceivePolicyGuard` `TransferBlocked` log.
121
+ *
122
+ * Throws if the log is not a `TransferBlocked` event. Use
123
+ * `fromTransactionReceipt` to extract every blocked transfer in a transaction
124
+ * (which skips unrelated logs).
125
+ *
126
+ * [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
127
+ *
128
+ * @example
129
+ * ```ts twoslash
130
+ * // @noErrors
131
+ * import { ReceivePolicyReceipt } from 'ox/tempo'
132
+ *
133
+ * const receipt = ReceivePolicyReceipt.fromLog(log)
134
+ * ```
135
+ *
136
+ * @param log - A `TransferBlocked` log (`data` & `topics`).
137
+ * @returns The receive-policy receipt.
138
+ */
139
+ export function fromLog(log) {
140
+ const { receipt } = AbiEvent.decode(transferBlocked, log);
141
+ return receipt;
142
+ }
143
+ /**
144
+ * Extracts every {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
145
+ * transaction receipt's logs.
146
+ *
147
+ * A single transaction may block multiple inbound transfers (e.g. a batched
148
+ * transfer to several recipients), so this returns an array – one entry per
149
+ * `TransferBlocked` log, in log order. Returns an empty array when no transfers
150
+ * were blocked.
151
+ *
152
+ * [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
153
+ *
154
+ * @example
155
+ * ```ts twoslash
156
+ * // @noErrors
157
+ * import { ReceivePolicyReceipt } from 'ox/tempo'
158
+ *
159
+ * const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
160
+ * // @log: ['0x...'] (pass each to `claim` / `burn`)
161
+ * ```
162
+ *
163
+ * @param receipt - The transaction receipt (or any object with `logs`).
164
+ * @returns The receive-policy receipts, one per blocked transfer.
165
+ */
166
+ export function fromTransactionReceipt(receipt) {
167
+ const selector = AbiEvent.getSelector(transferBlocked);
168
+ const receipts = [];
169
+ for (const log of receipt.logs ?? []) {
170
+ if (log.topics[0] !== selector)
171
+ continue;
172
+ receipts.push(fromLog(log));
173
+ }
174
+ return receipts;
175
+ }
176
+ //# sourceMappingURL=ReceivePolicyReceipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReceivePolicyReceipt.js","sourceRoot":"","sources":["../../tempo/ReceivePolicyReceipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAA;AA+CzD,gBAAgB;AAChB,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,eAAe,CAAU,CAAA;AAExE,gBAAgB;AAChB,MAAM,KAAK,GAAG,CAAC,UAAU,EAAE,MAAM,CAAU,CAAA;AAE3C,iEAAiE;AACjE,MAAM,UAAU,GAAG;IACjB;QACE,IAAI,EAAE,OAAO;QACb,UAAU,EAAE;YACV,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;YAClC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;YAC9C,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;YACvC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;YACtC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;YACrC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;YACxC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;YAC/B,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;SAClC;KACF;CACO,CAAA;AAEV,6EAA6E;AAC7E,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CACnC,0JAA0J,CAC3J,CAAA;AAED;;;;;;;;;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