metered-protocol 1.0.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/LICENSE +21 -0
- package/README.md +103 -0
- package/contracts/metered.ag +135 -0
- package/contracts/metered_ag.tests.json +1226 -0
- package/contracts/metered_session.sil +237 -0
- package/contracts/metered_session.tests.json +1113 -0
- package/dist/contracts/metered.ag +135 -0
- package/dist/contracts/metered_ag.tests.json +1226 -0
- package/dist/contracts/metered_session.sil +237 -0
- package/dist/contracts/metered_session.tests.json +1113 -0
- package/dist/src/bias.d.ts +48 -0
- package/dist/src/bias.d.ts.map +1 -0
- package/dist/src/bias.js +43 -0
- package/dist/src/bias.js.map +1 -0
- package/dist/src/checkpoint.d.ts +57 -0
- package/dist/src/checkpoint.d.ts.map +1 -0
- package/dist/src/checkpoint.js +84 -0
- package/dist/src/checkpoint.js.map +1 -0
- package/dist/src/deadline.d.ts +71 -0
- package/dist/src/deadline.d.ts.map +1 -0
- package/dist/src/deadline.js +77 -0
- package/dist/src/deadline.js.map +1 -0
- package/dist/src/encoding.d.ts +72 -0
- package/dist/src/encoding.d.ts.map +1 -0
- package/dist/src/encoding.js +187 -0
- package/dist/src/encoding.js.map +1 -0
- package/dist/src/history.d.ts +33 -0
- package/dist/src/history.d.ts.map +1 -0
- package/dist/src/history.js +38 -0
- package/dist/src/history.js.map +1 -0
- package/dist/src/http/buyer.d.ts +57 -0
- package/dist/src/http/buyer.d.ts.map +1 -0
- package/dist/src/http/buyer.js +151 -0
- package/dist/src/http/buyer.js.map +1 -0
- package/dist/src/http/client.d.ts +55 -0
- package/dist/src/http/client.d.ts.map +1 -0
- package/dist/src/http/client.js +83 -0
- package/dist/src/http/client.js.map +1 -0
- package/dist/src/http/harness.d.ts +18 -0
- package/dist/src/http/harness.d.ts.map +1 -0
- package/dist/src/http/harness.js +16 -0
- package/dist/src/http/harness.js.map +1 -0
- package/dist/src/http/protocol.d.ts +84 -0
- package/dist/src/http/protocol.d.ts.map +1 -0
- package/dist/src/http/protocol.js +22 -0
- package/dist/src/http/protocol.js.map +1 -0
- package/dist/src/http/provider.d.ts +123 -0
- package/dist/src/http/provider.d.ts.map +1 -0
- package/dist/src/http/provider.js +197 -0
- package/dist/src/http/provider.js.map +1 -0
- package/dist/src/http/serve.d.ts +34 -0
- package/dist/src/http/serve.d.ts.map +1 -0
- package/dist/src/http/serve.js +171 -0
- package/dist/src/http/serve.js.map +1 -0
- package/dist/src/http/service.d.ts +86 -0
- package/dist/src/http/service.d.ts.map +1 -0
- package/dist/src/http/service.js +161 -0
- package/dist/src/http/service.js.map +1 -0
- package/dist/src/index.d.ts +68 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +62 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/meter.d.ts +39 -0
- package/dist/src/meter.d.ts.map +1 -0
- package/dist/src/meter.js +100 -0
- package/dist/src/meter.js.map +1 -0
- package/dist/src/offer.d.ts +6 -0
- package/dist/src/offer.d.ts.map +1 -0
- package/dist/src/offer.js +92 -0
- package/dist/src/offer.js.map +1 -0
- package/dist/src/reconcile.d.ts +18 -0
- package/dist/src/reconcile.d.ts.map +1 -0
- package/dist/src/reconcile.js +101 -0
- package/dist/src/reconcile.js.map +1 -0
- package/dist/src/reservation.d.ts +51 -0
- package/dist/src/reservation.d.ts.map +1 -0
- package/dist/src/reservation.js +124 -0
- package/dist/src/reservation.js.map +1 -0
- package/dist/src/session.d.ts +40 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +92 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/signer.d.ts +31 -0
- package/dist/src/signer.d.ts.map +1 -0
- package/dist/src/signer.js +57 -0
- package/dist/src/signer.js.map +1 -0
- package/dist/src/store.d.ts +30 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +120 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/types.d.ts +80 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +9 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tools/anchor-cli.d.ts +2 -0
- package/dist/tools/anchor-cli.d.ts.map +1 -0
- package/dist/tools/anchor-cli.js +101 -0
- package/dist/tools/anchor-cli.js.map +1 -0
- package/dist/tools/anchor.d.ts +68 -0
- package/dist/tools/anchor.d.ts.map +1 -0
- package/dist/tools/anchor.js +136 -0
- package/dist/tools/anchor.js.map +1 -0
- package/dist/tools/chain.d.ts +18 -0
- package/dist/tools/chain.d.ts.map +1 -0
- package/dist/tools/chain.js +18 -0
- package/dist/tools/chain.js.map +1 -0
- package/dist/tools/conformance.d.ts +2 -0
- package/dist/tools/conformance.d.ts.map +1 -0
- package/dist/tools/conformance.js +220 -0
- package/dist/tools/conformance.js.map +1 -0
- package/dist/tools/contracts.d.ts +2 -0
- package/dist/tools/contracts.d.ts.map +1 -0
- package/dist/tools/contracts.js +68 -0
- package/dist/tools/contracts.js.map +1 -0
- package/dist/tools/covenant-binding.d.ts +40 -0
- package/dist/tools/covenant-binding.d.ts.map +1 -0
- package/dist/tools/covenant-binding.js +60 -0
- package/dist/tools/covenant-binding.js.map +1 -0
- package/dist/tools/covenant-profile.d.ts +41 -0
- package/dist/tools/covenant-profile.d.ts.map +1 -0
- package/dist/tools/covenant-profile.js +74 -0
- package/dist/tools/covenant-profile.js.map +1 -0
- package/dist/tools/covenant.d.ts +30 -0
- package/dist/tools/covenant.d.ts.map +1 -0
- package/dist/tools/covenant.js +54 -0
- package/dist/tools/covenant.js.map +1 -0
- package/dist/tools/demo-report.d.ts +24 -0
- package/dist/tools/demo-report.d.ts.map +1 -0
- package/dist/tools/demo-report.js +40 -0
- package/dist/tools/demo-report.js.map +1 -0
- package/dist/tools/demo.d.ts +2 -0
- package/dist/tools/demo.d.ts.map +1 -0
- package/dist/tools/demo.js +204 -0
- package/dist/tools/demo.js.map +1 -0
- package/dist/tools/dust-map.d.ts +2 -0
- package/dist/tools/dust-map.d.ts.map +1 -0
- package/dist/tools/dust-map.js +63 -0
- package/dist/tools/dust-map.js.map +1 -0
- package/dist/tools/expire-cases.d.ts +4 -0
- package/dist/tools/expire-cases.d.ts.map +1 -0
- package/dist/tools/expire-cases.js +211 -0
- package/dist/tools/expire-cases.js.map +1 -0
- package/dist/tools/fee-check.d.ts +2 -0
- package/dist/tools/fee-check.d.ts.map +1 -0
- package/dist/tools/fee-check.js +127 -0
- package/dist/tools/fee-check.js.map +1 -0
- package/dist/tools/fixtures.d.ts +39 -0
- package/dist/tools/fixtures.d.ts.map +1 -0
- package/dist/tools/fixtures.js +31 -0
- package/dist/tools/fixtures.js.map +1 -0
- package/dist/tools/gen-contract-tests.d.ts +2 -0
- package/dist/tools/gen-contract-tests.d.ts.map +1 -0
- package/dist/tools/gen-contract-tests.js +170 -0
- package/dist/tools/gen-contract-tests.js.map +1 -0
- package/dist/tools/kaspa.d.ts +13 -0
- package/dist/tools/kaspa.d.ts.map +1 -0
- package/dist/tools/kaspa.js +76 -0
- package/dist/tools/kaspa.js.map +1 -0
- package/dist/tools/live-deadline.d.ts +2 -0
- package/dist/tools/live-deadline.d.ts.map +1 -0
- package/dist/tools/live-deadline.js +122 -0
- package/dist/tools/live-deadline.js.map +1 -0
- package/dist/tools/live-expire.d.ts +2 -0
- package/dist/tools/live-expire.d.ts.map +1 -0
- package/dist/tools/live-expire.js +127 -0
- package/dist/tools/live-expire.js.map +1 -0
- package/dist/tools/live-settle.d.ts +2 -0
- package/dist/tools/live-settle.d.ts.map +1 -0
- package/dist/tools/live-settle.js +226 -0
- package/dist/tools/live-settle.js.map +1 -0
- package/dist/tools/live-steps.d.ts +63 -0
- package/dist/tools/live-steps.d.ts.map +1 -0
- package/dist/tools/live-steps.js +155 -0
- package/dist/tools/live-steps.js.map +1 -0
- package/dist/tools/model.d.ts +32 -0
- package/dist/tools/model.d.ts.map +1 -0
- package/dist/tools/model.js +99 -0
- package/dist/tools/model.js.map +1 -0
- package/dist/tools/send.d.ts +2 -0
- package/dist/tools/send.d.ts.map +1 -0
- package/dist/tools/send.js +41 -0
- package/dist/tools/send.js.map +1 -0
- package/dist/tools/session-chain.d.ts +69 -0
- package/dist/tools/session-chain.d.ts.map +1 -0
- package/dist/tools/session-chain.js +113 -0
- package/dist/tools/session-chain.js.map +1 -0
- package/dist/tools/sighash.d.ts +9 -0
- package/dist/tools/sighash.d.ts.map +1 -0
- package/dist/tools/sighash.js +68 -0
- package/dist/tools/sighash.js.map +1 -0
- package/dist/tools/sigscript-check.d.ts +2 -0
- package/dist/tools/sigscript-check.d.ts.map +1 -0
- package/dist/tools/sigscript-check.js +113 -0
- package/dist/tools/sigscript-check.js.map +1 -0
- package/dist/tools/sigscript.d.ts +61 -0
- package/dist/tools/sigscript.d.ts.map +1 -0
- package/dist/tools/sigscript.js +70 -0
- package/dist/tools/sigscript.js.map +1 -0
- package/dist/tools/state-layout.d.ts +2 -0
- package/dist/tools/state-layout.d.ts.map +1 -0
- package/dist/tools/state-layout.js +57 -0
- package/dist/tools/state-layout.js.map +1 -0
- package/package.json +59 -0
- package/spec/CONFORMANCE.md +80 -0
- package/spec/SPEC.md +821 -0
- package/spec/conformance-vectors.json +677 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Conformance
|
|
2
|
+
|
|
3
|
+
**If you are implementing `metered`, this is the file that tells you whether you have.**
|
|
4
|
+
|
|
5
|
+
`conformance-vectors.json` contains inputs and the exact outputs a correct implementation must
|
|
6
|
+
produce. It is generated from a working implementation and checked back against it on every commit,
|
|
7
|
+
so it describes behaviour that runs rather than behaviour that was remembered.
|
|
8
|
+
|
|
9
|
+
You need no TypeScript, no dependency on this repository, and no agreement with any of its internal
|
|
10
|
+
choices. You need the same answers.
|
|
11
|
+
|
|
12
|
+
## Why this file exists
|
|
13
|
+
|
|
14
|
+
A protocol whose central claim is that **two independent implementations can measure the same
|
|
15
|
+
delivered work and agree** is only as good as that agreement. Prose cannot establish it; identical
|
|
16
|
+
bytes can.
|
|
17
|
+
|
|
18
|
+
These vectors are generated from a working implementation and checked back against it, and a second
|
|
19
|
+
implementation written from the specification alone reproduces all of them.
|
|
20
|
+
|
|
21
|
+
## Running them
|
|
22
|
+
|
|
23
|
+
Each group names the section of `SPEC.md` it comes from. Every case has `given` and `expect`.
|
|
24
|
+
Compare the fields in `expect` exactly — byte for byte where they are hex, value for value
|
|
25
|
+
otherwise.
|
|
26
|
+
|
|
27
|
+
| Group | Section | What diverges if you get it wrong |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| canonical JSON | §2 | every digest and every signature, silently |
|
|
30
|
+
| settlement preimage | §3.4.1 | signatures two peers accept and the chain rejects |
|
|
31
|
+
| signature verification | §2.6, §3.4 | you accept forgeries, or reject honest peers |
|
|
32
|
+
| reconciliation | §5 | you bill a different amount than your counterparty |
|
|
33
|
+
| close shape and funding | §7.4a, §7.4b | funds that cannot be paid out at all |
|
|
34
|
+
|
|
35
|
+
## The four that catch people
|
|
36
|
+
|
|
37
|
+
1. **Canonical JSON sorts by UTF-16 code unit, not by code point or locale.** The vectors include a
|
|
38
|
+
case where those orders differ. A sort that looks right in your language may not be.
|
|
39
|
+
|
|
40
|
+
2. **A State's signature does NOT cover its JSON.** It covers the 72-byte preimage of §3.4.1 —
|
|
41
|
+
`sessionId(16) ‖ seq(8) ‖ cumulativeUnits(8) ‖ cumulativeSompi(8) ‖ prevState(32)`. Signing the
|
|
42
|
+
JSON instead produces a signature your counterparty accepts and the covenant cannot check, which
|
|
43
|
+
is a session that can never settle. Every other message *is* signed over canonical JSON. This one
|
|
44
|
+
is the exception, and it is the exception because a Kaspa script cannot build JSON.
|
|
45
|
+
|
|
46
|
+
3. **Integers in the preimage are 8-byte signed-magnitude, little-endian** — the sign lives in the
|
|
47
|
+
top bit of the last byte, not in a two's-complement representation. There is a vector with
|
|
48
|
+
`seq: -1` precisely because that is where the two encodings differ.
|
|
49
|
+
|
|
50
|
+
4. **`prevState` is `null` in JSON and 32 ZERO bytes in the preimage.** A null has no byte form, so
|
|
51
|
+
it is given one. Omitting those 32 bytes shortens the preimage and changes every digest after it.
|
|
52
|
+
|
|
53
|
+
## Signatures are pinned as verification, not as production
|
|
54
|
+
|
|
55
|
+
BIP340 signing is randomised: two correct implementations signing the same message produce different
|
|
56
|
+
bytes, and both are valid. So no vector asks you to produce a particular signature. The vectors give
|
|
57
|
+
you signatures and ask whether you agree they verify — including the cases where the answer is
|
|
58
|
+
**false**, which is the half that matters.
|
|
59
|
+
|
|
60
|
+
## What is not here
|
|
61
|
+
|
|
62
|
+
The tokeniser vectors live separately, in `../evidence/tokenizer-vectors.json`, because they are large
|
|
63
|
+
and change on a different schedule. `llm.output_tokens.v1` is only meaningful if you reproduce those
|
|
64
|
+
too: it counts delivered assistant content under the meter the Offer names, and a meter that draws
|
|
65
|
+
its boundaries elsewhere produces a different number for the same bytes.
|
|
66
|
+
|
|
67
|
+
`net.bytes_delivered.v1` needs no separate file. It is counted here, in §6, because an exact meter
|
|
68
|
+
has nothing to pin beyond the arithmetic — which is also why it is the unit that permits a
|
|
69
|
+
`toleranceAbs` of 0.
|
|
70
|
+
|
|
71
|
+
The covenant has its own suites — `contracts/metered_session.tests.json` and
|
|
72
|
+
`contracts/metered_ag.tests.json` — which execute against a SilverScript simulator rather than
|
|
73
|
+
against a protocol implementation.
|
|
74
|
+
|
|
75
|
+
## Reporting a disagreement
|
|
76
|
+
|
|
77
|
+
A vector that is wrong is a defect in this repository, not in the implementation that fails it.
|
|
78
|
+
Open an issue with the case, the value produced, and the section of `SPEC.md` relied on.
|
|
79
|
+
|
|
80
|
+
Regenerate with `npm run conformance`; verify with `npm test`.
|