ox 0.14.7 → 0.14.8
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/CHANGELOG.md +6 -0
- package/_cjs/erc8021/Attribution.js +74 -2
- package/_cjs/erc8021/Attribution.js.map +1 -1
- package/_cjs/erc8021/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/erc8021/Attribution.js +118 -9
- package/_esm/erc8021/Attribution.js.map +1 -1
- package/_esm/erc8021/index.js +5 -0
- package/_esm/erc8021/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/erc8021/Attribution.d.ts +70 -8
- package/_types/erc8021/Attribution.d.ts.map +1 -1
- package/_types/erc8021/index.d.ts +5 -0
- package/_types/erc8021/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/erc8021/Attribution.ts +190 -11
- package/erc8021/index.ts +5 -0
- package/package.json +1 -1
- package/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# ox
|
|
2
2
|
|
|
3
|
+
## 0.14.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0d0575e`](https://github.com/wevm/ox/commit/0d0575e36503403ce245eaaaf29aac106bad508a) Thanks [@jxom](https://github.com/jxom)! - Added ERC-8021 Schema 2 (CBOR-encoded) attribution support to the `Attribution` module.
|
|
8
|
+
|
|
3
9
|
## 0.14.7
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -4,19 +4,26 @@ exports.ercSuffixSize = exports.ercSuffix = void 0;
|
|
|
4
4
|
exports.getSchemaId = getSchemaId;
|
|
5
5
|
exports.toDataSuffix = toDataSuffix;
|
|
6
6
|
exports.fromData = fromData;
|
|
7
|
+
const Cbor = require("../core/Cbor.js");
|
|
7
8
|
const Hex = require("../core/Hex.js");
|
|
8
9
|
exports.ercSuffix = '0x80218021802180218021802180218021';
|
|
9
10
|
exports.ercSuffixSize = Hex.size(exports.ercSuffix);
|
|
10
11
|
function getSchemaId(attribution) {
|
|
12
|
+
if ('appCode' in attribution || 'walletCode' in attribution)
|
|
13
|
+
return 2;
|
|
11
14
|
if ('codeRegistry' in attribution)
|
|
12
15
|
return 1;
|
|
13
16
|
return 0;
|
|
14
17
|
}
|
|
15
18
|
function toDataSuffix(attribution) {
|
|
16
|
-
const
|
|
19
|
+
const schemaId = getSchemaId(attribution);
|
|
20
|
+
if (schemaId === 2) {
|
|
21
|
+
const schema2 = attribution;
|
|
22
|
+
return schema2ToDataSuffix(schema2);
|
|
23
|
+
}
|
|
24
|
+
const codesHex = Hex.fromString((attribution.codes ?? []).join(','));
|
|
17
25
|
const codesLength = Hex.size(codesHex);
|
|
18
26
|
const codesLengthHex = Hex.fromNumber(codesLength, { size: 1 });
|
|
19
|
-
const schemaId = getSchemaId(attribution);
|
|
20
27
|
const schemaIdHex = Hex.fromNumber(schemaId, { size: 1 });
|
|
21
28
|
if (schemaId === 1) {
|
|
22
29
|
const schema1 = attribution;
|
|
@@ -60,6 +67,9 @@ function fromData(data) {
|
|
|
60
67
|
id: 1,
|
|
61
68
|
};
|
|
62
69
|
}
|
|
70
|
+
if (schemaId === 2) {
|
|
71
|
+
return schema2FromData(data);
|
|
72
|
+
}
|
|
63
73
|
return undefined;
|
|
64
74
|
}
|
|
65
75
|
function registryFromData(data) {
|
|
@@ -89,4 +99,66 @@ function registryToData(registry) {
|
|
|
89
99
|
const paddedChainId = Hex.padLeft(chainIdAsHex, chainIdLen);
|
|
90
100
|
return Hex.concat(registry.address, paddedChainId, Hex.fromNumber(chainIdLen, { size: 1 }));
|
|
91
101
|
}
|
|
102
|
+
function schema2ToDataSuffix(attribution) {
|
|
103
|
+
const cborMap = {};
|
|
104
|
+
if (attribution.appCode)
|
|
105
|
+
cborMap.a = attribution.appCode;
|
|
106
|
+
if (attribution.walletCode)
|
|
107
|
+
cborMap.w = attribution.walletCode;
|
|
108
|
+
if (attribution.registries) {
|
|
109
|
+
const r = {};
|
|
110
|
+
if (attribution.registries.app) {
|
|
111
|
+
r.a = {
|
|
112
|
+
c: Hex.fromNumber(attribution.registries.app.chainId),
|
|
113
|
+
a: attribution.registries.app.address,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (attribution.registries.wallet) {
|
|
117
|
+
r.w = {
|
|
118
|
+
c: Hex.fromNumber(attribution.registries.wallet.chainId),
|
|
119
|
+
a: attribution.registries.wallet.address,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (r.a || r.w)
|
|
123
|
+
cborMap.r = r;
|
|
124
|
+
}
|
|
125
|
+
if (attribution.metadata && Object.keys(attribution.metadata).length > 0)
|
|
126
|
+
cborMap.m = attribution.metadata;
|
|
127
|
+
const cborHex = Cbor.encode(cborMap);
|
|
128
|
+
const cborBytes = Hex.size(cborHex);
|
|
129
|
+
return Hex.concat(cborHex, Hex.fromNumber(cborBytes, { size: 2 }), Hex.fromNumber(2, { size: 1 }), exports.ercSuffix);
|
|
130
|
+
}
|
|
131
|
+
function schema2FromData(data) {
|
|
132
|
+
const cborLengthHex = Hex.slice(data, -exports.ercSuffixSize - 1 - 2, -exports.ercSuffixSize - 1);
|
|
133
|
+
const cborLength = Hex.toNumber(cborLengthHex);
|
|
134
|
+
const cborStart = -exports.ercSuffixSize - 1 - 2 - cborLength;
|
|
135
|
+
const cborEnd = -exports.ercSuffixSize - 1 - 2;
|
|
136
|
+
const cborHex = Hex.slice(data, cborStart, cborEnd);
|
|
137
|
+
const decoded = Cbor.decode(cborHex);
|
|
138
|
+
const result = { id: 2 };
|
|
139
|
+
if (typeof decoded.a === 'string')
|
|
140
|
+
result.appCode = decoded.a;
|
|
141
|
+
if (typeof decoded.w === 'string')
|
|
142
|
+
result.walletCode = decoded.w;
|
|
143
|
+
if (decoded.r) {
|
|
144
|
+
const registries = {};
|
|
145
|
+
if (decoded.r.a?.c && decoded.r.a?.a) {
|
|
146
|
+
registries.app = {
|
|
147
|
+
address: decoded.r.a.a,
|
|
148
|
+
chainId: Hex.toNumber(decoded.r.a.c),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (decoded.r.w?.c && decoded.r.w?.a) {
|
|
152
|
+
registries.wallet = {
|
|
153
|
+
address: decoded.r.w.a,
|
|
154
|
+
chainId: Hex.toNumber(decoded.r.w.c),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (registries.app || registries.wallet)
|
|
158
|
+
result.registries = registries;
|
|
159
|
+
}
|
|
160
|
+
if (decoded.m && typeof decoded.m === 'object')
|
|
161
|
+
result.metadata = decoded.m;
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
92
164
|
//# sourceMappingURL=Attribution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Attribution.js","sourceRoot":"","sources":["../../erc8021/Attribution.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Attribution.js","sourceRoot":"","sources":["../../erc8021/Attribution.ts"],"names":[],"mappings":";;;AAuIA,kCAIC;AAoDD,oCAmCC;AA8DD,4BAoEC;AAnWD,wCAAuC;AAEvC,sCAAqC;AA+FxB,QAAA,SAAS,GAAG,oCAA6C,CAAA;AAKzD,QAAA,aAAa,GAAiB,GAAG,CAAC,IAAI,CAAC,iBAAS,CAAC,CAAA;AAgC9D,SAAgB,WAAW,CAAC,WAAwB;IAClD,IAAI,SAAS,IAAI,WAAW,IAAI,YAAY,IAAI,WAAW;QAAE,OAAO,CAAC,CAAA;IACrE,IAAI,cAAc,IAAI,WAAW;QAAE,OAAO,CAAC,CAAA;IAC3C,OAAO,CAAC,CAAA;AACV,CAAC;AAoDD,SAAgB,YAAY,CAAC,WAAwB;IAEnD,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;IAGzC,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,OAAO,GAAG,WAAmC,CAAA;QACnD,OAAO,mBAAmB,CAAC,OAAO,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O,CAAC,CAAC,CAAC,CAAC,CAAC,CAAoB;gBACzC,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAY,CAAC;aAChD,CAAA;QACH,CAAC;QACD,IAAI,UAAU,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM;YAAE,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;IACzE,CAAC;IAED,IAAI,OAAO,CAAC,CAAC,IAAI,OAAO,OAAO,CAAC,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAA;IAE3E,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../erc8021/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../erc8021/index.ts"],"names":[],"mappings":";;;AA0CA,kDAA+C"}
|
package/_cjs/version.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Cbor from '../core/Cbor.js';
|
|
1
2
|
import * as Hex from '../core/Hex.js';
|
|
2
3
|
/**
|
|
3
4
|
* ERC-8021 suffix identifier.
|
|
@@ -27,12 +28,19 @@ export const ercSuffixSize = /*#__PURE__*/ Hex.size(ercSuffix);
|
|
|
27
28
|
* }
|
|
28
29
|
* })
|
|
29
30
|
* // @log: 1
|
|
31
|
+
*
|
|
32
|
+
* const schemaId3 = Attribution.getSchemaId({
|
|
33
|
+
* appCode: 'baseapp',
|
|
34
|
+
* })
|
|
35
|
+
* // @log: 2
|
|
30
36
|
* ```
|
|
31
37
|
*
|
|
32
38
|
* @param attribution - The attribution object.
|
|
33
|
-
* @returns The schema ID (0 for canonical registry, 1 for custom registry).
|
|
39
|
+
* @returns The schema ID (0 for canonical registry, 1 for custom registry, 2 for CBOR-encoded).
|
|
34
40
|
*/
|
|
35
41
|
export function getSchemaId(attribution) {
|
|
42
|
+
if ('appCode' in attribution || 'walletCode' in attribution)
|
|
43
|
+
return 2;
|
|
36
44
|
if ('codeRegistry' in attribution)
|
|
37
45
|
return 1;
|
|
38
46
|
return 0;
|
|
@@ -67,23 +75,40 @@ export function getSchemaId(attribution) {
|
|
|
67
75
|
* })
|
|
68
76
|
* ```
|
|
69
77
|
*
|
|
78
|
+
* @example
|
|
79
|
+
* ### Schema 2 (CBOR-Encoded)
|
|
80
|
+
*
|
|
81
|
+
* ```ts twoslash
|
|
82
|
+
* import { Attribution } from 'ox/erc8021'
|
|
83
|
+
*
|
|
84
|
+
* const suffix = Attribution.toDataSuffix({
|
|
85
|
+
* appCode: 'baseapp',
|
|
86
|
+
* walletCode: 'privy',
|
|
87
|
+
* metadata: { source: 'webapp' },
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
70
91
|
* @param attribution - The attribution to convert.
|
|
71
92
|
* @returns The data suffix as a {@link ox#Hex.Hex} value.
|
|
72
93
|
*/
|
|
73
94
|
export function toDataSuffix(attribution) {
|
|
95
|
+
// Determine schema ID
|
|
96
|
+
const schemaId = getSchemaId(attribution);
|
|
97
|
+
// Schema 2: CBOR-encoded
|
|
98
|
+
if (schemaId === 2) {
|
|
99
|
+
const schema2 = attribution;
|
|
100
|
+
return schema2ToDataSuffix(schema2);
|
|
101
|
+
}
|
|
74
102
|
// Encode the codes as ASCII strings separated by commas
|
|
75
|
-
const codesHex = Hex.fromString(attribution.codes.join(','));
|
|
103
|
+
const codesHex = Hex.fromString((attribution.codes ?? []).join(','));
|
|
76
104
|
// Get the byte length of the encoded codes
|
|
77
105
|
const codesLength = Hex.size(codesHex);
|
|
78
106
|
// Encode the codes length as 1 byte
|
|
79
107
|
const codesLengthHex = Hex.fromNumber(codesLength, { size: 1 });
|
|
80
|
-
// Determine schema ID
|
|
81
|
-
const schemaId = getSchemaId(attribution);
|
|
82
108
|
const schemaIdHex = Hex.fromNumber(schemaId, { size: 1 });
|
|
83
|
-
//
|
|
109
|
+
// Schema 1: codeRegistryAddress (20 bytes) ∥ chainId ∥ chainIdLength (1 byte) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
84
110
|
if (schemaId === 1) {
|
|
85
111
|
const schema1 = attribution;
|
|
86
|
-
// Schema 1: codeRegistryAddress (20 bytes) ∥ chainId ∥ chainIdLength (1 byte) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
87
112
|
return Hex.concat(registryToData(schema1.codeRegistry), codesHex, codesLengthHex, schemaIdHex, ercSuffix);
|
|
88
113
|
}
|
|
89
114
|
// Schema 0: codes ∥ codesLength ∥ schemaId ∥ ercSuffix
|
|
@@ -115,14 +140,26 @@ export function toDataSuffix(attribution) {
|
|
|
115
140
|
* )
|
|
116
141
|
* // @log: {
|
|
117
142
|
* // @log: codes: ['baseapp', 'morpho'],
|
|
118
|
-
* // @log:
|
|
119
|
-
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc
|
|
143
|
+
* // @log: codeRegistry: {
|
|
144
|
+
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc',
|
|
120
145
|
* // @log: chainId: 8453,
|
|
121
|
-
* // @log: }
|
|
146
|
+
* // @log: },
|
|
122
147
|
* // @log: id: 1
|
|
123
148
|
* // @log: }
|
|
124
149
|
* ```
|
|
125
150
|
*
|
|
151
|
+
* @example
|
|
152
|
+
* ### Schema 2 (CBOR-Encoded)
|
|
153
|
+
*
|
|
154
|
+
* ```ts twoslash
|
|
155
|
+
* import { Attribution } from 'ox/erc8021'
|
|
156
|
+
*
|
|
157
|
+
* const attribution = Attribution.fromData(
|
|
158
|
+
* '0xdddddddda161616762617365617070000b0280218021802180218021802180218021'
|
|
159
|
+
* )
|
|
160
|
+
* // @log: { appCode: 'baseapp', id: 2 }
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
126
163
|
* @param data - The transaction calldata containing the attribution suffix.
|
|
127
164
|
* @returns The extracted attribution, or undefined if no valid attribution is found.
|
|
128
165
|
*/
|
|
@@ -173,6 +210,10 @@ export function fromData(data) {
|
|
|
173
210
|
id: 1,
|
|
174
211
|
};
|
|
175
212
|
}
|
|
213
|
+
// Schema 2: CBOR-encoded
|
|
214
|
+
if (schemaId === 2) {
|
|
215
|
+
return schema2FromData(data);
|
|
216
|
+
}
|
|
176
217
|
// Unknown schema ID
|
|
177
218
|
return undefined;
|
|
178
219
|
}
|
|
@@ -209,4 +250,72 @@ function registryToData(registry) {
|
|
|
209
250
|
const paddedChainId = Hex.padLeft(chainIdAsHex, chainIdLen);
|
|
210
251
|
return Hex.concat(registry.address, paddedChainId, Hex.fromNumber(chainIdLen, { size: 1 }));
|
|
211
252
|
}
|
|
253
|
+
function schema2ToDataSuffix(attribution) {
|
|
254
|
+
// Build the CBOR map using single-letter keys per the spec
|
|
255
|
+
const cborMap = {};
|
|
256
|
+
if (attribution.appCode)
|
|
257
|
+
cborMap.a = attribution.appCode;
|
|
258
|
+
if (attribution.walletCode)
|
|
259
|
+
cborMap.w = attribution.walletCode;
|
|
260
|
+
if (attribution.registries) {
|
|
261
|
+
const r = {};
|
|
262
|
+
if (attribution.registries.app) {
|
|
263
|
+
r.a = {
|
|
264
|
+
c: Hex.fromNumber(attribution.registries.app.chainId),
|
|
265
|
+
a: attribution.registries.app.address,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (attribution.registries.wallet) {
|
|
269
|
+
r.w = {
|
|
270
|
+
c: Hex.fromNumber(attribution.registries.wallet.chainId),
|
|
271
|
+
a: attribution.registries.wallet.address,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (r.a || r.w)
|
|
275
|
+
cborMap.r = r;
|
|
276
|
+
}
|
|
277
|
+
if (attribution.metadata && Object.keys(attribution.metadata).length > 0)
|
|
278
|
+
cborMap.m = attribution.metadata;
|
|
279
|
+
// Encode to CBOR
|
|
280
|
+
const cborHex = Cbor.encode(cborMap);
|
|
281
|
+
const cborBytes = Hex.size(cborHex);
|
|
282
|
+
// cborData ∥ cborLength (2 bytes) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
283
|
+
return Hex.concat(cborHex, Hex.fromNumber(cborBytes, { size: 2 }), Hex.fromNumber(2, { size: 1 }), ercSuffix);
|
|
284
|
+
}
|
|
285
|
+
function schema2FromData(data) {
|
|
286
|
+
// cborLength is 2 bytes before schema ID
|
|
287
|
+
const cborLengthHex = Hex.slice(data, -ercSuffixSize - 1 - 2, -ercSuffixSize - 1);
|
|
288
|
+
const cborLength = Hex.toNumber(cborLengthHex);
|
|
289
|
+
// Extract CBOR data
|
|
290
|
+
const cborStart = -ercSuffixSize - 1 - 2 - cborLength;
|
|
291
|
+
const cborEnd = -ercSuffixSize - 1 - 2;
|
|
292
|
+
const cborHex = Hex.slice(data, cborStart, cborEnd);
|
|
293
|
+
// Decode CBOR
|
|
294
|
+
const decoded = Cbor.decode(cborHex);
|
|
295
|
+
const result = { id: 2 };
|
|
296
|
+
if (typeof decoded.a === 'string')
|
|
297
|
+
result.appCode = decoded.a;
|
|
298
|
+
if (typeof decoded.w === 'string')
|
|
299
|
+
result.walletCode = decoded.w;
|
|
300
|
+
if (decoded.r) {
|
|
301
|
+
const registries = {};
|
|
302
|
+
if (decoded.r.a?.c && decoded.r.a?.a) {
|
|
303
|
+
registries.app = {
|
|
304
|
+
address: decoded.r.a.a,
|
|
305
|
+
chainId: Hex.toNumber(decoded.r.a.c),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
if (decoded.r.w?.c && decoded.r.w?.a) {
|
|
309
|
+
registries.wallet = {
|
|
310
|
+
address: decoded.r.w.a,
|
|
311
|
+
chainId: Hex.toNumber(decoded.r.w.c),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
if (registries.app || registries.wallet)
|
|
315
|
+
result.registries = registries;
|
|
316
|
+
}
|
|
317
|
+
if (decoded.m && typeof decoded.m === 'object')
|
|
318
|
+
result.metadata = decoded.m;
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
212
321
|
//# sourceMappingURL=Attribution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Attribution.js","sourceRoot":"","sources":["../../erc8021/Attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Attribution.js","sourceRoot":"","sources":["../../erc8021/Attribution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AAEvC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AA4FrC;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,oCAA6C,CAAA;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,WAAW,CAAC,WAAwB;IAClD,IAAI,SAAS,IAAI,WAAW,IAAI,YAAY,IAAI,WAAW;QAAE,OAAO,CAAC,CAAA;IACrE,IAAI,cAAc,IAAI,WAAW;QAAE,OAAO,CAAC,CAAA;IAC3C,OAAO,CAAC,CAAA;AACV,CAAC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,UAAU,YAAY,CAAC,WAAwB;IACnD,sBAAsB;IACtB,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;IAEzC,yBAAyB;IACzB,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,OAAO,GAAG,WAAmC,CAAA;QACnD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC;IAED,wDAAwD;IACxD,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,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AAC,CAAC,CAAC,CAAC,CAAoB;gBACzC,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAY,CAAC;aAChD,CAAA;QACH,CAAC;QACD,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;YACrC,UAAU,CAAC,MAAM,GAAG;gBAClB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAoB;gBACzC,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAY,CAAC;aAChD,CAAA;QACH,CAAC;QACD,IAAI,UAAU,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM;YAAE,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;IACzE,CAAC;IAED,IAAI,OAAO,CAAC,CAAC,IAAI,OAAO,OAAO,CAAC,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAA;IAE3E,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/_esm/erc8021/index.js
CHANGED
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
* codes: ['baseapp', 'morpho'],
|
|
16
16
|
* codeRegistry: { address: '0x0000000000000000000000000000000000000000', chainId: 1 },
|
|
17
17
|
* })
|
|
18
|
+
*
|
|
19
|
+
* const dataSuffix3 = Attribution.toDataSuffix({
|
|
20
|
+
* appCode: 'baseapp',
|
|
21
|
+
* walletCode: 'privy',
|
|
22
|
+
* })
|
|
18
23
|
* ```
|
|
19
24
|
*
|
|
20
25
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../erc8021/index.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../erc8021/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA"}
|
package/_esm/version.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as Address from '../core/Address.js';
|
|
2
|
+
import * as Cbor from '../core/Cbor.js';
|
|
2
3
|
import type * as Errors from '../core/Errors.js';
|
|
3
4
|
import * as Hex from '../core/Hex.js';
|
|
4
5
|
import type { OneOf } from '../core/internal/types.js';
|
|
@@ -8,7 +9,7 @@ import type { OneOf } from '../core/internal/types.js';
|
|
|
8
9
|
* Represents attribution metadata that can be appended to transaction calldata
|
|
9
10
|
* to track entities involved in facilitating a transaction.
|
|
10
11
|
*/
|
|
11
|
-
export type Attribution = OneOf<AttributionSchemaId0 | AttributionSchemaId1>;
|
|
12
|
+
export type Attribution = OneOf<AttributionSchemaId0 | AttributionSchemaId1 | AttributionSchemaId2>;
|
|
12
13
|
/**
|
|
13
14
|
* Schema 0: Canonical Registry Attribution.
|
|
14
15
|
*
|
|
@@ -38,13 +39,44 @@ export type AttributionSchemaId1Registry = {
|
|
|
38
39
|
/** Chain Id of the chain the custom code registry contract is deployed on. */
|
|
39
40
|
chainId: number;
|
|
40
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Schema 2: CBOR-Encoded Attribution.
|
|
44
|
+
*
|
|
45
|
+
* Uses CBOR encoding for extensible transaction annotation with optional fields,
|
|
46
|
+
* support for arbitrary metadata, and coexistence with other suffix-based systems.
|
|
47
|
+
*/
|
|
48
|
+
export type AttributionSchemaId2 = {
|
|
49
|
+
/** Application attribution code. */
|
|
50
|
+
appCode?: string | undefined;
|
|
51
|
+
/** Wallet attribution code. */
|
|
52
|
+
walletCode?: string | undefined;
|
|
53
|
+
/** Custom code registries keyed by entity type. */
|
|
54
|
+
registries?: AttributionSchemaId2Registries | undefined;
|
|
55
|
+
/** Arbitrary metadata key-value pairs. */
|
|
56
|
+
metadata?: Record<string, unknown> | undefined;
|
|
57
|
+
/** Schema identifier (2 for CBOR-encoded). */
|
|
58
|
+
id?: 2 | undefined;
|
|
59
|
+
};
|
|
60
|
+
export type AttributionSchemaId2Registries = {
|
|
61
|
+
/** Custom registry for the application entity. */
|
|
62
|
+
app?: AttributionSchemaId2Registry | undefined;
|
|
63
|
+
/** Custom registry for the wallet entity. */
|
|
64
|
+
wallet?: AttributionSchemaId2Registry | undefined;
|
|
65
|
+
};
|
|
66
|
+
export type AttributionSchemaId2Registry = {
|
|
67
|
+
/** Address of the custom code registry contract. */
|
|
68
|
+
address: Address.Address;
|
|
69
|
+
/** Chain ID of the chain the custom code registry contract is deployed on. */
|
|
70
|
+
chainId: number;
|
|
71
|
+
};
|
|
41
72
|
/**
|
|
42
73
|
* Attribution schema identifier.
|
|
43
74
|
*
|
|
44
75
|
* - `0`: Canonical registry
|
|
45
76
|
* - `1`: Custom registry
|
|
77
|
+
* - `2`: CBOR-encoded
|
|
46
78
|
*/
|
|
47
|
-
export type SchemaId = NonNullable<AttributionSchemaId0['id'] | AttributionSchemaId1['id']>;
|
|
79
|
+
export type SchemaId = NonNullable<AttributionSchemaId0['id'] | AttributionSchemaId1['id'] | AttributionSchemaId2['id']>;
|
|
48
80
|
/**
|
|
49
81
|
* ERC-8021 suffix identifier.
|
|
50
82
|
*/
|
|
@@ -73,10 +105,15 @@ export declare const ercSuffixSize: number;
|
|
|
73
105
|
* }
|
|
74
106
|
* })
|
|
75
107
|
* // @log: 1
|
|
108
|
+
*
|
|
109
|
+
* const schemaId3 = Attribution.getSchemaId({
|
|
110
|
+
* appCode: 'baseapp',
|
|
111
|
+
* })
|
|
112
|
+
* // @log: 2
|
|
76
113
|
* ```
|
|
77
114
|
*
|
|
78
115
|
* @param attribution - The attribution object.
|
|
79
|
-
* @returns The schema ID (0 for canonical registry, 1 for custom registry).
|
|
116
|
+
* @returns The schema ID (0 for canonical registry, 1 for custom registry, 2 for CBOR-encoded).
|
|
80
117
|
*/
|
|
81
118
|
export declare function getSchemaId(attribution: Attribution): SchemaId;
|
|
82
119
|
export declare namespace getSchemaId {
|
|
@@ -112,12 +149,25 @@ export declare namespace getSchemaId {
|
|
|
112
149
|
* })
|
|
113
150
|
* ```
|
|
114
151
|
*
|
|
152
|
+
* @example
|
|
153
|
+
* ### Schema 2 (CBOR-Encoded)
|
|
154
|
+
*
|
|
155
|
+
* ```ts twoslash
|
|
156
|
+
* import { Attribution } from 'ox/erc8021'
|
|
157
|
+
*
|
|
158
|
+
* const suffix = Attribution.toDataSuffix({
|
|
159
|
+
* appCode: 'baseapp',
|
|
160
|
+
* walletCode: 'privy',
|
|
161
|
+
* metadata: { source: 'webapp' },
|
|
162
|
+
* })
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
115
165
|
* @param attribution - The attribution to convert.
|
|
116
166
|
* @returns The data suffix as a {@link ox#Hex.Hex} value.
|
|
117
167
|
*/
|
|
118
168
|
export declare function toDataSuffix(attribution: Attribution): Hex.Hex;
|
|
119
169
|
export declare namespace toDataSuffix {
|
|
120
|
-
type ErrorType = getSchemaId.ErrorType | Hex.concat.ErrorType | Hex.fromString.ErrorType | Hex.fromNumber.ErrorType | Hex.size.ErrorType | Errors.GlobalErrorType;
|
|
170
|
+
type ErrorType = getSchemaId.ErrorType | Hex.concat.ErrorType | Hex.fromString.ErrorType | Hex.fromNumber.ErrorType | Hex.size.ErrorType | Cbor.encode.ErrorType | Errors.GlobalErrorType;
|
|
121
171
|
}
|
|
122
172
|
/**
|
|
123
173
|
* Extracts an {@link ox#Attribution.Attribution} from transaction calldata.
|
|
@@ -145,19 +195,31 @@ export declare namespace toDataSuffix {
|
|
|
145
195
|
* )
|
|
146
196
|
* // @log: {
|
|
147
197
|
* // @log: codes: ['baseapp', 'morpho'],
|
|
148
|
-
* // @log:
|
|
149
|
-
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc
|
|
198
|
+
* // @log: codeRegistry: {
|
|
199
|
+
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc',
|
|
150
200
|
* // @log: chainId: 8453,
|
|
151
|
-
* // @log: }
|
|
201
|
+
* // @log: },
|
|
152
202
|
* // @log: id: 1
|
|
153
203
|
* // @log: }
|
|
154
204
|
* ```
|
|
155
205
|
*
|
|
206
|
+
* @example
|
|
207
|
+
* ### Schema 2 (CBOR-Encoded)
|
|
208
|
+
*
|
|
209
|
+
* ```ts twoslash
|
|
210
|
+
* import { Attribution } from 'ox/erc8021'
|
|
211
|
+
*
|
|
212
|
+
* const attribution = Attribution.fromData(
|
|
213
|
+
* '0xdddddddda161616762617365617070000b0280218021802180218021802180218021'
|
|
214
|
+
* )
|
|
215
|
+
* // @log: { appCode: 'baseapp', id: 2 }
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
156
218
|
* @param data - The transaction calldata containing the attribution suffix.
|
|
157
219
|
* @returns The extracted attribution, or undefined if no valid attribution is found.
|
|
158
220
|
*/
|
|
159
221
|
export declare function fromData(data: Hex.Hex): Attribution | undefined;
|
|
160
222
|
export declare namespace fromData {
|
|
161
|
-
type ErrorType = Hex.slice.ErrorType | Hex.toNumber.ErrorType | Hex.toString.ErrorType | Hex.size.ErrorType | Errors.GlobalErrorType;
|
|
223
|
+
type ErrorType = Hex.slice.ErrorType | Hex.toNumber.ErrorType | Hex.toString.ErrorType | Hex.size.ErrorType | Cbor.decode.ErrorType | Errors.GlobalErrorType;
|
|
162
224
|
}
|
|
163
225
|
//# sourceMappingURL=Attribution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Attribution.d.ts","sourceRoot":"","sources":["../../erc8021/Attribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CA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,GACrB,GAAG,CAAC,MAAM,CAAC,SAAS,GACpB,GAAG,CAAC,UAAU,CAAC,SAAS,GACxB,GAAG,CAAC,UAAU,CAAC,SAAS,GACxB,GAAG,CAAC,IAAI,CAAC,SAAS,GAClB,IAAI,CAAC,MAAM,CAAC,SAAS,GACrB,MAAM,CAAC,eAAe,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,WAAW,GAAG,SAAS,CAoE/D;AA8CD,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,KAAK,SAAS,GACV,GAAG,CAAC,KAAK,CAAC,SAAS,GACnB,GAAG,CAAC,QAAQ,CAAC,SAAS,GACtB,GAAG,CAAC,QAAQ,CAAC,SAAS,GACtB,GAAG,CAAC,IAAI,CAAC,SAAS,GAClB,IAAI,CAAC,MAAM,CAAC,SAAS,GACrB,MAAM,CAAC,eAAe,CAAA;CAC3B"}
|
|
@@ -17,6 +17,11 @@ export type {};
|
|
|
17
17
|
* codes: ['baseapp', 'morpho'],
|
|
18
18
|
* codeRegistry: { address: '0x0000000000000000000000000000000000000000', chainId: 1 },
|
|
19
19
|
* })
|
|
20
|
+
*
|
|
21
|
+
* const dataSuffix3 = Attribution.toDataSuffix({
|
|
22
|
+
* appCode: 'baseapp',
|
|
23
|
+
* walletCode: 'privy',
|
|
24
|
+
* })
|
|
20
25
|
* ```
|
|
21
26
|
*
|
|
22
27
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../erc8021/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,YAAY,EAAE,CAAA;AAEd
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../erc8021/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,YAAY,EAAE,CAAA;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA"}
|
package/_types/version.d.ts
CHANGED
package/erc8021/Attribution.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as Address from '../core/Address.js'
|
|
2
|
+
import * as Cbor from '../core/Cbor.js'
|
|
2
3
|
import type * as Errors from '../core/Errors.js'
|
|
3
4
|
import * as Hex from '../core/Hex.js'
|
|
4
5
|
import type { OneOf } from '../core/internal/types.js'
|
|
@@ -9,7 +10,9 @@ import type { OneOf } from '../core/internal/types.js'
|
|
|
9
10
|
* Represents attribution metadata that can be appended to transaction calldata
|
|
10
11
|
* to track entities involved in facilitating a transaction.
|
|
11
12
|
*/
|
|
12
|
-
export type Attribution = OneOf<
|
|
13
|
+
export type Attribution = OneOf<
|
|
14
|
+
AttributionSchemaId0 | AttributionSchemaId1 | AttributionSchemaId2
|
|
15
|
+
>
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Schema 0: Canonical Registry Attribution.
|
|
@@ -44,14 +47,50 @@ export type AttributionSchemaId1Registry = {
|
|
|
44
47
|
chainId: number
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Schema 2: CBOR-Encoded Attribution.
|
|
52
|
+
*
|
|
53
|
+
* Uses CBOR encoding for extensible transaction annotation with optional fields,
|
|
54
|
+
* support for arbitrary metadata, and coexistence with other suffix-based systems.
|
|
55
|
+
*/
|
|
56
|
+
export type AttributionSchemaId2 = {
|
|
57
|
+
/** Application attribution code. */
|
|
58
|
+
appCode?: string | undefined
|
|
59
|
+
/** Wallet attribution code. */
|
|
60
|
+
walletCode?: string | undefined
|
|
61
|
+
/** Custom code registries keyed by entity type. */
|
|
62
|
+
registries?: AttributionSchemaId2Registries | undefined
|
|
63
|
+
/** Arbitrary metadata key-value pairs. */
|
|
64
|
+
metadata?: Record<string, unknown> | undefined
|
|
65
|
+
/** Schema identifier (2 for CBOR-encoded). */
|
|
66
|
+
id?: 2 | undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type AttributionSchemaId2Registries = {
|
|
70
|
+
/** Custom registry for the application entity. */
|
|
71
|
+
app?: AttributionSchemaId2Registry | undefined
|
|
72
|
+
/** Custom registry for the wallet entity. */
|
|
73
|
+
wallet?: AttributionSchemaId2Registry | undefined
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type AttributionSchemaId2Registry = {
|
|
77
|
+
/** Address of the custom code registry contract. */
|
|
78
|
+
address: Address.Address
|
|
79
|
+
/** Chain ID of the chain the custom code registry contract is deployed on. */
|
|
80
|
+
chainId: number
|
|
81
|
+
}
|
|
82
|
+
|
|
47
83
|
/**
|
|
48
84
|
* Attribution schema identifier.
|
|
49
85
|
*
|
|
50
86
|
* - `0`: Canonical registry
|
|
51
87
|
* - `1`: Custom registry
|
|
88
|
+
* - `2`: CBOR-encoded
|
|
52
89
|
*/
|
|
53
90
|
export type SchemaId = NonNullable<
|
|
54
|
-
|
|
91
|
+
| AttributionSchemaId0['id']
|
|
92
|
+
| AttributionSchemaId1['id']
|
|
93
|
+
| AttributionSchemaId2['id']
|
|
55
94
|
>
|
|
56
95
|
|
|
57
96
|
/**
|
|
@@ -84,12 +123,18 @@ export const ercSuffixSize = /*#__PURE__*/ Hex.size(ercSuffix)
|
|
|
84
123
|
* }
|
|
85
124
|
* })
|
|
86
125
|
* // @log: 1
|
|
126
|
+
*
|
|
127
|
+
* const schemaId3 = Attribution.getSchemaId({
|
|
128
|
+
* appCode: 'baseapp',
|
|
129
|
+
* })
|
|
130
|
+
* // @log: 2
|
|
87
131
|
* ```
|
|
88
132
|
*
|
|
89
133
|
* @param attribution - The attribution object.
|
|
90
|
-
* @returns The schema ID (0 for canonical registry, 1 for custom registry).
|
|
134
|
+
* @returns The schema ID (0 for canonical registry, 1 for custom registry, 2 for CBOR-encoded).
|
|
91
135
|
*/
|
|
92
136
|
export function getSchemaId(attribution: Attribution): SchemaId {
|
|
137
|
+
if ('appCode' in attribution || 'walletCode' in attribution) return 2
|
|
93
138
|
if ('codeRegistry' in attribution) return 1
|
|
94
139
|
return 0
|
|
95
140
|
}
|
|
@@ -128,12 +173,34 @@ export declare namespace getSchemaId {
|
|
|
128
173
|
* })
|
|
129
174
|
* ```
|
|
130
175
|
*
|
|
176
|
+
* @example
|
|
177
|
+
* ### Schema 2 (CBOR-Encoded)
|
|
178
|
+
*
|
|
179
|
+
* ```ts twoslash
|
|
180
|
+
* import { Attribution } from 'ox/erc8021'
|
|
181
|
+
*
|
|
182
|
+
* const suffix = Attribution.toDataSuffix({
|
|
183
|
+
* appCode: 'baseapp',
|
|
184
|
+
* walletCode: 'privy',
|
|
185
|
+
* metadata: { source: 'webapp' },
|
|
186
|
+
* })
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
131
189
|
* @param attribution - The attribution to convert.
|
|
132
190
|
* @returns The data suffix as a {@link ox#Hex.Hex} value.
|
|
133
191
|
*/
|
|
134
192
|
export function toDataSuffix(attribution: Attribution): Hex.Hex {
|
|
193
|
+
// Determine schema ID
|
|
194
|
+
const schemaId = getSchemaId(attribution)
|
|
195
|
+
|
|
196
|
+
// Schema 2: CBOR-encoded
|
|
197
|
+
if (schemaId === 2) {
|
|
198
|
+
const schema2 = attribution as AttributionSchemaId2
|
|
199
|
+
return schema2ToDataSuffix(schema2)
|
|
200
|
+
}
|
|
201
|
+
|
|
135
202
|
// Encode the codes as ASCII strings separated by commas
|
|
136
|
-
const codesHex = Hex.fromString(attribution.codes.join(','))
|
|
203
|
+
const codesHex = Hex.fromString((attribution.codes ?? []).join(','))
|
|
137
204
|
|
|
138
205
|
// Get the byte length of the encoded codes
|
|
139
206
|
const codesLength = Hex.size(codesHex)
|
|
@@ -141,14 +208,11 @@ export function toDataSuffix(attribution: Attribution): Hex.Hex {
|
|
|
141
208
|
// Encode the codes length as 1 byte
|
|
142
209
|
const codesLengthHex = Hex.fromNumber(codesLength, { size: 1 })
|
|
143
210
|
|
|
144
|
-
// Determine schema ID
|
|
145
|
-
const schemaId = getSchemaId(attribution)
|
|
146
211
|
const schemaIdHex = Hex.fromNumber(schemaId, { size: 1 })
|
|
147
212
|
|
|
148
|
-
//
|
|
213
|
+
// Schema 1: codeRegistryAddress (20 bytes) ∥ chainId ∥ chainIdLength (1 byte) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
149
214
|
if (schemaId === 1) {
|
|
150
215
|
const schema1 = attribution as AttributionSchemaId1
|
|
151
|
-
// Schema 1: codeRegistryAddress (20 bytes) ∥ chainId ∥ chainIdLength (1 byte) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
152
216
|
return Hex.concat(
|
|
153
217
|
registryToData(schema1.codeRegistry),
|
|
154
218
|
codesHex,
|
|
@@ -169,6 +233,7 @@ export declare namespace toDataSuffix {
|
|
|
169
233
|
| Hex.fromString.ErrorType
|
|
170
234
|
| Hex.fromNumber.ErrorType
|
|
171
235
|
| Hex.size.ErrorType
|
|
236
|
+
| Cbor.encode.ErrorType
|
|
172
237
|
| Errors.GlobalErrorType
|
|
173
238
|
}
|
|
174
239
|
|
|
@@ -198,14 +263,26 @@ export declare namespace toDataSuffix {
|
|
|
198
263
|
* )
|
|
199
264
|
* // @log: {
|
|
200
265
|
* // @log: codes: ['baseapp', 'morpho'],
|
|
201
|
-
* // @log:
|
|
202
|
-
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc
|
|
266
|
+
* // @log: codeRegistry: {
|
|
267
|
+
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc',
|
|
203
268
|
* // @log: chainId: 8453,
|
|
204
|
-
* // @log: }
|
|
269
|
+
* // @log: },
|
|
205
270
|
* // @log: id: 1
|
|
206
271
|
* // @log: }
|
|
207
272
|
* ```
|
|
208
273
|
*
|
|
274
|
+
* @example
|
|
275
|
+
* ### Schema 2 (CBOR-Encoded)
|
|
276
|
+
*
|
|
277
|
+
* ```ts twoslash
|
|
278
|
+
* import { Attribution } from 'ox/erc8021'
|
|
279
|
+
*
|
|
280
|
+
* const attribution = Attribution.fromData(
|
|
281
|
+
* '0xdddddddda161616762617365617070000b0280218021802180218021802180218021'
|
|
282
|
+
* )
|
|
283
|
+
* // @log: { appCode: 'baseapp', id: 2 }
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
209
286
|
* @param data - The transaction calldata containing the attribution suffix.
|
|
210
287
|
* @returns The extracted attribution, or undefined if no valid attribution is found.
|
|
211
288
|
*/
|
|
@@ -270,6 +347,10 @@ export function fromData(data: Hex.Hex): Attribution | undefined {
|
|
|
270
347
|
id: 1,
|
|
271
348
|
}
|
|
272
349
|
}
|
|
350
|
+
// Schema 2: CBOR-encoded
|
|
351
|
+
if (schemaId === 2) {
|
|
352
|
+
return schema2FromData(data)
|
|
353
|
+
}
|
|
273
354
|
|
|
274
355
|
// Unknown schema ID
|
|
275
356
|
return undefined
|
|
@@ -325,5 +406,103 @@ export declare namespace fromData {
|
|
|
325
406
|
| Hex.toNumber.ErrorType
|
|
326
407
|
| Hex.toString.ErrorType
|
|
327
408
|
| Hex.size.ErrorType
|
|
409
|
+
| Cbor.decode.ErrorType
|
|
328
410
|
| Errors.GlobalErrorType
|
|
329
411
|
}
|
|
412
|
+
|
|
413
|
+
// ---- Schema 2 helpers ----
|
|
414
|
+
|
|
415
|
+
/** Internal CBOR map shape matching the ERC-8021 spec. */
|
|
416
|
+
type Schema2CborMap = {
|
|
417
|
+
a?: string
|
|
418
|
+
w?: string
|
|
419
|
+
r?: {
|
|
420
|
+
a?: { c: string; a: string }
|
|
421
|
+
w?: { c: string; a: string }
|
|
422
|
+
}
|
|
423
|
+
m?: Record<string, unknown>
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function schema2ToDataSuffix(attribution: AttributionSchemaId2): Hex.Hex {
|
|
427
|
+
// Build the CBOR map using single-letter keys per the spec
|
|
428
|
+
const cborMap: Schema2CborMap = {}
|
|
429
|
+
|
|
430
|
+
if (attribution.appCode) cborMap.a = attribution.appCode
|
|
431
|
+
if (attribution.walletCode) cborMap.w = attribution.walletCode
|
|
432
|
+
|
|
433
|
+
if (attribution.registries) {
|
|
434
|
+
const r: Schema2CborMap['r'] = {}
|
|
435
|
+
if (attribution.registries.app) {
|
|
436
|
+
r.a = {
|
|
437
|
+
c: Hex.fromNumber(attribution.registries.app.chainId),
|
|
438
|
+
a: attribution.registries.app.address,
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (attribution.registries.wallet) {
|
|
442
|
+
r.w = {
|
|
443
|
+
c: Hex.fromNumber(attribution.registries.wallet.chainId),
|
|
444
|
+
a: attribution.registries.wallet.address,
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (r.a || r.w) cborMap.r = r
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (attribution.metadata && Object.keys(attribution.metadata).length > 0)
|
|
451
|
+
cborMap.m = attribution.metadata
|
|
452
|
+
|
|
453
|
+
// Encode to CBOR
|
|
454
|
+
const cborHex = Cbor.encode(cborMap)
|
|
455
|
+
const cborBytes = Hex.size(cborHex)
|
|
456
|
+
|
|
457
|
+
// cborData ∥ cborLength (2 bytes) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
458
|
+
return Hex.concat(
|
|
459
|
+
cborHex,
|
|
460
|
+
Hex.fromNumber(cborBytes, { size: 2 }),
|
|
461
|
+
Hex.fromNumber(2, { size: 1 }),
|
|
462
|
+
ercSuffix,
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function schema2FromData(data: Hex.Hex): AttributionSchemaId2 | undefined {
|
|
467
|
+
// cborLength is 2 bytes before schema ID
|
|
468
|
+
const cborLengthHex = Hex.slice(
|
|
469
|
+
data,
|
|
470
|
+
-ercSuffixSize - 1 - 2,
|
|
471
|
+
-ercSuffixSize - 1,
|
|
472
|
+
)
|
|
473
|
+
const cborLength = Hex.toNumber(cborLengthHex)
|
|
474
|
+
|
|
475
|
+
// Extract CBOR data
|
|
476
|
+
const cborStart = -ercSuffixSize - 1 - 2 - cborLength
|
|
477
|
+
const cborEnd = -ercSuffixSize - 1 - 2
|
|
478
|
+
const cborHex = Hex.slice(data, cborStart, cborEnd)
|
|
479
|
+
|
|
480
|
+
// Decode CBOR
|
|
481
|
+
const decoded = Cbor.decode<Schema2CborMap>(cborHex)
|
|
482
|
+
|
|
483
|
+
const result: AttributionSchemaId2 = { id: 2 }
|
|
484
|
+
|
|
485
|
+
if (typeof decoded.a === 'string') result.appCode = decoded.a
|
|
486
|
+
if (typeof decoded.w === 'string') result.walletCode = decoded.w
|
|
487
|
+
|
|
488
|
+
if (decoded.r) {
|
|
489
|
+
const registries: AttributionSchemaId2Registries = {}
|
|
490
|
+
if (decoded.r.a?.c && decoded.r.a?.a) {
|
|
491
|
+
registries.app = {
|
|
492
|
+
address: decoded.r.a.a as Address.Address,
|
|
493
|
+
chainId: Hex.toNumber(decoded.r.a.c as Hex.Hex),
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (decoded.r.w?.c && decoded.r.w?.a) {
|
|
497
|
+
registries.wallet = {
|
|
498
|
+
address: decoded.r.w.a as Address.Address,
|
|
499
|
+
chainId: Hex.toNumber(decoded.r.w.c as Hex.Hex),
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (registries.app || registries.wallet) result.registries = registries
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (decoded.m && typeof decoded.m === 'object') result.metadata = decoded.m
|
|
506
|
+
|
|
507
|
+
return result
|
|
508
|
+
}
|
package/erc8021/index.ts
CHANGED
|
@@ -19,6 +19,11 @@ export type {}
|
|
|
19
19
|
* codes: ['baseapp', 'morpho'],
|
|
20
20
|
* codeRegistry: { address: '0x0000000000000000000000000000000000000000', chainId: 1 },
|
|
21
21
|
* })
|
|
22
|
+
*
|
|
23
|
+
* const dataSuffix3 = Attribution.toDataSuffix({
|
|
24
|
+
* appCode: 'baseapp',
|
|
25
|
+
* walletCode: 'privy',
|
|
26
|
+
* })
|
|
22
27
|
* ```
|
|
23
28
|
*
|
|
24
29
|
* @example
|
package/package.json
CHANGED
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.14.
|
|
2
|
+
export const version = '0.14.8'
|