@ekwo-ai/core 0.11.0 → 0.12.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/README.md +5 -0
- package/dist/books/document-pdf.d.ts +87 -0
- package/dist/books/document-pdf.d.ts.map +1 -0
- package/dist/books/document-pdf.js +222 -0
- package/dist/books/document-pdf.js.map +1 -0
- package/dist/books/index.d.ts +1 -0
- package/dist/books/index.d.ts.map +1 -1
- package/dist/books/index.js +1 -0
- package/dist/books/index.js.map +1 -1
- package/dist/einvoicing/directory.d.ts +38 -0
- package/dist/einvoicing/directory.d.ts.map +1 -0
- package/dist/einvoicing/directory.js +121 -0
- package/dist/einvoicing/directory.js.map +1 -0
- package/dist/einvoicing/formats.d.ts +65 -0
- package/dist/einvoicing/formats.d.ts.map +1 -0
- package/dist/einvoicing/formats.js +380 -0
- package/dist/einvoicing/formats.js.map +1 -0
- package/dist/einvoicing/index.d.ts +11 -0
- package/dist/einvoicing/index.d.ts.map +1 -0
- package/dist/einvoicing/index.js +11 -0
- package/dist/einvoicing/index.js.map +1 -0
- package/dist/einvoicing/issue.d.ts +98 -0
- package/dist/einvoicing/issue.d.ts.map +1 -0
- package/dist/einvoicing/issue.js +398 -0
- package/dist/einvoicing/issue.js.map +1 -0
- package/dist/einvoicing/transport.d.ts +130 -0
- package/dist/einvoicing/transport.d.ts.map +1 -0
- package/dist/einvoicing/transport.js +60 -0
- package/dist/einvoicing/transport.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/proofs/filing-proofs.d.ts +93 -0
- package/dist/proofs/filing-proofs.d.ts.map +1 -0
- package/dist/proofs/filing-proofs.js +161 -0
- package/dist/proofs/filing-proofs.js.map +1 -0
- package/dist/proofs/index.d.ts +7 -0
- package/dist/proofs/index.d.ts.map +1 -0
- package/dist/proofs/index.js +7 -0
- package/dist/proofs/index.js.map +1 -0
- package/dist/proofs/opentimestamps.d.ts +185 -0
- package/dist/proofs/opentimestamps.d.ts.map +1 -0
- package/dist/proofs/opentimestamps.js +508 -0
- package/dist/proofs/opentimestamps.js.map +1 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/package.json +14 -11
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAwB,MAAM,WAAW,CAAC;AACpE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,4BAA4B,EAC5B,iBAAiB,EACjB,yBAAyB,GAG1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAgB,MAAM,eAAe,CAAC;AACjG,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GAGpB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAwB,MAAM,WAAW,CAAC;AACpE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,4BAA4B,EAC5B,iBAAiB,EACjB,yBAAyB,GAG1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAgB,MAAM,eAAe,CAAC;AACjG,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GAGpB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filing proofs, for every surface: prove a file, complete what is pending,
|
|
3
|
+
* read a proof back by its hash.
|
|
4
|
+
*
|
|
5
|
+
* The network half — calendars, block explorer — is `opentimestamps.ts`; the
|
|
6
|
+
* database half is three functions of the schema (`record_filing_proof`,
|
|
7
|
+
* `upgrade_filing_proof`, `filing_proof`). This file joins them through the
|
|
8
|
+
* same `Backend` every bookkeeping function is written against, so the
|
|
9
|
+
* command line, the MCP server and a scheduled job act as the person or key
|
|
10
|
+
* they are, under row level security.
|
|
11
|
+
*/
|
|
12
|
+
import { type Backend, type Row } from '../books/backend.js';
|
|
13
|
+
import { type ProofFetch } from './opentimestamps.js';
|
|
14
|
+
export type FilingProofSubject = 'tax_filing' | 'fiscal_year' | 'document';
|
|
15
|
+
export declare const FILING_PROOF_SUBJECTS: readonly FilingProofSubject[];
|
|
16
|
+
export interface NetworkOptions {
|
|
17
|
+
fetch: ProofFetch;
|
|
18
|
+
/** Calendars a hash is submitted to. `DEFAULT_CALENDARS` otherwise. */
|
|
19
|
+
calendars?: readonly string[];
|
|
20
|
+
/** The only calendars an upgrade dials. `DEFAULT_UPGRADE_CALENDARS` otherwise. */
|
|
21
|
+
upgradeCalendars?: readonly string[];
|
|
22
|
+
/** An Esplora block explorer, for the time of the anchoring block. */
|
|
23
|
+
explorer?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ProveFileArgs {
|
|
26
|
+
subject_kind: FilingProofSubject;
|
|
27
|
+
subject_id: string;
|
|
28
|
+
/** The exact bytes of the file. Only their sha256 leaves this process. */
|
|
29
|
+
bytes: Uint8Array;
|
|
30
|
+
attachment_id?: string;
|
|
31
|
+
values_sha256?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hashes a file, submits the hash to the calendars and records the pending
|
|
35
|
+
* proof. A file already proved by this company is not submitted again: the
|
|
36
|
+
* proof it has is returned.
|
|
37
|
+
*/
|
|
38
|
+
export declare function proveFile(backend: Backend, args: ProveFileArgs, network: NetworkOptions): Promise<Row>;
|
|
39
|
+
export interface UpgradeReport {
|
|
40
|
+
checked: number;
|
|
41
|
+
/** Anchored in a block during this run. */
|
|
42
|
+
completed: Row[];
|
|
43
|
+
/** Still waiting on a calendar. */
|
|
44
|
+
pending: {
|
|
45
|
+
id: string;
|
|
46
|
+
sha256: string;
|
|
47
|
+
calendars: string[];
|
|
48
|
+
}[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Asks the calendars about every pending proof of a company, records the
|
|
52
|
+
* longer proof, and completes those a Bitcoin block now anchors — with the
|
|
53
|
+
* time of that block, after checking its merkle root against the proof.
|
|
54
|
+
* Meant to run on a schedule: a calendar commits a round to a block in a few
|
|
55
|
+
* hours, and asking again before then costs one request and changes nothing.
|
|
56
|
+
*/
|
|
57
|
+
export declare function upgradeFilingProofs(backend: Backend, companyId: string, network: NetworkOptions): Promise<UpgradeReport>;
|
|
58
|
+
export interface PublishedProof {
|
|
59
|
+
sha256: string;
|
|
60
|
+
method: string;
|
|
61
|
+
status: string;
|
|
62
|
+
anchor_chain: string | null;
|
|
63
|
+
anchor_height: number | string | null;
|
|
64
|
+
anchor_time: string | null;
|
|
65
|
+
anchor_reference: string | null;
|
|
66
|
+
recorded_at: string;
|
|
67
|
+
completed_at: string | null;
|
|
68
|
+
proof_base64: string;
|
|
69
|
+
}
|
|
70
|
+
/** What the public door of the schema says about a hash: one row per method, or none. */
|
|
71
|
+
export declare function lookupFilingProof(backend: Backend, sha256Hex: string): Promise<PublishedProof[]>;
|
|
72
|
+
export interface ProofCheck {
|
|
73
|
+
/** The proof is about these bytes. */
|
|
74
|
+
matches_file: boolean;
|
|
75
|
+
/** Bitcoin blocks the proof is anchored in, checked against an explorer when one was asked. */
|
|
76
|
+
bitcoin: {
|
|
77
|
+
height: number;
|
|
78
|
+
hash?: string;
|
|
79
|
+
time?: string;
|
|
80
|
+
}[];
|
|
81
|
+
/** Calendars the proof still waits on. */
|
|
82
|
+
pending: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks a `.ots` file against the bytes it claims to be about, and — given
|
|
86
|
+
* an explorer — each Bitcoin anchor against the block it names. Needs nothing
|
|
87
|
+
* from any Ekwo installation: a proof is verified against the public ledger.
|
|
88
|
+
*/
|
|
89
|
+
export declare function checkProof(bytes: Uint8Array, ots: Uint8Array, network?: {
|
|
90
|
+
fetch: ProofFetch;
|
|
91
|
+
explorer?: string;
|
|
92
|
+
}): Promise<ProofCheck>;
|
|
93
|
+
//# sourceMappingURL=filing-proofs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filing-proofs.d.ts","sourceRoot":"","sources":["../../src/proofs/filing-proofs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EASL,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,aAAa,GAAG,UAAU,CAAC;AAE3E,eAAO,MAAM,qBAAqB,EAAE,SAAS,kBAAkB,EAA8C,CAAC;AAwB9G,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,UAAU,CAAC;IAClB,uEAAuE;IACvE,SAAS,CAAC,EAAE,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CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,yFAAyF;AACzF,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAEtG;AAED,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,+FAA+F;IAC/F,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5D,0CAA0C;IAC1C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD,OAAO,CAAC,UAAU,CAAC,CAcrB"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filing proofs, for every surface: prove a file, complete what is pending,
|
|
3
|
+
* read a proof back by its hash.
|
|
4
|
+
*
|
|
5
|
+
* The network half — calendars, block explorer — is `opentimestamps.ts`; the
|
|
6
|
+
* database half is three functions of the schema (`record_filing_proof`,
|
|
7
|
+
* `upgrade_filing_proof`, `filing_proof`). This file joins them through the
|
|
8
|
+
* same `Backend` every bookkeeping function is written against, so the
|
|
9
|
+
* command line, the MCP server and a scheduled job act as the person or key
|
|
10
|
+
* they are, under row level security.
|
|
11
|
+
*/
|
|
12
|
+
import { BooksError } from '../books/backend.js';
|
|
13
|
+
import { bitcoinAnchors, bitcoinBlockAt, pendingCalendars, readOts, sha256, stampDigest, toHex, upgradeProof, } from './opentimestamps.js';
|
|
14
|
+
export const FILING_PROOF_SUBJECTS = ['tax_filing', 'fiscal_year', 'document'];
|
|
15
|
+
/** The columns a proof is read with. The bytes travel as hex text on both routes. */
|
|
16
|
+
const PROOF_COLUMNS = [
|
|
17
|
+
'id',
|
|
18
|
+
'company_id',
|
|
19
|
+
'subject_kind',
|
|
20
|
+
'tax_filing_id',
|
|
21
|
+
'fiscal_year_id',
|
|
22
|
+
'document_id',
|
|
23
|
+
'attachment_id',
|
|
24
|
+
'sha256',
|
|
25
|
+
'values_sha256',
|
|
26
|
+
'method',
|
|
27
|
+
'status',
|
|
28
|
+
'calendars',
|
|
29
|
+
'anchor_chain',
|
|
30
|
+
'anchor_height',
|
|
31
|
+
'anchor_time',
|
|
32
|
+
'anchor_reference',
|
|
33
|
+
'created_at',
|
|
34
|
+
'completed_at',
|
|
35
|
+
];
|
|
36
|
+
/** What a stored proof carries, without its bytes. */
|
|
37
|
+
function proofView(row) {
|
|
38
|
+
const { proof: _proof, ...rest } = row;
|
|
39
|
+
return rest;
|
|
40
|
+
}
|
|
41
|
+
/** `\x0001…` — how both routes render a bytea column. */
|
|
42
|
+
function bytesOfHexText(value) {
|
|
43
|
+
const text = String(value ?? '');
|
|
44
|
+
if (!text.startsWith('\\x'))
|
|
45
|
+
throw new BooksError(`bad_proof: a proof read back as "${text.slice(0, 20)}…"`);
|
|
46
|
+
return Uint8Array.from(Buffer.from(text.slice(2), 'hex'));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Hashes a file, submits the hash to the calendars and records the pending
|
|
50
|
+
* proof. A file already proved by this company is not submitted again: the
|
|
51
|
+
* proof it has is returned.
|
|
52
|
+
*/
|
|
53
|
+
export async function proveFile(backend, args, network) {
|
|
54
|
+
const digest = sha256(args.bytes);
|
|
55
|
+
const hex = toHex(digest);
|
|
56
|
+
const existing = await backend.select({
|
|
57
|
+
table: 'filing_proofs',
|
|
58
|
+
columns: PROOF_COLUMNS,
|
|
59
|
+
where: [
|
|
60
|
+
{ column: 'sha256', op: 'eq', value: hex },
|
|
61
|
+
{ column: 'method', op: 'eq', value: 'opentimestamps' },
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
if (existing.length > 0) {
|
|
65
|
+
return { proof: existing[0], already_proved: true, calendars_failed: [] };
|
|
66
|
+
}
|
|
67
|
+
const stamped = await stampDigest(digest, {
|
|
68
|
+
fetch: network.fetch,
|
|
69
|
+
...(network.calendars === undefined ? {} : { calendars: network.calendars }),
|
|
70
|
+
});
|
|
71
|
+
const [row] = await backend.rpc('record_filing_proof', {
|
|
72
|
+
p_subject_kind: args.subject_kind,
|
|
73
|
+
p_subject_id: args.subject_id,
|
|
74
|
+
p_sha256: hex,
|
|
75
|
+
p_method: 'opentimestamps',
|
|
76
|
+
p_proof_base64: Buffer.from(stamped.ots).toString('base64'),
|
|
77
|
+
p_calendars: stamped.calendars,
|
|
78
|
+
...(args.attachment_id === undefined ? {} : { p_attachment_id: args.attachment_id }),
|
|
79
|
+
...(args.values_sha256 === undefined ? {} : { p_values_sha256: args.values_sha256 }),
|
|
80
|
+
});
|
|
81
|
+
if (row === undefined)
|
|
82
|
+
throw new BooksError('record_filing_proof returned no row');
|
|
83
|
+
return { proof: proofView(row), already_proved: false, calendars_failed: stamped.failures };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Asks the calendars about every pending proof of a company, records the
|
|
87
|
+
* longer proof, and completes those a Bitcoin block now anchors — with the
|
|
88
|
+
* time of that block, after checking its merkle root against the proof.
|
|
89
|
+
* Meant to run on a schedule: a calendar commits a round to a block in a few
|
|
90
|
+
* hours, and asking again before then costs one request and changes nothing.
|
|
91
|
+
*/
|
|
92
|
+
export async function upgradeFilingProofs(backend, companyId, network) {
|
|
93
|
+
const rows = await backend.select({
|
|
94
|
+
table: 'filing_proofs',
|
|
95
|
+
columns: ['id', 'sha256', 'proof::text'],
|
|
96
|
+
where: [
|
|
97
|
+
{ column: 'company_id', op: 'eq', value: companyId },
|
|
98
|
+
{ column: 'status', op: 'eq', value: 'pending' },
|
|
99
|
+
{ column: 'method', op: 'eq', value: 'opentimestamps' },
|
|
100
|
+
],
|
|
101
|
+
order: [{ column: 'created_at' }],
|
|
102
|
+
});
|
|
103
|
+
const report = { checked: rows.length, completed: [], pending: [] };
|
|
104
|
+
for (const row of rows) {
|
|
105
|
+
const ots = bytesOfHexText(row['proof']);
|
|
106
|
+
const upgraded = await upgradeProof(ots, {
|
|
107
|
+
fetch: network.fetch,
|
|
108
|
+
...(network.upgradeCalendars === undefined ? {} : { calendars: network.upgradeCalendars }),
|
|
109
|
+
});
|
|
110
|
+
if (upgraded.bitcoin !== undefined) {
|
|
111
|
+
const block = await bitcoinBlockAt(upgraded.bitcoin.height, upgraded.bitcoin.merkleRoot, {
|
|
112
|
+
fetch: network.fetch,
|
|
113
|
+
...(network.explorer === undefined ? {} : { explorer: network.explorer }),
|
|
114
|
+
});
|
|
115
|
+
const [done] = await backend.rpc('upgrade_filing_proof', {
|
|
116
|
+
p_proof_id: row['id'],
|
|
117
|
+
p_proof_base64: Buffer.from(upgraded.ots).toString('base64'),
|
|
118
|
+
p_anchor_chain: 'bitcoin',
|
|
119
|
+
p_anchor_height: block.height,
|
|
120
|
+
p_anchor_time: block.time,
|
|
121
|
+
p_anchor_reference: block.hash,
|
|
122
|
+
});
|
|
123
|
+
if (done !== undefined)
|
|
124
|
+
report.completed.push(proofView(done));
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (upgraded.changed) {
|
|
128
|
+
await backend.rpc('upgrade_filing_proof', {
|
|
129
|
+
p_proof_id: row['id'],
|
|
130
|
+
p_proof_base64: Buffer.from(upgraded.ots).toString('base64'),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
report.pending.push({ id: String(row['id']), sha256: String(row['sha256']), calendars: upgraded.pending });
|
|
134
|
+
}
|
|
135
|
+
return report;
|
|
136
|
+
}
|
|
137
|
+
/** What the public door of the schema says about a hash: one row per method, or none. */
|
|
138
|
+
export async function lookupFilingProof(backend, sha256Hex) {
|
|
139
|
+
return backend.rpc('filing_proof', { p_sha256: sha256Hex });
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks a `.ots` file against the bytes it claims to be about, and — given
|
|
143
|
+
* an explorer — each Bitcoin anchor against the block it names. Needs nothing
|
|
144
|
+
* from any Ekwo installation: a proof is verified against the public ledger.
|
|
145
|
+
*/
|
|
146
|
+
export async function checkProof(bytes, ots, network) {
|
|
147
|
+
const proof = readOts(ots);
|
|
148
|
+
const matches = toHex(proof.digest) === toHex(sha256(bytes));
|
|
149
|
+
const anchors = bitcoinAnchors(proof.timestamp);
|
|
150
|
+
const bitcoin = [];
|
|
151
|
+
for (const anchor of anchors) {
|
|
152
|
+
if (network === undefined) {
|
|
153
|
+
bitcoin.push({ height: anchor.height });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const block = await bitcoinBlockAt(anchor.height, anchor.merkleRoot, network);
|
|
157
|
+
bitcoin.push({ height: block.height, hash: block.hash, time: block.time });
|
|
158
|
+
}
|
|
159
|
+
return { matches_file: matches, bitcoin, pending: pendingCalendars(proof.timestamp) };
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=filing-proofs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filing-proofs.js","sourceRoot":"","sources":["../../src/proofs/filing-proofs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAA0B,MAAM,qBAAqB,CAAC;AACzE,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,MAAM,EACN,WAAW,EACX,KAAK,EACL,YAAY,GAEb,MAAM,qBAAqB,CAAC;AAI7B,MAAM,CAAC,MAAM,qBAAqB,GAAkC,CAAC,YAAY,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;AAE9G,qFAAqF;AACrF,MAAM,aAAa,GAAG;IACpB,IAAI;IACJ,YAAY;IACZ,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AAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filing proofs: the sha256 of a file committed to a public ledger, and the
|
|
3
|
+
* proof that it was. `docs/filing-proofs.md` says what the feature is for.
|
|
4
|
+
*/
|
|
5
|
+
export * from './opentimestamps.js';
|
|
6
|
+
export * from './filing-proofs.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proofs/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filing proofs: the sha256 of a file committed to a public ledger, and the
|
|
3
|
+
* proof that it was. `docs/filing-proofs.md` says what the feature is for.
|
|
4
|
+
*/
|
|
5
|
+
export * from './opentimestamps.js';
|
|
6
|
+
export * from './filing-proofs.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proofs/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTimestamps: the detached proof file (`.ots`), the public calendars that
|
|
3
|
+
* aggregate hashes into Bitcoin transactions, and the block a proof ends in.
|
|
4
|
+
*
|
|
5
|
+
* Written against the format as the reference implementation serialises it
|
|
6
|
+
* (python-opentimestamps, `core/timestamp.py`, `core/op.py`,
|
|
7
|
+
* `core/notary.py`) rather than through a library: the published JavaScript
|
|
8
|
+
* client carries a Bitcoin library and a dozen transitive dependencies to do
|
|
9
|
+
* what a few hundred lines do here, and none of them is needed to stamp, to
|
|
10
|
+
* upgrade, or to read which block a proof is anchored in.
|
|
11
|
+
*
|
|
12
|
+
* Three acts, and the network is only ever reached through the `fetch` the
|
|
13
|
+
* caller hands in:
|
|
14
|
+
*
|
|
15
|
+
* stampDigest() a sha256 goes to the calendars; a pending proof comes back
|
|
16
|
+
* upgradeProof() the calendars are asked again; a Bitcoin anchor, eventually
|
|
17
|
+
* bitcoinBlockAt() a block explorer gives the time of the anchoring block,
|
|
18
|
+
* and its merkle root is checked against the proof
|
|
19
|
+
*
|
|
20
|
+
* Only the 32 bytes of the hash leave, and a random nonce is appended before
|
|
21
|
+
* they do, so a calendar does not even learn the hash of the file.
|
|
22
|
+
*/
|
|
23
|
+
/** The 31 bytes every detached proof file starts with. */
|
|
24
|
+
export declare const OTS_MAGIC: Uint8Array<ArrayBuffer>;
|
|
25
|
+
declare const OP_SHA1 = 2;
|
|
26
|
+
declare const OP_RIPEMD160 = 3;
|
|
27
|
+
declare const OP_SHA256 = 8;
|
|
28
|
+
declare const OP_APPEND = 240;
|
|
29
|
+
declare const OP_PREPEND = 241;
|
|
30
|
+
declare const OP_REVERSE = 242;
|
|
31
|
+
declare const OP_HEXLIFY = 243;
|
|
32
|
+
export type Op = {
|
|
33
|
+
tag: typeof OP_SHA1 | typeof OP_RIPEMD160 | typeof OP_SHA256 | typeof OP_REVERSE | typeof OP_HEXLIFY;
|
|
34
|
+
} | {
|
|
35
|
+
tag: typeof OP_APPEND | typeof OP_PREPEND;
|
|
36
|
+
arg: Uint8Array;
|
|
37
|
+
};
|
|
38
|
+
export type Attestation = {
|
|
39
|
+
kind: 'pending';
|
|
40
|
+
uri: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'bitcoin';
|
|
43
|
+
height: number;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'unknown';
|
|
46
|
+
tag: Uint8Array;
|
|
47
|
+
payload: Uint8Array;
|
|
48
|
+
};
|
|
49
|
+
/** A message, what is attested about it, and the operations that lead from it. */
|
|
50
|
+
export interface Timestamp {
|
|
51
|
+
msg: Uint8Array;
|
|
52
|
+
attestations: Attestation[];
|
|
53
|
+
ops: {
|
|
54
|
+
op: Op;
|
|
55
|
+
stamp: Timestamp;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
/** A whole `.ots` file: the hash of the file, and the timestamp of that hash. */
|
|
59
|
+
export interface DetachedTimestamp {
|
|
60
|
+
/** sha256 of the file, the only file hash this module writes or reads. */
|
|
61
|
+
digest: Uint8Array;
|
|
62
|
+
timestamp: Timestamp;
|
|
63
|
+
}
|
|
64
|
+
/** Something the bytes or the network said that a proof cannot be built on. */
|
|
65
|
+
export declare class OtsError extends Error {
|
|
66
|
+
name: string;
|
|
67
|
+
readonly code: string;
|
|
68
|
+
constructor(code: string, message: string);
|
|
69
|
+
}
|
|
70
|
+
export declare const toHex: (bytes: Uint8Array) => string;
|
|
71
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
72
|
+
export declare function sha256(bytes: Uint8Array): Uint8Array;
|
|
73
|
+
/** What an operation makes of a message. */
|
|
74
|
+
export declare function applyOp(op: Op, msg: Uint8Array): Uint8Array;
|
|
75
|
+
/** Reads a timestamp whose starting message is `msg`, as a calendar returns one. */
|
|
76
|
+
export declare function readTimestamp(bytes: Uint8Array, msg: Uint8Array): Timestamp;
|
|
77
|
+
/** Writes a timestamp: every item but the last is preceded by 0xff. */
|
|
78
|
+
export declare function writeTimestamp(stamp: Timestamp): Uint8Array;
|
|
79
|
+
/** Reads a whole `.ots` file. */
|
|
80
|
+
export declare function readOts(bytes: Uint8Array): DetachedTimestamp;
|
|
81
|
+
/** Writes a whole `.ots` file. */
|
|
82
|
+
export declare function writeOts(proof: DetachedTimestamp): Uint8Array;
|
|
83
|
+
/** Every attestation of a timestamp, with the message it attests and the node it sits on. */
|
|
84
|
+
export declare function attestationsOf(stamp: Timestamp): {
|
|
85
|
+
msg: Uint8Array;
|
|
86
|
+
attestation: Attestation;
|
|
87
|
+
node: Timestamp;
|
|
88
|
+
}[];
|
|
89
|
+
/** Adds what `other` knows about the same message to `target`. */
|
|
90
|
+
export declare function mergeTimestamp(target: Timestamp, other: Timestamp): void;
|
|
91
|
+
/** The Bitcoin anchors of a proof: the block height, and the merkle root the proof arrives at. */
|
|
92
|
+
export declare function bitcoinAnchors(stamp: Timestamp): {
|
|
93
|
+
height: number;
|
|
94
|
+
merkleRoot: Uint8Array;
|
|
95
|
+
}[];
|
|
96
|
+
/** The calendars a proof still waits on. */
|
|
97
|
+
export declare function pendingCalendars(stamp: Timestamp): string[];
|
|
98
|
+
/** What this module needs of `fetch`, so a test or another runtime can stand in for it. */
|
|
99
|
+
export type ProofFetch = (url: string, init?: {
|
|
100
|
+
method?: string;
|
|
101
|
+
headers?: Record<string, string>;
|
|
102
|
+
body?: Uint8Array;
|
|
103
|
+
}) => Promise<{
|
|
104
|
+
ok: boolean;
|
|
105
|
+
status: number;
|
|
106
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
107
|
+
text(): Promise<string>;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* The public calendars the reference client submits to by default. Four
|
|
111
|
+
* operators, so that a proof does not depend on one of them staying up: a
|
|
112
|
+
* hash is submitted to all of them and the proof keeps every answer.
|
|
113
|
+
*/
|
|
114
|
+
export declare const DEFAULT_CALENDARS: readonly ["https://a.pool.opentimestamps.org", "https://b.pool.opentimestamps.org", "https://a.pool.eternitywall.com", "https://ots.btc.catallaxy.com"];
|
|
115
|
+
/**
|
|
116
|
+
* The calendars the aggregators above hand a proof over to, which are the
|
|
117
|
+
* ones a pending proof names and an upgrade asks. A proof is bytes somebody
|
|
118
|
+
* handed over, so an upgrade dials only calendars it was told to trust; these
|
|
119
|
+
* four by default, as in the reference client.
|
|
120
|
+
*/
|
|
121
|
+
export declare const DEFAULT_UPGRADE_CALENDARS: readonly ["https://alice.btc.calendar.opentimestamps.org", "https://bob.btc.calendar.opentimestamps.org", "https://finney.calendar.eternitywall.com", "https://btc.calendar.catallaxy.com"];
|
|
122
|
+
/** An Esplora block explorer API, which several public explorers serve. */
|
|
123
|
+
export declare const DEFAULT_BITCOIN_EXPLORER = "https://blockstream.info/api";
|
|
124
|
+
export interface StampOptions {
|
|
125
|
+
fetch: ProofFetch;
|
|
126
|
+
calendars?: readonly string[];
|
|
127
|
+
/** How many calendars have to answer. Two by default, or all of them if fewer are given. */
|
|
128
|
+
minimum?: number;
|
|
129
|
+
/** For a test: the 16 bytes appended before submission. Random otherwise. */
|
|
130
|
+
nonce?: Uint8Array;
|
|
131
|
+
}
|
|
132
|
+
export interface Stamped {
|
|
133
|
+
/** The `.ots` file, pending. */
|
|
134
|
+
ots: Uint8Array;
|
|
135
|
+
/** The calendars that answered. */
|
|
136
|
+
calendars: string[];
|
|
137
|
+
/** The calendars that did not, and why. */
|
|
138
|
+
failures: {
|
|
139
|
+
calendar: string;
|
|
140
|
+
reason: string;
|
|
141
|
+
}[];
|
|
142
|
+
}
|
|
143
|
+
/** Submits the sha256 of a file to the calendars, and returns the pending proof. */
|
|
144
|
+
export declare function stampDigest(digest: Uint8Array, options: StampOptions): Promise<Stamped>;
|
|
145
|
+
export interface UpgradeOptions {
|
|
146
|
+
fetch: ProofFetch;
|
|
147
|
+
/**
|
|
148
|
+
* The calendars this client agrees to ask. A proof names the calendar it
|
|
149
|
+
* waits on, and a proof is bytes somebody handed over: a calendar outside
|
|
150
|
+
* this list is not dialled. `DEFAULT_UPGRADE_CALENDARS` when left out.
|
|
151
|
+
*/
|
|
152
|
+
calendars?: readonly string[];
|
|
153
|
+
}
|
|
154
|
+
export interface Upgraded {
|
|
155
|
+
ots: Uint8Array;
|
|
156
|
+
/** Whether the calendars added anything. */
|
|
157
|
+
changed: boolean;
|
|
158
|
+
/** The lowest Bitcoin block the proof is now anchored in, if any. */
|
|
159
|
+
bitcoin: {
|
|
160
|
+
height: number;
|
|
161
|
+
merkleRoot: Uint8Array;
|
|
162
|
+
} | undefined;
|
|
163
|
+
/** The calendars still waiting for a block. */
|
|
164
|
+
pending: string[];
|
|
165
|
+
}
|
|
166
|
+
/** Asks each calendar a proof waits on whether its commitment is in a block yet. */
|
|
167
|
+
export declare function upgradeProof(ots: Uint8Array, options: UpgradeOptions): Promise<Upgraded>;
|
|
168
|
+
export interface BitcoinBlock {
|
|
169
|
+
height: number;
|
|
170
|
+
hash: string;
|
|
171
|
+
/** The time in the block header, ISO 8601. */
|
|
172
|
+
time: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The block at a height, read from an Esplora explorer, with its merkle root
|
|
176
|
+
* checked against the one the proof arrives at. A proof whose path does not
|
|
177
|
+
* end in the merkle root of that block is not a proof of anything, and is
|
|
178
|
+
* refused rather than dated.
|
|
179
|
+
*/
|
|
180
|
+
export declare function bitcoinBlockAt(height: number, merkleRoot: Uint8Array, options: {
|
|
181
|
+
fetch: ProofFetch;
|
|
182
|
+
explorer?: string;
|
|
183
|
+
}): Promise<BitcoinBlock>;
|
|
184
|
+
export {};
|
|
185
|
+
//# sourceMappingURL=opentimestamps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentimestamps.d.ts","sourceRoot":"","sources":["../../src/proofs/opentimestamps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,0DAA0D;AAC1D,eAAO,MAAM,SAAS,yBAGpB,CAAC;AAGH,QAAA,MAAM,OAAO,IAAO,CAAC;AACrB,QAAA,MAAM,YAAY,IAAO,CAAC;AAC1B,QAAA,MAAM,SAAS,IAAO,CAAC;AAEvB,QAAA,MAAM,SAAS,MAAO,CAAC;AACvB,QAAA,MAAM,UAAU,MAAO,CAAC;AACxB,QAAA,MAAM,UAAU,MAAO,CAAC;AACxB,QAAA,MAAM,UAAU,MAAO,CAAC;AAUxB,MAAM,MAAM,EAAE,GACV;IAAE,GAAG,EAAE,OAAO,OAAO,GAAG,O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