@orangecheck/stamp-ots 0.2.1 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orangecheck/stamp-ots",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "OpenTimestamps calendar client, proof helpers, and anchor-verification hooks for OC Stamp envelopes. See https://github.com/orangecheck/oc-stamp-protocol.",
5
5
  "keywords": [
6
6
  "bitcoin",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@noble/hashes": "^1.8.0",
52
- "@orangecheck/stamp-core": "^0.1.2"
52
+ "@orangecheck/stamp-core": "^1.0.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^22.10.2",
@@ -0,0 +1,74 @@
1
+ // The anchor verifier plugged into @orangecheck/stamp-core 1.x verify(), end
2
+ // to end: SPEC §8 step 5 through the `verifyOtsAnchor` hook.
3
+
4
+ import { verify, type StampEnvelope } from '@orangecheck/stamp-core';
5
+ import { sha256 } from '@noble/hashes/sha2';
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { blockHashOf, makeAnchorVerifier } from './anchor.js';
9
+ import { base64Encode, hexDecode } from './base64.js';
10
+ import { serializeTimestamp, type OtsTimestamp } from './ots.js';
11
+
12
+ // oc-stamp-protocol test-vectors/v01-minimal.json (placeholder signature).
13
+ const ENVELOPE = {
14
+ v: 1,
15
+ kind: 'stamp',
16
+ id: 'ad30c983dfc872a8c53cd70eb4d84e1869967a4b8433586beec7ba468b03c3de',
17
+ content: {
18
+ hash: 'sha256:1111111111111111111111111111111111111111111111111111111111111111',
19
+ length: 42,
20
+ mime: 'text/plain',
21
+ ref: null,
22
+ },
23
+ signer: { address: 'bc1qalice000000000000000000000000000000000', alg: 'bip322' },
24
+ signed_at: '2026-04-24T18:30:00Z',
25
+ stake: null,
26
+ ots: null,
27
+ sig: { alg: 'bip322', pubkey: 'bc1qalice000000000000000000000000000000000', value: 'ZmFrZS1zaWduYXR1cmU=' },
28
+ } as unknown as StampEnvelope;
29
+
30
+ const HEIGHT = 900_000;
31
+ const idBytes = hexDecode(ENVELOPE.id);
32
+ const root = sha256(idBytes);
33
+ // id --sha256--> root, attested at HEIGHT.
34
+ const proofTree: OtsTimestamp = {
35
+ msg: idBytes,
36
+ attestations: [],
37
+ ops: [{ op: { kind: 'sha256' }, child: { msg: root, attestations: [{ kind: 'bitcoin', height: HEIGHT }], ops: [] } }],
38
+ };
39
+ const header = new Uint8Array(80);
40
+ header.set(root, 36);
41
+ const HASH = blockHashOf(header);
42
+ const headers = { getHeaderAt: async (h: number) => (h === HEIGHT ? header : null) };
43
+
44
+ function withOts(blockHash = HASH): StampEnvelope {
45
+ return {
46
+ ...ENVELOPE,
47
+ ots: {
48
+ status: 'confirmed',
49
+ proof: base64Encode(serializeTimestamp(proofTree)),
50
+ calendars: ['https://alice.btc.calendar.opentimestamps.org'],
51
+ block_height: HEIGHT,
52
+ block_hash: blockHash,
53
+ upgraded_at: '2026-09-24T00:00:00Z',
54
+ },
55
+ } as StampEnvelope;
56
+ }
57
+
58
+ describe('stamp-core verify() with makeAnchorVerifier', () => {
59
+ const verifyOtsAnchor = makeAnchorVerifier({ headerSource: headers });
60
+
61
+ it('reports a verified confirmed anchor', async () => {
62
+ const r = await verify({ envelope: withOts(), skipSignatureVerification: true, verifyOtsAnchor });
63
+ expect(r.ok && r.anchor).toEqual({ status: 'confirmed', blockHeight: HEIGHT, blockHash: HASH, verified: true });
64
+ });
65
+
66
+ it('fails E_BAD_ANCHOR when the claimed block hash is not the header at that height', async () => {
67
+ const r = await verify({
68
+ envelope: withOts('00'.repeat(32)),
69
+ skipSignatureVerification: true,
70
+ verifyOtsAnchor,
71
+ });
72
+ expect(r.ok ? 'ok' : r.code).toBe('E_BAD_ANCHOR');
73
+ });
74
+ });