@plane31/blind-relay 0.0.0-stage → 0.1.1
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 +202 -0
- package/README.md +26 -2
- package/dist/adapters/index.d.ts +18 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +22 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/audience.d.ts +77 -0
- package/dist/audience.d.ts.map +1 -0
- package/dist/audience.js +76 -0
- package/dist/audience.js.map +1 -0
- package/dist/bytes.d.ts +54 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +200 -0
- package/dist/bytes.js.map +1 -0
- package/dist/circle.d.ts +59 -0
- package/dist/circle.d.ts.map +1 -0
- package/dist/circle.js +105 -0
- package/dist/circle.js.map +1 -0
- package/dist/client.d.ts +234 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1365 -0
- package/dist/client.js.map +1 -0
- package/dist/codec.d.ts +189 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +512 -0
- package/dist/codec.js.map +1 -0
- package/dist/crypto/backend.d.ts +39 -0
- package/dist/crypto/backend.d.ts.map +1 -0
- package/dist/crypto/backend.js +8 -0
- package/dist/crypto/backend.js.map +1 -0
- package/dist/crypto/noble.d.ts +3 -0
- package/dist/crypto/noble.d.ts.map +1 -0
- package/dist/crypto/noble.js +107 -0
- package/dist/crypto/noble.js.map +1 -0
- package/dist/crypto/sodium.d.ts +7 -0
- package/dist/crypto/sodium.d.ts.map +1 -0
- package/dist/crypto/sodium.js +39 -0
- package/dist/crypto/sodium.js.map +1 -0
- package/dist/crypto.d.ts +66 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +225 -0
- package/dist/crypto.js.map +1 -0
- package/dist/epoch.d.ts +93 -0
- package/dist/epoch.d.ts.map +1 -0
- package/dist/epoch.js +121 -0
- package/dist/epoch.js.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +30 -0
- package/dist/errors.js.map +1 -0
- package/dist/historyIndex.d.ts +15 -0
- package/dist/historyIndex.d.ts.map +1 -0
- package/dist/historyIndex.js +57 -0
- package/dist/historyIndex.js.map +1 -0
- package/dist/identity.d.ts +62 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +99 -0
- package/dist/identity.js.map +1 -0
- package/dist/inbox.d.ts +153 -0
- package/dist/inbox.d.ts.map +1 -0
- package/dist/inbox.js +472 -0
- package/dist/inbox.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/outbox.d.ts +96 -0
- package/dist/outbox.d.ts.map +1 -0
- package/dist/outbox.js +339 -0
- package/dist/outbox.js.map +1 -0
- package/dist/policy.d.ts +33 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +71 -0
- package/dist/policy.js.map +1 -0
- package/dist/record.d.ts +49 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +46 -0
- package/dist/record.js.map +1 -0
- package/dist/reset.d.ts +74 -0
- package/dist/reset.d.ts.map +1 -0
- package/dist/reset.js +127 -0
- package/dist/reset.js.map +1 -0
- package/dist/rows.d.ts +16 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +103 -0
- package/dist/rows.js.map +1 -0
- package/dist/slots.d.ts +22 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +38 -0
- package/dist/slots.js.map +1 -0
- package/dist/store.d.ts +357 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +192 -0
- package/dist/store.js.map +1 -0
- package/dist/testing/clock.d.ts +14 -0
- package/dist/testing/clock.d.ts.map +1 -0
- package/dist/testing/clock.js +27 -0
- package/dist/testing/clock.js.map +1 -0
- package/dist/testing/fakeHost.d.ts +118 -0
- package/dist/testing/fakeHost.d.ts.map +1 -0
- package/dist/testing/fakeHost.js +462 -0
- package/dist/testing/fakeHost.js.map +1 -0
- package/dist/testing/faults.d.ts +97 -0
- package/dist/testing/faults.d.ts.map +1 -0
- package/dist/testing/faults.js +264 -0
- package/dist/testing/faults.js.map +1 -0
- package/dist/testing/fixtures.d.ts +15 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +22 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/providers.d.ts +16 -0
- package/dist/testing/providers.d.ts.map +1 -0
- package/dist/testing/providers.js +36 -0
- package/dist/testing/providers.js.map +1 -0
- package/dist/testing/sweep.d.ts +46 -0
- package/dist/testing/sweep.d.ts.map +1 -0
- package/dist/testing/sweep.js +366 -0
- package/dist/testing/sweep.js.map +1 -0
- package/dist/transactions.d.ts +75 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.js +212 -0
- package/dist/transactions.js.map +1 -0
- package/dist/transport.d.ts +125 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +6 -0
- package/dist/transport.js.map +1 -0
- package/dist/vault.d.ts +59 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +69 -0
- package/dist/vault.js.map +1 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @plane31/blind-relay
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Kavach v1 protocol in pure TypeScript: end-to-end encrypted, relayed, durable records between a person's devices and the devices of the people they share with, for circles of up to 100 accounts, through a server that stores only what it cannot open and deletes each record once every reader has it. The package is product-agnostic: a product declares its record kinds and keeps its payload codecs in its own profile. The specification is `spec/Kavach-v1.md` in the repository; `spec/Profile-template.md` lists what a product decides.
|
|
4
|
+
|
|
5
|
+
Status: protocol revision 8, package 0.x. The primitives are audited libraries; the composition is not yet independently reviewed, and nothing here is production-ready. The API may change between 0.x minor versions; the protocol revision is tracked separately in the specification.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pnpm add @plane31/blind-relay
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Entry points
|
|
12
|
+
|
|
13
|
+
- `@plane31/blind-relay`: `open` and the `Client` with `enqueue`, `newest`, `historyPage`, `sync`, the circles API, `subscribe` and `inspect`; the `KindDeclaration` and `RetentionPolicy` a product passes to `open`; `KavachError` and `ErrorCode`; the `RecoveryProvider` contract; `toHex`, `fromHex` and `equalBytes`.
|
|
14
|
+
- `@plane31/blind-relay/adapters`: the `Store`, `Tx`, `SecretStore`, `Transport`, `Directory` and `Relay` contracts an adapter or host implements, with the table and row types; `MemoryStore` and `MemorySecretStore` as the behavioural reference; the signed-document codec a host verifies with; `buildResetKeyList` and `buildResetReceipt` for a host's key tooling.
|
|
15
|
+
- `@plane31/blind-relay/testing`: the fault harness (a fake host, a crashing store, a malicious transport, the crash and lost-response sweeps) and the fixtures a test builds protocol state with.
|
|
16
|
+
- `@plane31/blind-relay/sodium`: the optional libsodium backend for Node; the default backend is portable JavaScript, which is what Hermes needs.
|
|
17
|
+
|
|
18
|
+
Randomness comes from the Web Crypto global. A runtime without one (Hermes) installs it first; `@plane31/blind-relay-expo` does that from `expo-crypto`.
|
|
19
|
+
|
|
20
|
+
## Development
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
pnpm install
|
|
24
|
+
pnpm typecheck && pnpm lint && pnpm test
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The test suite runs under both cipher-suite backends and against the frozen conformance vectors. Apache-2.0.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plane31/blind-relay/adapters: the contracts an adapter or host author implements, and what their
|
|
3
|
+
* tests need to drive them. Applications import `@plane31/blind-relay` instead.
|
|
4
|
+
*
|
|
5
|
+
* A `Store` and `SecretStore` adapter implements the row tables and the transaction interface;
|
|
6
|
+
* a `Transport` adapter implements the directory and relay calls; a `RecoveryProvider` keeps
|
|
7
|
+
* the recovery key with the platform; a host parses and verifies the signed documents the
|
|
8
|
+
* transport carries. The in-memory implementations are the behavioural reference.
|
|
9
|
+
*/
|
|
10
|
+
export { Reader, Writer, compareBytes, concat, equalBytes, fromHex, toHex, u16, u32, u64 } from "../bytes.js";
|
|
11
|
+
export { bodyHash, identityId, randomBytes, ready, recordId, signingKeypairFromSeed, streamId, type SigningKeypair } from "../crypto.js";
|
|
12
|
+
export { KavachError, isKavachError, type ErrorCode } from "../errors.js";
|
|
13
|
+
export { DocumentType, buildResetKeyList, buildResetReceipt, expectType, parseDocument, parseVaultHeader, verifyDocument, type AccountDevice, type AccountResetReceipt, type CircleSnapshot, type EncryptedRecord, type EpochManifest, type Parsed, type ResetKeyEntry, type ResetKeyList, type SignedDocument, type VaultHeader } from "../codec.js";
|
|
14
|
+
export { MemorySecretStore, MemoryStore, invokeSync, type ActivationRow, type CertificateRow, type CircleRow, type ClockRow, type EpochRow, type EpochStatus, type HistoryRow, type NewestRow, type MemoryStoreOptions, type MetaRow, type OutboxRow, type OutboxStatus, type EnqueueKeyRow, type HistoryIndexRow, type KeyRange, inKeyRange, type PendingResetRow, type PinRow, type QuarantineRow, type ReaderEpochRow, type ResetListRow, type ResetReceiptRow, type RevisionRow, type SecretName, type SecretStore, type SelfRow, type Store, type StoreState, type StreamRow, type SubscriptionRow, type TableName, type Tables, type Tx, type UnresolvedRow, type VaultRow } from "../store.js";
|
|
15
|
+
export type { AppendOutcome, AppendStatus, Directory, EpochBundle, JoinRequest, MutationOutcome, MutationStatus, ReadRecordsResult, Relay, ResolvedAccount, Transport } from "../transport.js";
|
|
16
|
+
export type { BackupState, ProviderLoadResult, ProviderSaveResult, ProviderStatus, ProviderStatusResult, RecoveryProvider } from "../vault.js";
|
|
17
|
+
export { openStore, t1Activate, t1Header, t1Secrets, t3ApplyChange, type ChangeResult, type OpenedState } from "../transactions.js";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAG9G,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAGzI,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,EAAE,EACP,KAAK,aAAa,EAClB,KAAK,QAAQ,EACd,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,WAAW,EACX,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,SAAS,EACV,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/I,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plane31/blind-relay/adapters: the contracts an adapter or host author implements, and what their
|
|
3
|
+
* tests need to drive them. Applications import `@plane31/blind-relay` instead.
|
|
4
|
+
*
|
|
5
|
+
* A `Store` and `SecretStore` adapter implements the row tables and the transaction interface;
|
|
6
|
+
* a `Transport` adapter implements the directory and relay calls; a `RecoveryProvider` keeps
|
|
7
|
+
* the recovery key with the platform; a host parses and verifies the signed documents the
|
|
8
|
+
* transport carries. The in-memory implementations are the behavioural reference.
|
|
9
|
+
*/
|
|
10
|
+
// Bytes --------------------------------------------------------------------------------------------
|
|
11
|
+
export { Reader, Writer, compareBytes, concat, equalBytes, fromHex, toHex, u16, u32, u64 } from "../bytes.js";
|
|
12
|
+
// Cipher suite: readiness, randomness and the identifiers a host derives --------------------------
|
|
13
|
+
export { bodyHash, identityId, randomBytes, ready, recordId, signingKeypairFromSeed, streamId } from "../crypto.js";
|
|
14
|
+
// Errors -------------------------------------------------------------------------------------------
|
|
15
|
+
export { KavachError, isKavachError } from "../errors.js";
|
|
16
|
+
// Signed documents, as a host or transport sees them ----------------------------------------------
|
|
17
|
+
export { DocumentType, buildResetKeyList, buildResetReceipt, expectType, parseDocument, parseVaultHeader, verifyDocument } from "../codec.js";
|
|
18
|
+
// Store --------------------------------------------------------------------------------------------
|
|
19
|
+
export { MemorySecretStore, MemoryStore, invokeSync, inKeyRange } from "../store.js";
|
|
20
|
+
// The transactions an adapter test drives against a store -----------------------------------------
|
|
21
|
+
export { openStore, t1Activate, t1Header, t1Secrets, t3ApplyChange } from "../transactions.js";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,qGAAqG;AACrG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAE9G,oGAAoG;AACpG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,QAAQ,EAAuB,MAAM,cAAc,CAAC;AAEzI,qGAAqG;AACrG,OAAO,EAAE,WAAW,EAAE,aAAa,EAAkB,MAAM,cAAc,CAAC;AAE1E,oGAAoG;AACpG,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,cAAc,EAWf,MAAM,aAAa,CAAC;AAErB,qGAAqG;AACrG,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,UAAU,EAgBV,UAAU,EAoBX,MAAM,aAAa,CAAC;AAoBrB,oGAAoG;AACpG,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAuC,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { CircleState } from "./circle.js";
|
|
2
|
+
import type { AccountPin } from "./identity.js";
|
|
3
|
+
export declare const MAX_AUDIENCE = 100;
|
|
4
|
+
export interface AudienceEntry {
|
|
5
|
+
readonly identityId: Uint8Array;
|
|
6
|
+
readonly certificateHash: Uint8Array;
|
|
7
|
+
readonly boxKey: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export interface ResolvedAudience {
|
|
10
|
+
/** Sorted by identity id, self included. */
|
|
11
|
+
readonly rows: readonly AudienceEntry[];
|
|
12
|
+
/** Rows other than self. */
|
|
13
|
+
readonly recipientCount: number;
|
|
14
|
+
/** A digest-friendly description of the exact certificate-bound audience. */
|
|
15
|
+
readonly key: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function isEligible(circle: CircleState, selfIdentityId: Uint8Array): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Self plus every member of every eligible circle, each at its current certificate. Anything
|
|
20
|
+
* missing is `METADATA_REQUIRED`; more than 100 distinct accounts is `RECIPIENT_LIMIT`. The
|
|
21
|
+
* author never guesses, omits a recipient or reuses an obsolete key.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveAudience(self: AccountPin, circles: readonly CircleState[], pins: ReadonlyMap<string, AccountPin>, retired?: ReadonlySet<string>): ResolvedAudience;
|
|
24
|
+
export type AudienceEvent = {
|
|
25
|
+
readonly kind: "snapshot";
|
|
26
|
+
readonly circleId: Uint8Array;
|
|
27
|
+
readonly revision: bigint;
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: "deviceChanged";
|
|
30
|
+
readonly identityId: Uint8Array;
|
|
31
|
+
readonly certificateHash: Uint8Array;
|
|
32
|
+
} | {
|
|
33
|
+
readonly kind: "ownActivation";
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "join";
|
|
36
|
+
readonly circleId: Uint8Array;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "leave";
|
|
39
|
+
readonly circleId: Uint8Array;
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: "enable";
|
|
42
|
+
readonly circleId: Uint8Array;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "disable";
|
|
45
|
+
readonly circleId: Uint8Array;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "counterExhausted";
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: "hygiene";
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "clockReversal";
|
|
52
|
+
};
|
|
53
|
+
export interface RevisionState {
|
|
54
|
+
readonly desiredRevision: bigint;
|
|
55
|
+
/** Highest snapshot revision processed per circle, so reprocessing does not increment. */
|
|
56
|
+
readonly seenSnapshots: ReadonlyMap<string, bigint>;
|
|
57
|
+
/** Certificate hash last accepted per recipient, so a replayed certificate does not increment. */
|
|
58
|
+
readonly seenCertificates: ReadonlyMap<string, string>;
|
|
59
|
+
}
|
|
60
|
+
export declare const initialRevisionState: RevisionState;
|
|
61
|
+
export interface Invalidation {
|
|
62
|
+
/** The active epoch is no longer usable; allocated counters are burned. */
|
|
63
|
+
readonly clearActiveEpoch: true;
|
|
64
|
+
/** Outbox rows sealed under the obsolete revision and not yet handed off are cancelled. */
|
|
65
|
+
readonly cancelObsoleteOutbox: true;
|
|
66
|
+
readonly paused: "rotation";
|
|
67
|
+
}
|
|
68
|
+
export declare const INVALIDATION: Invalidation;
|
|
69
|
+
/**
|
|
70
|
+
* Apply one event. Returns the new state and whether the desired revision moved. Every move
|
|
71
|
+
* is a rotation: the caller performs the invalidation in the same transaction (T3).
|
|
72
|
+
*/
|
|
73
|
+
export declare function applyAudienceEvent(state: RevisionState, event: AudienceEvent): {
|
|
74
|
+
state: RevisionState;
|
|
75
|
+
changed: boolean;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=audience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audience.d.ts","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,SAAS,aAAa,EAAE,CAAC;IACxC,4BAA4B;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,GAAG,OAAO,CAOnF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW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gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxD;AAED,eAAO,MAAM,oBAAoB,EAAE,aAA8F,CAAC;AAElI,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC;IAChC,2FAA2F;IAC3F,QAAQ,CAAC,oBAAoB,EAAE,IAAI,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B;AAED,eAAO,MAAM,YAAY,EAAE,YAAyF,CAAC;AAErH;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAyBzH"}
|
package/dist/audience.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audience resolution and the desired revision (protocol section 7).
|
|
3
|
+
*/
|
|
4
|
+
import { compareBytes, equalBytes, toHex } from "./bytes.js";
|
|
5
|
+
import { KavachError } from "./errors.js";
|
|
6
|
+
export const MAX_AUDIENCE = 100;
|
|
7
|
+
export function isEligible(circle, selfIdentityId) {
|
|
8
|
+
return (circle.status === "member" &&
|
|
9
|
+
circle.enabled &&
|
|
10
|
+
circle.revision > 0n &&
|
|
11
|
+
circle.members.some((m) => equalBytes(m, selfIdentityId)));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Self plus every member of every eligible circle, each at its current certificate. Anything
|
|
15
|
+
* missing is `METADATA_REQUIRED`; more than 100 distinct accounts is `RECIPIENT_LIMIT`. The
|
|
16
|
+
* author never guesses, omits a recipient or reuses an obsolete key.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveAudience(self, circles, pins, retired = new Set()) {
|
|
19
|
+
const stage = "resolveAudience";
|
|
20
|
+
const wanted = new Map();
|
|
21
|
+
wanted.set(toHex(self.identityId), self.identityId);
|
|
22
|
+
for (const c of circles) {
|
|
23
|
+
if (!isEligible(c, self.identityId))
|
|
24
|
+
continue;
|
|
25
|
+
// An identity retired by a validated reset receipt is no longer a recipient.
|
|
26
|
+
for (const m of c.members)
|
|
27
|
+
if (!retired.has(toHex(m)))
|
|
28
|
+
wanted.set(toHex(m), m);
|
|
29
|
+
}
|
|
30
|
+
if (wanted.size > MAX_AUDIENCE)
|
|
31
|
+
throw new KavachError("RECIPIENT_LIMIT", stage, `${wanted.size} accounts`);
|
|
32
|
+
const rows = [];
|
|
33
|
+
for (const [hex, iid] of wanted) {
|
|
34
|
+
const pin = hex === toHex(self.identityId) ? self : pins.get(hex);
|
|
35
|
+
if (!pin)
|
|
36
|
+
throw new KavachError("METADATA_REQUIRED", stage, "no certificate for a member");
|
|
37
|
+
rows.push({ identityId: iid, certificateHash: pin.certificateHash, boxKey: pin.boxKey });
|
|
38
|
+
}
|
|
39
|
+
rows.sort((a, b) => compareBytes(a.identityId, b.identityId));
|
|
40
|
+
return { rows, recipientCount: rows.length - 1, key: rows.map((r) => toHex(r.identityId) + ":" + toHex(r.certificateHash)).join(",") };
|
|
41
|
+
}
|
|
42
|
+
export const initialRevisionState = { desiredRevision: 1n, seenSnapshots: new Map(), seenCertificates: new Map() };
|
|
43
|
+
export const INVALIDATION = { clearActiveEpoch: true, cancelObsoleteOutbox: true, paused: "rotation" };
|
|
44
|
+
/**
|
|
45
|
+
* Apply one event. Returns the new state and whether the desired revision moved. Every move
|
|
46
|
+
* is a rotation: the caller performs the invalidation in the same transaction (T3).
|
|
47
|
+
*/
|
|
48
|
+
export function applyAudienceEvent(state, event) {
|
|
49
|
+
const bump = (extra) => ({
|
|
50
|
+
state: { ...state, ...extra, desiredRevision: state.desiredRevision + 1n },
|
|
51
|
+
changed: true
|
|
52
|
+
});
|
|
53
|
+
switch (event.kind) {
|
|
54
|
+
case "snapshot": {
|
|
55
|
+
const key = toHex(event.circleId);
|
|
56
|
+
const seen = state.seenSnapshots.get(key) ?? 0n;
|
|
57
|
+
if (event.revision <= seen)
|
|
58
|
+
return { state, changed: false };
|
|
59
|
+
const seenSnapshots = new Map(state.seenSnapshots);
|
|
60
|
+
seenSnapshots.set(key, event.revision);
|
|
61
|
+
return bump({ seenSnapshots });
|
|
62
|
+
}
|
|
63
|
+
case "deviceChanged": {
|
|
64
|
+
const key = toHex(event.identityId);
|
|
65
|
+
const hash = toHex(event.certificateHash);
|
|
66
|
+
if (state.seenCertificates.get(key) === hash)
|
|
67
|
+
return { state, changed: false };
|
|
68
|
+
const seenCertificates = new Map(state.seenCertificates);
|
|
69
|
+
seenCertificates.set(key, hash);
|
|
70
|
+
return bump({ seenCertificates });
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
return bump();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=audience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audience.js","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAiBhC,MAAM,UAAU,UAAU,CAAC,MAAmB,EAAE,cAA0B;IACxE,OAAO,CACL,MAAM,CAAC,MAAM,KAAK,QAAQ;QAC1B,MAAM,CAAC,OAAO;QACd,MAAM,CAAC,QAAQ,GAAG,EAAE;QACpB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,OAA+B,EAAE,IAAqC,EAAE,UAA+B,IAAI,GAAG,EAAE;IAChK,MAAM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Q,IAAI,IAAI;gBAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;YAC7D,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACnD,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvC,OAAO,IAAI,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YAC1C,IAAI,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI;gBAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;YAC/E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACzD,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACpC,CAAC;QACD;YACE,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const MAX_DOCUMENT_BYTES = 16384;
|
|
2
|
+
export declare const MAX_PAYLOAD_BYTES = 4096;
|
|
3
|
+
export declare function concat(...parts: readonly Uint8Array[]): Uint8Array;
|
|
4
|
+
export declare function u8(value: number): Uint8Array;
|
|
5
|
+
export declare function u16(value: number): Uint8Array;
|
|
6
|
+
export declare function u32(value: number): Uint8Array;
|
|
7
|
+
export declare function u64(value: bigint): Uint8Array;
|
|
8
|
+
export declare function i32(value: number): Uint8Array;
|
|
9
|
+
/** The `accountName` rule: 1 to 64 ASCII letters, digits, underscore or hyphen, case-sensitive. */
|
|
10
|
+
export declare function isValidName(name: string): boolean;
|
|
11
|
+
/** `B(name)`: u8 byte length followed by the ASCII bytes. */
|
|
12
|
+
export declare function encodeName(name: string): Uint8Array;
|
|
13
|
+
export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
14
|
+
export declare function isAllZero(bytes: Uint8Array): boolean;
|
|
15
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
16
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
17
|
+
/** Compare two byte strings lexicographically, as the strict sort orders in section 3 require. */
|
|
18
|
+
export declare function compareBytes(a: Uint8Array, b: Uint8Array): number;
|
|
19
|
+
/**
|
|
20
|
+
* A bounded reader. Every take is checked against the end; `end()` refuses trailing bytes.
|
|
21
|
+
* All failures are `MALFORMED`, which is what the codec reports before any cryptography.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Reader {
|
|
24
|
+
private readonly data;
|
|
25
|
+
private readonly stage;
|
|
26
|
+
private offset;
|
|
27
|
+
constructor(data: Uint8Array, stage?: string);
|
|
28
|
+
get position(): number;
|
|
29
|
+
get remaining(): number;
|
|
30
|
+
take(n: number): Uint8Array;
|
|
31
|
+
u8(): number;
|
|
32
|
+
u16(): number;
|
|
33
|
+
u32(): number;
|
|
34
|
+
u64(): bigint;
|
|
35
|
+
i32(): number;
|
|
36
|
+
/** `B(name)`, enforcing the name rule. */
|
|
37
|
+
name(): string;
|
|
38
|
+
/** The bytes consumed so far, for AAD and body hashing. */
|
|
39
|
+
consumed(): Uint8Array;
|
|
40
|
+
end(): void;
|
|
41
|
+
}
|
|
42
|
+
/** An append-only writer for building bodies. */
|
|
43
|
+
export declare class Writer {
|
|
44
|
+
private readonly parts;
|
|
45
|
+
bytes(value: Uint8Array): this;
|
|
46
|
+
u8(value: number): this;
|
|
47
|
+
u16(value: number): this;
|
|
48
|
+
u32(value: number): this;
|
|
49
|
+
u64(value: bigint): this;
|
|
50
|
+
i32(value: number): this;
|
|
51
|
+
name(value: string): this;
|
|
52
|
+
finish(): Uint8Array;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AAKvC,wBAAgB,MAAM,CAAC,GAAG,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAUlE;AAED,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAG5C;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAG7C;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAK7C;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAK7C;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAK7C;AAED,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAKnD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAKhE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAIpD;AAID,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI/C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAK/C;AAED,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAA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