@meantjs/profile 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  The five Candid Profile library packages (`@meantjs/profile`, `/format`, `/consent`, `/tools`, `/reconcile`) release together under one version and pin each other exactly; a version appears here even when this package did not change. Release steps: `docs/releasing.md` in the repository.
4
4
 
5
+ ## 0.2.0 — 2026-10-28
6
+
7
+ - `intent` and `effect` may sit on a case of a variant in a method's arguments, such as `propose(0).Transfer`
8
+ (spec §5.2, D-053). The resolved form carries them on the case node. New errors: `E_CASE_OVERLAP` (two tagged cases
9
+ of one method that one call can hold both of) and `E_CASE_EFFECT` (a case effect that needs confirmation, or is
10
+ irreversible, under a method effect that does not or is not); `E_TAG_TARGET` for a case tag at any other value
11
+ address; `E_TEMPLATE_PATH` for a case template's placeholder through another case of a variant on its path. A
12
+ profile that 0.1.0 accepts resolves as before.
13
+ - EVM contracts, experimental (spec §15, D-054). `kind: "contract"` profiles carry an ABI (`binds.abi`, human-readable
14
+ fragments or JSON entries) and optional `binds.deployments`; EVM packs carry `binds.abi` and apply by selector, with
15
+ their addresses and placeholders rewritten to the contract's parameter names. `resolveService({ abi })` and
16
+ `candid-profile resolve --abi <file>` resolve a contract; its resolved form has `"chain": "evm"`, `abi` nodes, and
17
+ each method's `selector`, `signature` and `state_mutability`. A new standard pack, `erc20`; `loadPacks()` and
18
+ `STANDARD_PACKS` now list it first, and a Candid service skips it. New errors: `E_ABI`, `E_CHAIN`,
19
+ `E_ADDRESS_CHECKSUM`; on a contract, `E_TAG_TARGET` for `idempotency`, `outcome`, `list`, `names` and `named`,
20
+ `E_TAG_NOT_APPLICABLE` for `account` and `subaccount`, and `E_TEMPLATE` for `[ ]` segments.
21
+ - `@meantjs/profile/evm`, browser-safe and without dependencies: Keccak-256, ABI fragments (`parseAbi`,
22
+ `parseSignature`, canonical text, selectors, `abiInterfaceId`), a strict ABI codec (`encodeParams`, `encodeCall`,
23
+ `decodeParams`, which refuses anything but the canonical encoding), EIP-55 addresses (`toChecksumAddress`,
24
+ `readAddress`) and EIP-712 digests (`typedDataDigest`).
25
+ - The schema: `amount` takes `threshold` and `message` (display only: a value at or above the threshold shows as the
26
+ message and the symbol, "Unlimited USDC").
27
+
5
28
  ## 0.1.0 — 2026-10-28
6
29
 
7
30
  First published version.
package/README.md CHANGED
@@ -10,7 +10,8 @@ npm install @meantjs/profile
10
10
 
11
11
  - **Runs on:** Node 22 or later for the main entry and the `candid-profile` CLI. `@meantjs/profile/browser` is for
12
12
  browser bundles (checked with esbuild, and in Chromium under a CSP without `'unsafe-eval'`; the cli's wasm needs
13
- `'wasm-unsafe-eval'`, below). `@meantjs/profile/address` has no dependency and runs anywhere.
13
+ `'wasm-unsafe-eval'`, below). `@meantjs/profile/address` and `@meantjs/profile/evm` have no dependency and run
14
+ anywhere.
14
15
  - **Module format:** ES modules only, with hand-written TypeScript declarations for every entry.
15
16
  - **Spec:** [Candid Profile v0](https://github.com/B3Pay/Meant/blob/main/profile/docs/profile-v0.md). **Licence:** Apache-2.0.
16
17
  - **Versions:** the five Candid Profile packages (`@meantjs/profile`, `/format`, `/consent`, `/tools`,
@@ -21,7 +22,7 @@ npm install @meantjs/profile
21
22
  import { createSchemaValidator, resolveService, loadPacks, validateProfile } from "@meantjs/profile";
22
23
 
23
24
  const validateSchema = await createSchemaValidator(); // the schema this package ships
24
- const packs = await loadPacks(); // the standard packs it ships (ICRC-1, ICRC-2)
25
+ const packs = await loadPacks(); // the standard packs it ships (ERC-20, ICRC-1, ICRC-2)
25
26
  const r = await resolveService({
26
27
  did: await readFile("ledger.did", "utf8"),
27
28
  validateSchema,
@@ -163,10 +164,38 @@ const r = await resolveService({ did: serviceText, profiles: served.ok ? [{ doc:
163
164
  serves, so a profile for another interface is `rebound` or `stale` as any other.
164
165
  - Tests: `test/served.test.mjs`; end to end on PocketIC in `packages/kit/pocketic/`.
165
166
 
167
+ ## EVM contracts (experimental, spec section 15, D-054)
168
+
169
+ A third input, `abi`: an EVM contract's ABI as human-readable fragments or JSON ABI entries. The resolver reads it as
170
+ the graph a `.did` compiles to (a function is a method, its parameters one record at argument 0, a tuple a record in
171
+ ABI order), so addresses, tags, layers and the resolved form work unchanged; the resolved form says `"chain": "evm"`,
172
+ its nodes carry `abi` instead of `candid`, and each method has `selector`, `signature` and `state_mutability`.
173
+
174
+ ```js
175
+ const r = await resolveService({ abi: ["function transfer(address dst, uint256 wad) returns (bool)", …], validateSchema, packs: (await loadPacks()).map(({ doc }) => ({ doc })) });
176
+ r.resolved.methods.transfer.tags.intent.args.template; // "Send {wad} to {dst}": the erc20 pack's, in this contract's names
177
+ ```
178
+
179
+ - **Contract profiles** (`kind: "contract"`) carry their ABI in `binds.abi` and the contracts they describe in
180
+ `binds.deployments` (EIP-55 checked: `E_ADDRESS_CHECKSUM`). **EVM packs** carry `binds.abi` and apply to a contract
181
+ that has every one of their functions, by selector, output types and kind of call (no subtyping); their addresses
182
+ and placeholders are rewritten to the contract's parameter names by position. A pack or profile for the other kind
183
+ of interface is `E_CHAIN` when given, and skipped in a pack search, so `loadPacks()` serves both kinds.
184
+ - **Refused for now:** overloaded function names and unreadable fragments (`E_ABI`); `idempotency`, `outcome`, `list`,
185
+ `names` and `named` on a contract (`E_TAG_TARGET`); `account` and `subaccount` (`E_TAG_NOT_APPLICABLE`); `[ ]`
186
+ template segments (`E_TEMPLATE`).
187
+ - **`@meantjs/profile/evm`** is the toolkit underneath, browser-safe and without dependencies: `keccak256`, `parseAbi`,
188
+ `parseSignature`, `canonicalFragment`, `selectorOf`, `abiInterfaceId`, a strict codec (`encodeParams`, `encodeCall`,
189
+ `decodeParams`: a value read from anything but its canonical encoding is refused), `toChecksumAddress`,
190
+ `readAddress` and `typedDataDigest` (EIP-712). `test/evm.test.mjs` checks Keccak against an independent
191
+ implementation (and the block boundary), the ERC-20 selectors, the ERC-8176 schema UID, EIP-55's examples and
192
+ EIP-712's Mail example.
193
+
166
194
  ## CLI
167
195
 
168
196
  ```sh
169
197
  node packages/resolver/bin/candid-profile.mjs resolve <service.did> [--profile p.json ...] [--packs] [--packs-dir dir] [--verbose] [--quiet] > resolved.json
198
+ node packages/resolver/bin/candid-profile.mjs resolve --abi contract.abi.json [--profile p.json ...] [--packs] # an EVM contract (section 15)
170
199
  # after `npm ci` the bin is also linked: npx candid-profile resolve ...
171
200
  ```
172
201
 
@@ -0,0 +1,221 @@
1
+ {
2
+ "format": "candid-profile",
3
+ "format_version": 0,
4
+ "kind": "pack",
5
+ "name": "erc20",
6
+ "origin": "pack",
7
+ "language": "en",
8
+ "description": "Standard pack for EIP-20 tokens on EVM chains (spec section 15, experimental). Applies to any contract that has every function of `binds.abi` with the same selector, outputs and kind of call; parameter names may differ (they are matched by position). `name()` is left out: no annotation reads it and EIP-20 makes it optional. A token without `decimals()` or `symbol()` matches no pack and needs a contract profile with literal values.",
9
+ "binds": {
10
+ "standard": "ERC-20",
11
+ "spec_url": "https://eips.ethereum.org/EIPS/eip-20",
12
+ "abi": [
13
+ "function symbol() view returns (string)",
14
+ "function decimals() view returns (uint8)",
15
+ "function balanceOf(address owner) view returns (uint256)",
16
+ "function allowance(address owner, address spender) view returns (uint256)",
17
+ "function transfer(address to, uint256 value) returns (bool)",
18
+ "function approve(address spender, uint256 value) returns (bool)",
19
+ "function transferFrom(address from, address to, uint256 value) returns (bool)"
20
+ ]
21
+ },
22
+ "annotations": [
23
+ {
24
+ "at": "transfer",
25
+ "tag": "intent",
26
+ "args": {
27
+ "title": "Send tokens",
28
+ "template": "Send {value} to {to}"
29
+ }
30
+ },
31
+ {
32
+ "at": "transfer",
33
+ "tag": "effect",
34
+ "args": {
35
+ "kind": "transfer",
36
+ "irreversible": true
37
+ }
38
+ },
39
+ {
40
+ "at": "transfer(0).value",
41
+ "tag": "amount",
42
+ "args": {
43
+ "decimals": {
44
+ "from": "query:decimals"
45
+ },
46
+ "symbol": {
47
+ "from": "query:symbol"
48
+ }
49
+ }
50
+ },
51
+ {
52
+ "at": "transfer(0).value",
53
+ "tag": "describe",
54
+ "args": {
55
+ "label": "Amount"
56
+ }
57
+ },
58
+ {
59
+ "at": "transfer(0).to",
60
+ "tag": "describe",
61
+ "args": {
62
+ "label": "Recipient"
63
+ }
64
+ },
65
+ {
66
+ "at": "approve",
67
+ "tag": "intent",
68
+ "args": {
69
+ "title": "Approve spending",
70
+ "template": "Set {spender}'s allowance to {value}, replacing any existing allowance"
71
+ }
72
+ },
73
+ {
74
+ "at": "approve",
75
+ "tag": "effect",
76
+ "args": {
77
+ "kind": "approve",
78
+ "irreversible": false
79
+ }
80
+ },
81
+ {
82
+ "at": "approve(0).spender",
83
+ "tag": "describe",
84
+ "args": {
85
+ "label": "Spender"
86
+ }
87
+ },
88
+ {
89
+ "at": "approve(0).value",
90
+ "tag": "amount",
91
+ "args": {
92
+ "decimals": {
93
+ "from": "query:decimals"
94
+ },
95
+ "symbol": {
96
+ "from": "query:symbol"
97
+ },
98
+ "threshold": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
99
+ "message": "Unlimited"
100
+ }
101
+ },
102
+ {
103
+ "at": "approve(0).value",
104
+ "tag": "describe",
105
+ "args": {
106
+ "label": "Allowance",
107
+ "help": "Maximum the spender may transfer. An approval replaces the previous allowance; it does not add to it."
108
+ }
109
+ },
110
+ {
111
+ "at": "transferFrom",
112
+ "tag": "intent",
113
+ "args": {
114
+ "title": "Transfer using allowance",
115
+ "template": "Move {value} from {from} to {to} using an allowance"
116
+ }
117
+ },
118
+ {
119
+ "at": "transferFrom",
120
+ "tag": "effect",
121
+ "args": {
122
+ "kind": "transfer",
123
+ "irreversible": true
124
+ }
125
+ },
126
+ {
127
+ "at": "transferFrom(0).from",
128
+ "tag": "describe",
129
+ "args": {
130
+ "label": "From"
131
+ }
132
+ },
133
+ {
134
+ "at": "transferFrom(0).to",
135
+ "tag": "describe",
136
+ "args": {
137
+ "label": "Recipient"
138
+ }
139
+ },
140
+ {
141
+ "at": "transferFrom(0).value",
142
+ "tag": "amount",
143
+ "args": {
144
+ "decimals": {
145
+ "from": "query:decimals"
146
+ },
147
+ "symbol": {
148
+ "from": "query:symbol"
149
+ }
150
+ }
151
+ },
152
+ {
153
+ "at": "transferFrom(0).value",
154
+ "tag": "describe",
155
+ "args": {
156
+ "label": "Amount"
157
+ }
158
+ },
159
+ {
160
+ "at": "balanceOf",
161
+ "tag": "describe",
162
+ "args": {
163
+ "label": "Balance of an address"
164
+ }
165
+ },
166
+ {
167
+ "at": "balanceOf(0).owner",
168
+ "tag": "describe",
169
+ "args": {
170
+ "label": "Owner"
171
+ }
172
+ },
173
+ {
174
+ "at": "balanceOf->(0)",
175
+ "tag": "amount",
176
+ "args": {
177
+ "decimals": {
178
+ "from": "query:decimals"
179
+ },
180
+ "symbol": {
181
+ "from": "query:symbol"
182
+ }
183
+ }
184
+ },
185
+ {
186
+ "at": "allowance",
187
+ "tag": "describe",
188
+ "args": {
189
+ "label": "Allowance of a spender"
190
+ }
191
+ },
192
+ {
193
+ "at": "allowance(0).owner",
194
+ "tag": "describe",
195
+ "args": {
196
+ "label": "Owner"
197
+ }
198
+ },
199
+ {
200
+ "at": "allowance(0).spender",
201
+ "tag": "describe",
202
+ "args": {
203
+ "label": "Spender"
204
+ }
205
+ },
206
+ {
207
+ "at": "allowance->(0)",
208
+ "tag": "amount",
209
+ "args": {
210
+ "decimals": {
211
+ "from": "query:decimals"
212
+ },
213
+ "symbol": {
214
+ "from": "query:symbol"
215
+ },
216
+ "threshold": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
217
+ "message": "Unlimited"
218
+ }
219
+ }
220
+ ]
221
+ }
@@ -24,7 +24,8 @@
24
24
  "kind": {
25
25
  "enum": [
26
26
  "canister",
27
- "pack"
27
+ "pack",
28
+ "contract"
28
29
  ]
29
30
  },
30
31
  "name": {
@@ -100,14 +101,36 @@
100
101
  }
101
102
  }
102
103
  }
104
+ },
105
+ {
106
+ "if": {
107
+ "properties": {
108
+ "kind": {
109
+ "const": "contract"
110
+ }
111
+ }
112
+ },
113
+ "then": {
114
+ "properties": {
115
+ "origin": {
116
+ "enum": [
117
+ "author",
118
+ "third_party",
119
+ "inferred"
120
+ ]
121
+ },
122
+ "binds": {
123
+ "$ref": "#/$defs/contract_binds"
124
+ }
125
+ }
126
+ }
103
127
  }
104
128
  ],
105
129
  "$defs": {
106
130
  "pack_binds": {
107
131
  "type": "object",
108
132
  "required": [
109
- "standard",
110
- "requires"
133
+ "standard"
111
134
  ],
112
135
  "additionalProperties": false,
113
136
  "properties": {
@@ -123,8 +146,30 @@
123
146
  "type": "string",
124
147
  "minLength": 10,
125
148
  "description": "A Candid service fragment. The pack applies to a canister whose service type is a subtype of this fragment."
149
+ },
150
+ "abi": {
151
+ "$ref": "#/$defs/evm_abi",
152
+ "description": "An EVM pack (spec section 15, experimental): the functions it applies to. The pack applies to a contract that has each of them, with the same selector, outputs and kind of call."
126
153
  }
127
- }
154
+ },
155
+ "oneOf": [
156
+ {
157
+ "required": [
158
+ "requires"
159
+ ],
160
+ "properties": {
161
+ "requires": true
162
+ }
163
+ },
164
+ {
165
+ "required": [
166
+ "abi"
167
+ ],
168
+ "properties": {
169
+ "abi": true
170
+ }
171
+ }
172
+ ]
128
173
  },
129
174
  "canister_binds": {
130
175
  "type": "object",
@@ -147,6 +192,73 @@
147
192
  }
148
193
  }
149
194
  },
195
+ "contract_binds": {
196
+ "type": "object",
197
+ "description": "An EVM contract (spec section 15, experimental): its ABI, and where it is deployed.",
198
+ "required": [
199
+ "abi"
200
+ ],
201
+ "additionalProperties": false,
202
+ "properties": {
203
+ "abi": {
204
+ "$ref": "#/$defs/evm_abi"
205
+ },
206
+ "deployments": {
207
+ "type": "array",
208
+ "minItems": 1,
209
+ "description": "The chain ids and addresses the profile describes (ERC-7730 context.contract.deployments). A consumer applies the profile to a call only when its target is listed.",
210
+ "items": {
211
+ "type": "object",
212
+ "required": [
213
+ "chain_id",
214
+ "address"
215
+ ],
216
+ "additionalProperties": false,
217
+ "properties": {
218
+ "chain_id": {
219
+ "type": "integer",
220
+ "minimum": 1
221
+ },
222
+ "address": {
223
+ "type": "string",
224
+ "pattern": "^0x[0-9a-fA-F]{40}$"
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ },
231
+ "evm_abi": {
232
+ "type": "array",
233
+ "minItems": 1,
234
+ "description": "EVM ABI function fragments: human-readable (`function transfer(address to, uint256 value) returns (bool)`) or JSON ABI entries. Only functions are read; events, errors, the constructor, fallback and receive are skipped. Parameter names are what addresses use.",
235
+ "items": {
236
+ "oneOf": [
237
+ {
238
+ "type": "string",
239
+ "pattern": "^\\s*(function|event|error|constructor|fallback|receive)\\b"
240
+ },
241
+ {
242
+ "type": "object",
243
+ "required": [
244
+ "type"
245
+ ],
246
+ "properties": {
247
+ "type": {
248
+ "enum": [
249
+ "function",
250
+ "event",
251
+ "error",
252
+ "constructor",
253
+ "fallback",
254
+ "receive"
255
+ ]
256
+ }
257
+ }
258
+ }
259
+ ]
260
+ }
261
+ },
150
262
  "value_address": {
151
263
  "type": "string",
152
264
  "description": "METHOD(i)path | METHOD->(i)path | type:DECL path. Paths: .label, .#id, [] (vec element). opt is transparent.",
@@ -244,8 +356,6 @@
244
356
  "properties": {
245
357
  "tag": {
246
358
  "enum": [
247
- "intent",
248
- "effect",
249
359
  "idempotency",
250
360
  "outcome",
251
361
  "list",
@@ -262,6 +372,32 @@
262
372
  }
263
373
  }
264
374
  },
375
+ {
376
+ "if": {
377
+ "properties": {
378
+ "tag": {
379
+ "enum": [
380
+ "intent",
381
+ "effect"
382
+ ]
383
+ }
384
+ }
385
+ },
386
+ "then": {
387
+ "properties": {
388
+ "at": {
389
+ "anyOf": [
390
+ {
391
+ "$ref": "#/$defs/method_address"
392
+ },
393
+ {
394
+ "$ref": "#/$defs/value_address"
395
+ }
396
+ ]
397
+ }
398
+ }
399
+ }
400
+ },
265
401
  {
266
402
  "if": {
267
403
  "properties": {
@@ -638,7 +774,23 @@
638
774
  "$ref": "#/$defs/dynamic"
639
775
  }
640
776
  ]
777
+ },
778
+ "threshold": {
779
+ "type": "string",
780
+ "pattern": "^(0|[1-9][0-9]{0,77})$",
781
+ "description": "Display only: a value at or above this (base units, a decimal string) displays as `message` and the symbol, for example \"Unlimited USDC\" (spec section 5.3)."
782
+ },
783
+ "message": {
784
+ "type": "string",
785
+ "minLength": 1,
786
+ "maxLength": 32,
787
+ "description": "What a value at or above `threshold` displays as (default \"Unlimited\")."
641
788
  }
789
+ },
790
+ "dependentRequired": {
791
+ "message": [
792
+ "threshold"
793
+ ]
642
794
  }
643
795
  },
644
796
  "args_timestamp": {