@peerbit/trusted-network 6.0.130 → 6.0.131
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/dist/src/v2-authority-entry.d.ts +34 -2
- package/dist/src/v2-authority-entry.d.ts.map +1 -1
- package/dist/src/v2-authority-entry.js +184 -85
- package/dist/src/v2-authority-entry.js.map +1 -1
- package/dist/src/v2-resource-fence-entry.d.ts.map +1 -1
- package/dist/src/v2-resource-fence-entry.js +7 -60
- package/dist/src/v2-resource-fence-entry.js.map +1 -1
- package/package.json +11 -7
- package/src/v2-authority-entry.ts +281 -111
- package/src/v2-resource-fence-entry.ts +8 -84
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type SignatureWithKey } from "@peerbit/crypto";
|
|
2
|
+
import { EntryV0, type Meta } from "@peerbit/log";
|
|
2
3
|
import { NetworkDescriptorV2 } from "./v2.js";
|
|
4
|
+
export declare const TRUSTED_NETWORK_V2_MAX_CANONICAL_ENTRY_CID_CHARACTERS = 128;
|
|
5
|
+
export type CanonicalPublicEntryV0ScanLimitsV2 = Readonly<{
|
|
6
|
+
label: string;
|
|
7
|
+
minimumSignatures: number;
|
|
8
|
+
maximumSignatures: number;
|
|
9
|
+
maximumDirectParents?: number;
|
|
10
|
+
maximumMetadataBytes?: number;
|
|
11
|
+
}>;
|
|
12
|
+
export type CanonicalPublicEntryV0ScanV2 = Readonly<{
|
|
13
|
+
entry: EntryV0<Uint8Array>;
|
|
14
|
+
meta: Meta;
|
|
15
|
+
signatures: SignatureWithKey[];
|
|
16
|
+
metaBytes: Uint8Array;
|
|
17
|
+
payloadBytes: Uint8Array;
|
|
18
|
+
signableBytes: Uint8Array;
|
|
19
|
+
reservedBytes: Uint8Array;
|
|
20
|
+
hasHash: boolean;
|
|
21
|
+
directParentCount: number;
|
|
22
|
+
signatureCount: number;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Bounds-scans and canonically decodes one already-captured public EntryV0.
|
|
26
|
+
* Record meaning, signer authority, reserved bytes, hash option, and causal
|
|
27
|
+
* semantics remain the responsibility of the caller's domain profile.
|
|
28
|
+
*/
|
|
29
|
+
export declare const scanCanonicalPublicEntryV0V2: (entryBytes: Uint8Array, limits: CanonicalPublicEntryV0ScanLimitsV2) => CanonicalPublicEntryV0ScanV2;
|
|
30
|
+
export declare const assertCanonicalSecp256k1SignatureV2: (signature: Uint8Array, label: string) => void;
|
|
31
|
+
export declare const canonicalDirectParentsV2: (parents: readonly string[], label: string) => Array<{
|
|
32
|
+
cid: string;
|
|
33
|
+
digest: Uint8Array;
|
|
34
|
+
}>;
|
|
3
35
|
export type AuthenticatedAuthorityEntryV0V2 = {
|
|
4
36
|
descriptor: NetworkDescriptorV2;
|
|
5
37
|
entryBytes: Uint8Array;
|
|
6
|
-
entry:
|
|
38
|
+
entry: CanonicalPublicEntryV0ScanV2["entry"];
|
|
7
39
|
metaBytes: Uint8Array;
|
|
8
40
|
payloadBytes: Uint8Array;
|
|
9
41
|
reservedBytes: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2-authority-entry.d.ts","sourceRoot":"","sources":["../../src/v2-authority-entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"v2-authority-entry.d.ts","sourceRoot":"","sources":["../../src/v2-authority-entry.ts"],"names":[],"mappings":"AAOA,OAAO,EAAkB,KAAK,gBAAgB,EAAU,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAS,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,cAAc,CAAC;AAEtE,OAAO,EACN,mBAAmB,EAInB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,qDAAqD,MAAM,CAAC;AAEzE,MAAM,MAAM,kCAAkC,GAAG,QAAQ,CAAC;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1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I,CAAC;AAQV,eAAO,MAAM,8BAA8B,GAC1C,YAAY,UAAU,EACtB,mBAAmB,MAAM,KACvB,UAcF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,GAClD,oBAAoB,UAAU,EAC9B,YAAY,mBAAmB,EAC/B,gBAAgB,yBAAyB,KACvC,OAAO,CAAC,+BAA+B,CA0CzC,CAAC;AAEF,eAAO,MAAM,8BAA8B,GAC1C,YAAY,UAAU,EACtB,YAAY,mBAAmB,EAC/B,mBAAmB,MAAM,EACzB,gBAAgB,yBAAyB,KACvC,OAAO,CAAC,+BAA+B,CAKxC,CAAC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { deserialize, serialize } from "@dao-xyz/borsh";
|
|
2
|
+
import { cidifyString, codecMap, defaultHasher, stringifyCid, } from "@peerbit/blocks-interface";
|
|
2
3
|
import { DecryptedThing, verify } from "@peerbit/crypto";
|
|
3
4
|
import { Entry, EntryV0, NO_ENCODING } from "@peerbit/log";
|
|
4
5
|
import { equals } from "uint8arrays";
|
|
5
6
|
import { NetworkDescriptorV2, assertNetworkDescriptorV2, copyUint8ArrayWithLengthV2, exactUint8ArrayByteLengthV2, } from "./v2.js";
|
|
7
|
+
export const TRUSTED_NETWORK_V2_MAX_CANONICAL_ENTRY_CID_CHARACTERS = 128;
|
|
6
8
|
class BoundsReaderV2 {
|
|
7
9
|
bytes;
|
|
10
|
+
label;
|
|
8
11
|
offset = 0;
|
|
9
12
|
view;
|
|
10
|
-
constructor(bytes) {
|
|
13
|
+
constructor(bytes, label) {
|
|
11
14
|
this.bytes = bytes;
|
|
15
|
+
this.label = label;
|
|
12
16
|
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
13
17
|
}
|
|
14
18
|
get position() {
|
|
@@ -17,51 +21,51 @@ class BoundsReaderV2 {
|
|
|
17
21
|
get remaining() {
|
|
18
22
|
return this.bytes.byteLength - this.offset;
|
|
19
23
|
}
|
|
20
|
-
readU8(
|
|
21
|
-
return this.readExact(1,
|
|
24
|
+
readU8(field) {
|
|
25
|
+
return this.readExact(1, field)[0];
|
|
22
26
|
}
|
|
23
|
-
readU32(
|
|
24
|
-
this.requireRemaining(4,
|
|
27
|
+
readU32(field) {
|
|
28
|
+
this.requireRemaining(4, field);
|
|
25
29
|
const value = this.view.getUint32(this.offset, true);
|
|
26
30
|
this.offset += 4;
|
|
27
31
|
return value;
|
|
28
32
|
}
|
|
29
|
-
readBytes(
|
|
30
|
-
return this.readExact(this.readU32(`${
|
|
33
|
+
readBytes(field) {
|
|
34
|
+
return this.readExact(this.readU32(`${field} length`), field);
|
|
31
35
|
}
|
|
32
|
-
readExact(byteLength,
|
|
33
|
-
this.requireRemaining(byteLength,
|
|
36
|
+
readExact(byteLength, field) {
|
|
37
|
+
this.requireRemaining(byteLength, field);
|
|
34
38
|
const start = this.offset;
|
|
35
39
|
this.offset += byteLength;
|
|
36
40
|
return this.bytes.subarray(start, this.offset);
|
|
37
41
|
}
|
|
38
|
-
expectU8(expected,
|
|
39
|
-
if (this.readU8(
|
|
40
|
-
throw new Error(
|
|
42
|
+
expectU8(expected, field) {
|
|
43
|
+
if (this.readU8(field) !== expected) {
|
|
44
|
+
throw new Error(`${this.label} EntryV0 has invalid ${field}`);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
|
-
expectDone(
|
|
47
|
+
expectDone(field) {
|
|
44
48
|
if (this.offset !== this.bytes.byteLength) {
|
|
45
|
-
throw new Error(
|
|
49
|
+
throw new Error(`${this.label} EntryV0 has trailing ${field} bytes`);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
requireRemaining(byteLength,
|
|
52
|
+
requireRemaining(byteLength, field) {
|
|
49
53
|
if (!Number.isSafeInteger(byteLength) ||
|
|
50
54
|
byteLength < 0 ||
|
|
51
55
|
byteLength > this.bytes.byteLength - this.offset) {
|
|
52
|
-
throw new Error(
|
|
56
|
+
throw new Error(`${this.label} EntryV0 has truncated ${field}`);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
const readPublicWrapperV2 = (reader, label) => {
|
|
57
|
-
if (reader.readU8(`${
|
|
58
|
-
reader.readU8(`${
|
|
59
|
-
throw new Error(
|
|
60
|
+
const readPublicWrapperV2 = (reader, label, field) => {
|
|
61
|
+
if (reader.readU8(`${field} MaybeEncrypted variant`) !== 0 ||
|
|
62
|
+
reader.readU8(`${field} DecryptedThing variant`) !== 0) {
|
|
63
|
+
throw new Error(`${label} EntryV0 ${field} must be public`);
|
|
60
64
|
}
|
|
61
|
-
return reader.readBytes(
|
|
65
|
+
return reader.readBytes(field);
|
|
62
66
|
};
|
|
63
|
-
const
|
|
64
|
-
const reader = new BoundsReaderV2(
|
|
67
|
+
const scanMetaV2 = (bytes, limits) => {
|
|
68
|
+
const reader = new BoundsReaderV2(bytes, limits.label);
|
|
65
69
|
reader.expectU8(0, "metadata variant");
|
|
66
70
|
reader.expectU8(0, "clock variant");
|
|
67
71
|
reader.readBytes("clock id");
|
|
@@ -69,83 +73,198 @@ const scanMetaStructureV2 = (metaBytes) => {
|
|
|
69
73
|
reader.readExact(8, "timestamp wall time");
|
|
70
74
|
reader.readExact(4, "timestamp logical time");
|
|
71
75
|
reader.readBytes("gid");
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (directParentCount > Math.floor(reader.remaining / 4)) {
|
|
76
|
-
throw new Error("Authority EntryV0 has impossible direct-parent count");
|
|
76
|
+
const parentCount = reader.readU32("direct-parent count");
|
|
77
|
+
if (parentCount > Math.floor(reader.remaining / 4)) {
|
|
78
|
+
throw new Error(`${limits.label} EntryV0 has impossible direct-parent count`);
|
|
77
79
|
}
|
|
78
|
-
|
|
80
|
+
if (limits.maximumDirectParents !== undefined &&
|
|
81
|
+
parentCount > limits.maximumDirectParents) {
|
|
82
|
+
throw new Error(`${limits.label} EntryV0 may contain at most ${limits.maximumDirectParents} direct parents`);
|
|
83
|
+
}
|
|
84
|
+
for (let index = 0; index < parentCount; index++) {
|
|
79
85
|
reader.readBytes("direct parent");
|
|
80
86
|
}
|
|
81
87
|
reader.readU8("entry type");
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
reader.readBytes("metadata data");
|
|
88
|
+
const metadataOption = reader.readU8("metadata data option");
|
|
89
|
+
if (metadataOption === 1) {
|
|
90
|
+
const metadata = reader.readBytes("metadata data");
|
|
91
|
+
if (limits.maximumMetadataBytes !== undefined &&
|
|
92
|
+
metadata.byteLength > limits.maximumMetadataBytes) {
|
|
93
|
+
throw new Error(`${limits.label} EntryV0 metadata may contain at most ${limits.maximumMetadataBytes} bytes`);
|
|
94
|
+
}
|
|
85
95
|
}
|
|
86
|
-
else if (
|
|
87
|
-
throw new Error(
|
|
96
|
+
else if (metadataOption !== 0) {
|
|
97
|
+
throw new Error(`${limits.label} EntryV0 has invalid metadata data option`);
|
|
88
98
|
}
|
|
89
99
|
reader.expectDone("metadata");
|
|
90
|
-
return
|
|
100
|
+
return parentCount;
|
|
91
101
|
};
|
|
92
|
-
const
|
|
93
|
-
const reader = new BoundsReaderV2(
|
|
102
|
+
const scanPayloadV2 = (bytes, label) => {
|
|
103
|
+
const reader = new BoundsReaderV2(bytes, label);
|
|
94
104
|
reader.expectU8(0, "payload variant");
|
|
95
105
|
const data = reader.readBytes("payload data");
|
|
96
106
|
reader.expectDone("payload");
|
|
97
107
|
return data;
|
|
98
108
|
};
|
|
99
|
-
const
|
|
100
|
-
const reader = new BoundsReaderV2(
|
|
109
|
+
const scanSignatureV2 = (bytes, label) => {
|
|
110
|
+
const reader = new BoundsReaderV2(bytes, label);
|
|
101
111
|
reader.expectU8(0, "signature variant");
|
|
102
112
|
reader.readBytes("signature data");
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
throw new Error(
|
|
113
|
+
const keyVariant = reader.readU8("signature public-key variant");
|
|
114
|
+
const keyLength = keyVariant === 0 ? 32 : keyVariant === 1 ? 33 : undefined;
|
|
115
|
+
if (keyLength === undefined) {
|
|
116
|
+
throw new Error(`${label} EntryV0 uses an unsupported signing key`);
|
|
107
117
|
}
|
|
108
|
-
reader.readExact(
|
|
118
|
+
reader.readExact(keyLength, "signature public key");
|
|
109
119
|
reader.readU8("signature prehash");
|
|
110
120
|
reader.expectDone("signature");
|
|
111
121
|
};
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Bounds-scans and canonically decodes one already-captured public EntryV0.
|
|
124
|
+
* Record meaning, signer authority, reserved bytes, hash option, and causal
|
|
125
|
+
* semantics remain the responsibility of the caller's domain profile.
|
|
126
|
+
*/
|
|
127
|
+
export const scanCanonicalPublicEntryV0V2 = (entryBytes, limits) => {
|
|
128
|
+
if (!Number.isSafeInteger(limits.minimumSignatures) ||
|
|
129
|
+
!Number.isSafeInteger(limits.maximumSignatures) ||
|
|
130
|
+
limits.minimumSignatures < 1 ||
|
|
131
|
+
limits.maximumSignatures < limits.minimumSignatures) {
|
|
132
|
+
throw new Error("Invalid internal EntryV0 signature bounds");
|
|
133
|
+
}
|
|
134
|
+
const reader = new BoundsReaderV2(entryBytes, limits.label);
|
|
114
135
|
reader.expectU8(0, "entry variant");
|
|
115
|
-
const metaBytes = readPublicWrapperV2(reader, "metadata");
|
|
116
|
-
const payloadContainerBytes = readPublicWrapperV2(reader, "payload");
|
|
136
|
+
const metaBytes = readPublicWrapperV2(reader, limits.label, "metadata");
|
|
137
|
+
const payloadContainerBytes = readPublicWrapperV2(reader, limits.label, "payload");
|
|
117
138
|
const reservedBytes = reader.readExact(4, "reserved bytes");
|
|
118
139
|
const signablePrefixLength = reader.position;
|
|
119
140
|
if (reader.readU8("signatures option") !== 1) {
|
|
120
|
-
throw new Error(
|
|
141
|
+
throw new Error(`${limits.label} EntryV0 must contain signatures`);
|
|
121
142
|
}
|
|
122
143
|
reader.expectU8(0, "signatures variant");
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
const signatureCount = reader.readU32("signature count");
|
|
145
|
+
if (signatureCount < limits.minimumSignatures ||
|
|
146
|
+
signatureCount > limits.maximumSignatures ||
|
|
147
|
+
signatureCount > Math.floor(reader.remaining / 6)) {
|
|
148
|
+
const expected = limits.minimumSignatures === 1 && limits.maximumSignatures === 1
|
|
149
|
+
? "exactly one signature"
|
|
150
|
+
: limits.minimumSignatures === limits.maximumSignatures
|
|
151
|
+
? `exactly ${limits.minimumSignatures}`
|
|
152
|
+
: `${limits.minimumSignatures}-${limits.maximumSignatures} signatures`;
|
|
153
|
+
throw new Error(`${limits.label} EntryV0 must contain ${expected}`);
|
|
154
|
+
}
|
|
155
|
+
for (let index = 0; index < signatureCount; index++) {
|
|
156
|
+
scanSignatureV2(readPublicWrapperV2(reader, limits.label, "signature"), limits.label);
|
|
125
157
|
}
|
|
126
|
-
const signatureBytes = readPublicWrapperV2(reader, "signature");
|
|
127
158
|
const hashOption = reader.readU8("hash option");
|
|
128
159
|
if (hashOption === 1) {
|
|
129
160
|
reader.readBytes("hash");
|
|
130
161
|
}
|
|
131
162
|
else if (hashOption !== 0) {
|
|
132
|
-
throw new Error(
|
|
163
|
+
throw new Error(`${limits.label} EntryV0 has invalid hash option`);
|
|
133
164
|
}
|
|
134
165
|
reader.expectDone("storage");
|
|
135
|
-
const directParentCount =
|
|
136
|
-
const payloadBytes =
|
|
137
|
-
scanSignatureStructureV2(signatureBytes);
|
|
166
|
+
const directParentCount = scanMetaV2(metaBytes, limits);
|
|
167
|
+
const payloadBytes = scanPayloadV2(payloadContainerBytes, limits.label);
|
|
138
168
|
const signableBytes = new Uint8Array(signablePrefixLength + 2);
|
|
139
169
|
signableBytes.set(entryBytes.subarray(0, signablePrefixLength));
|
|
170
|
+
const entry = deserialize(entryBytes, Entry);
|
|
171
|
+
if (!(entry instanceof EntryV0)) {
|
|
172
|
+
throw new Error(`${limits.label} entry must use EntryV0`);
|
|
173
|
+
}
|
|
174
|
+
if (!equals(entryBytes, serialize(entry))) {
|
|
175
|
+
throw new Error(`${limits.label} EntryV0 storage is not canonical`);
|
|
176
|
+
}
|
|
177
|
+
if (!(entry._meta instanceof DecryptedThing) ||
|
|
178
|
+
!(entry._payload instanceof DecryptedThing)) {
|
|
179
|
+
throw new Error(`${limits.label} EntryV0 metadata and payload must be public`);
|
|
180
|
+
}
|
|
181
|
+
if (entry._signatures === undefined ||
|
|
182
|
+
entry._signatures.signatures.length !== signatureCount ||
|
|
183
|
+
entry._signatures.signatures.some((signature) => !(signature instanceof DecryptedThing))) {
|
|
184
|
+
throw new Error(`${limits.label} EntryV0 signatures must be public`);
|
|
185
|
+
}
|
|
186
|
+
entry.init({ encoding: NO_ENCODING });
|
|
187
|
+
const meta = entry.meta;
|
|
188
|
+
if (!equals(metaBytes, serialize(meta))) {
|
|
189
|
+
throw new Error(`${limits.label} EntryV0 nested encoding is not canonical`);
|
|
190
|
+
}
|
|
191
|
+
if (!equals(payloadBytes, entry.payload.data)) {
|
|
192
|
+
throw new Error(`${limits.label} EntryV0 payload framing is inconsistent`);
|
|
193
|
+
}
|
|
194
|
+
const signatures = entry.signatures;
|
|
195
|
+
if (signatures.length !== signatureCount) {
|
|
196
|
+
throw new Error(`${limits.label} EntryV0 signature framing is inconsistent`);
|
|
197
|
+
}
|
|
140
198
|
return {
|
|
199
|
+
entry,
|
|
200
|
+
meta,
|
|
201
|
+
signatures,
|
|
141
202
|
metaBytes,
|
|
142
203
|
payloadBytes,
|
|
143
204
|
signableBytes,
|
|
144
205
|
reservedBytes,
|
|
145
206
|
hasHash: hashOption === 1,
|
|
146
207
|
directParentCount,
|
|
208
|
+
signatureCount,
|
|
147
209
|
};
|
|
148
210
|
};
|
|
211
|
+
const SECP256K1_SIGNATURE_TEXT_BYTES = 132;
|
|
212
|
+
const SECP256K1_LOW_S_MAX_HEX = "7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0";
|
|
213
|
+
const isLowerHexByteV2 = (value) => (value >= 0x30 && value <= 0x39) || (value >= 0x61 && value <= 0x66);
|
|
214
|
+
export const assertCanonicalSecp256k1SignatureV2 = (signature, label) => {
|
|
215
|
+
if (signature.byteLength !== SECP256K1_SIGNATURE_TEXT_BYTES ||
|
|
216
|
+
signature[0] !== 0x30 ||
|
|
217
|
+
signature[1] !== 0x78) {
|
|
218
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
219
|
+
}
|
|
220
|
+
for (let index = 2; index < signature.byteLength; index++) {
|
|
221
|
+
if (!isLowerHexByteV2(signature[index])) {
|
|
222
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (signature[130] !== 0x31 ||
|
|
226
|
+
(signature[131] !== 0x62 && signature[131] !== 0x63)) {
|
|
227
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
228
|
+
}
|
|
229
|
+
for (let index = 0; index < SECP256K1_LOW_S_MAX_HEX.length; index++) {
|
|
230
|
+
const actual = signature[66 + index];
|
|
231
|
+
const maximum = SECP256K1_LOW_S_MAX_HEX.charCodeAt(index);
|
|
232
|
+
if (actual < maximum)
|
|
233
|
+
break;
|
|
234
|
+
if (actual > maximum) {
|
|
235
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
export const canonicalDirectParentsV2 = (parents, label) => {
|
|
240
|
+
const seen = new Set();
|
|
241
|
+
return parents.map((cid) => {
|
|
242
|
+
let parsed;
|
|
243
|
+
try {
|
|
244
|
+
parsed = cidifyString(cid);
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
throw new Error(`${label} EntryV0 direct parents must use canonical CIDv1/raw/sha2-256`);
|
|
248
|
+
}
|
|
249
|
+
if (!cid ||
|
|
250
|
+
cid.length > TRUSTED_NETWORK_V2_MAX_CANONICAL_ENTRY_CID_CHARACTERS ||
|
|
251
|
+
parsed.version !== 1 ||
|
|
252
|
+
parsed.code !== codecMap.raw.code ||
|
|
253
|
+
parsed.multihash.code !== defaultHasher.code ||
|
|
254
|
+
parsed.multihash.digest.byteLength !== 32 ||
|
|
255
|
+
stringifyCid(parsed) !== cid) {
|
|
256
|
+
throw new Error(`${label} EntryV0 direct parents must use canonical CIDv1/raw/sha2-256`);
|
|
257
|
+
}
|
|
258
|
+
if (seen.has(cid)) {
|
|
259
|
+
throw new Error(`${label} EntryV0 direct parents must be unique`);
|
|
260
|
+
}
|
|
261
|
+
seen.add(cid);
|
|
262
|
+
return {
|
|
263
|
+
cid,
|
|
264
|
+
digest: copyUint8ArrayWithLengthV2(parsed.multihash.digest, parsed.multihash.digest.byteLength),
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
};
|
|
149
268
|
const validateMaximumEntryBytesV2 = (maximumEntryBytes) => {
|
|
150
269
|
if (!Number.isSafeInteger(maximumEntryBytes) || maximumEntryBytes < 1) {
|
|
151
270
|
throw new Error("Invalid internal authority EntryV0 byte limit");
|
|
@@ -174,46 +293,26 @@ export const captureAuthorityEntryV0BytesV2 = (entryBytes, maximumEntryBytes) =>
|
|
|
174
293
|
export const authenticateCapturedAuthorityEntryV0V2 = async (capturedEntryBytes, descriptor, assertProfile) => {
|
|
175
294
|
assertNetworkDescriptorV2(descriptor);
|
|
176
295
|
const authorityBytes = serialize(descriptor.policyAuthority);
|
|
177
|
-
const scanned =
|
|
296
|
+
const scanned = scanCanonicalPublicEntryV0V2(capturedEntryBytes, {
|
|
297
|
+
label: "Authority",
|
|
298
|
+
minimumSignatures: 1,
|
|
299
|
+
maximumSignatures: 1,
|
|
300
|
+
});
|
|
178
301
|
const capturedDescriptor = deserialize(serialize(descriptor), NetworkDescriptorV2);
|
|
179
302
|
assertNetworkDescriptorV2(capturedDescriptor);
|
|
180
303
|
if (!equals(serialize(capturedDescriptor.policyAuthority), authorityBytes)) {
|
|
181
304
|
throw new Error("Network descriptor changed during capture");
|
|
182
305
|
}
|
|
183
|
-
const
|
|
184
|
-
if (!(
|
|
185
|
-
throw new Error("Authority entry must use EntryV0");
|
|
186
|
-
}
|
|
187
|
-
if (!equals(capturedEntryBytes, serialize(entry))) {
|
|
188
|
-
throw new Error("Authority EntryV0 storage is not canonical");
|
|
189
|
-
}
|
|
190
|
-
if (!(entry._meta instanceof DecryptedThing)) {
|
|
191
|
-
throw new Error("Authority EntryV0 metadata must be public");
|
|
192
|
-
}
|
|
193
|
-
if (!(entry._payload instanceof DecryptedThing)) {
|
|
194
|
-
throw new Error("Authority EntryV0 payload must be public");
|
|
195
|
-
}
|
|
196
|
-
if (entry._signatures === undefined ||
|
|
197
|
-
entry._signatures.signatures.length !== 1 ||
|
|
198
|
-
!(entry._signatures.signatures[0] instanceof DecryptedThing)) {
|
|
199
|
-
throw new Error("Authority EntryV0 must contain one public signature");
|
|
200
|
-
}
|
|
201
|
-
entry.init({ encoding: NO_ENCODING });
|
|
202
|
-
const payload = entry.payload;
|
|
203
|
-
const signatures = entry.signatures;
|
|
204
|
-
if (signatures.length !== 1 ||
|
|
205
|
-
!equals(serialize(signatures[0].publicKey), authorityBytes)) {
|
|
306
|
+
const signatures = scanned.signatures;
|
|
307
|
+
if (!equals(serialize(signatures[0].publicKey), authorityBytes)) {
|
|
206
308
|
throw new Error("Authority EntryV0 signer is not the policy authority");
|
|
207
309
|
}
|
|
208
|
-
if (!equals(scanned.payloadBytes, payload.data)) {
|
|
209
|
-
throw new Error("Authority EntryV0 payload framing is inconsistent");
|
|
210
|
-
}
|
|
211
310
|
const authenticated = {
|
|
212
311
|
descriptor: capturedDescriptor,
|
|
213
312
|
entryBytes: capturedEntryBytes,
|
|
214
|
-
entry,
|
|
313
|
+
entry: scanned.entry,
|
|
215
314
|
metaBytes: scanned.metaBytes,
|
|
216
|
-
payloadBytes:
|
|
315
|
+
payloadBytes: scanned.payloadBytes,
|
|
217
316
|
reservedBytes: scanned.reservedBytes,
|
|
218
317
|
hasHash: scanned.hasHash,
|
|
219
318
|
directParentCount: scanned.directParentCount,
|
|
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C/B,iBAAyB,EACzB,aAAyC,EACE,EAAE,CAC7C,sCAAsC,CACrC,8BAA8B,CAAC,UAAU,EAAE,iBAAiB,CAAC,EAC7D,UAAU,EACV,aAAa,CACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2-resource-fence-entry.d.ts","sourceRoot":"","sources":["../../src/v2-resource-fence-entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"v2-resource-fence-entry.d.ts","sourceRoot":"","sources":["../../src/v2-resource-fence-entry.ts"],"names":[],"mappings":"AAUA,OAAO,EACN,mBAAmB,EACnB,eAAe,EAOf,MAAM,SAAS,CAAC;AAoEjB,MAAM,MAAM,iCAAiC,GAAG,QAAQ,CAAC;IACxD,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,aAAa,EAAE,aAAa,CAAC,QAAQ,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC,CAAC;CAC5E,CAAC,CAAC;AAEH,MAAM,MAAM,0CAA0C,GAAG,QAAQ,CAAC;IACjE,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,mBAAmB,CAAC;IAChC,kBAAkB,EAAE,UAAU,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAiCH;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,GAAU,8DAKpD,0CAA0C,KAAG,OAAO,CAAC,iCAAiC,CA6CxF,CAAC"}
|
|
@@ -1,68 +1,12 @@
|
|
|
1
1
|
import { serialize } from "@dao-xyz/borsh";
|
|
2
|
-
import { calculateRawCid
|
|
2
|
+
import { calculateRawCid } from "@peerbit/blocks-interface";
|
|
3
3
|
import { EntryType } from "@peerbit/log";
|
|
4
4
|
import { equals } from "uint8arrays";
|
|
5
|
-
import { authenticateAuthorityEntryV0V2, } from "./v2-authority-entry.js";
|
|
5
|
+
import { assertCanonicalSecp256k1SignatureV2, authenticateAuthorityEntryV0V2, canonicalDirectParentsV2, } from "./v2-authority-entry.js";
|
|
6
6
|
import { NetworkDescriptorV2, ResourceFenceV2, TRUSTED_NETWORK_V2_MAX_RESOURCE_FENCE_DIRECT_PARENTS, TRUSTED_NETWORK_V2_MAX_RESOURCE_FENCE_ENTRY_BYTES, TRUSTED_NETWORK_V2_RESOURCE_FENCE_BODY_BYTES, copyUint8ArrayWithLengthV2, decodeResourceFenceV2, exactUint8ArrayByteLengthV2, } from "./v2.js";
|
|
7
7
|
const RESOURCE_FENCE_AUTHORITY_LIMITS_V2 = Object.freeze({
|
|
8
8
|
maximumEntryBytes: TRUSTED_NETWORK_V2_MAX_RESOURCE_FENCE_ENTRY_BYTES,
|
|
9
9
|
});
|
|
10
|
-
const SECP256K1_SIGNATURE_TEXT_BYTES = 132;
|
|
11
|
-
const SECP256K1_LOW_S_MAX_HEX = "7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0";
|
|
12
|
-
const isLowerHexByteV2 = (value) => (value >= 0x30 && value <= 0x39) || (value >= 0x61 && value <= 0x66);
|
|
13
|
-
const assertCanonicalSecp256k1SignatureV2 = (signature) => {
|
|
14
|
-
if (signature.byteLength !== SECP256K1_SIGNATURE_TEXT_BYTES ||
|
|
15
|
-
signature[0] !== 0x30 ||
|
|
16
|
-
signature[1] !== 0x78) {
|
|
17
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
18
|
-
}
|
|
19
|
-
for (let i = 2; i < signature.byteLength; i++) {
|
|
20
|
-
if (!isLowerHexByteV2(signature[i])) {
|
|
21
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (signature[130] !== 0x31 ||
|
|
25
|
-
(signature[131] !== 0x62 && signature[131] !== 0x63)) {
|
|
26
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
27
|
-
}
|
|
28
|
-
for (let i = 0; i < SECP256K1_LOW_S_MAX_HEX.length; i++) {
|
|
29
|
-
const actual = signature[66 + i];
|
|
30
|
-
const maximum = SECP256K1_LOW_S_MAX_HEX.charCodeAt(i);
|
|
31
|
-
if (actual < maximum)
|
|
32
|
-
break;
|
|
33
|
-
if (actual > maximum) {
|
|
34
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const canonicalDirectParentsV2 = (parents) => {
|
|
39
|
-
const seen = new Set();
|
|
40
|
-
return parents.map((cid) => {
|
|
41
|
-
let parsed;
|
|
42
|
-
try {
|
|
43
|
-
parsed = cidifyString(cid);
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
throw new Error("Authority EntryV0 direct parents must use canonical CIDv1/raw/sha2-256");
|
|
47
|
-
}
|
|
48
|
-
if (!cid ||
|
|
49
|
-
parsed.version !== 1 ||
|
|
50
|
-
parsed.code !== codecMap.raw.code ||
|
|
51
|
-
parsed.multihash.code !== defaultHasher.code ||
|
|
52
|
-
parsed.multihash.digest.byteLength !== 32 ||
|
|
53
|
-
stringifyCid(parsed) !== cid) {
|
|
54
|
-
throw new Error("Authority EntryV0 direct parents must use canonical CIDv1/raw/sha2-256");
|
|
55
|
-
}
|
|
56
|
-
if (seen.has(cid)) {
|
|
57
|
-
throw new Error("Authority EntryV0 direct parents must be unique");
|
|
58
|
-
}
|
|
59
|
-
seen.add(cid);
|
|
60
|
-
return {
|
|
61
|
-
cid,
|
|
62
|
-
digest: copyUint8ArrayWithLengthV2(parsed.multihash.digest, parsed.multihash.digest.byteLength),
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
10
|
const assertResourceFenceEntryV0ProfileV2 = (authenticated) => {
|
|
67
11
|
if (authenticated.hasHash) {
|
|
68
12
|
throw new Error("Authority EntryV0 has invalid resource hash option: embedded hash");
|
|
@@ -97,9 +41,12 @@ const assertResourceFenceEntryV0ProfileV2 = (authenticated) => {
|
|
|
97
41
|
}
|
|
98
42
|
const signature = authenticated.entry.signatures[0];
|
|
99
43
|
if (serialize(signature.publicKey)[0] === 1) {
|
|
100
|
-
assertCanonicalSecp256k1SignatureV2(signature.signature);
|
|
44
|
+
assertCanonicalSecp256k1SignatureV2(signature.signature, "Authority");
|
|
101
45
|
}
|
|
102
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
meta,
|
|
48
|
+
directParents: canonicalDirectParentsV2(meta.next, "Authority"),
|
|
49
|
+
};
|
|
103
50
|
};
|
|
104
51
|
const captureResourceIdV2 = (resourceId) => {
|
|
105
52
|
let byteLength;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2-resource-fence-entry.js","sourceRoot":"","sources":["../../src/v2-resource-fence-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"v2-resource-fence-entry.js","sourceRoot":"","sources":["../../src/v2-resource-fence-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAa,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAEN,mCAAmC,EACnC,8BAA8B,EAC9B,wBAAwB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,oDAAoD,EACpD,iDAAiD,EACjD,4CAA4C,EAC5C,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC3B,M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CAC5B,aAAa,EACb,IAAI,EACJ,QAAQ,CAAC,GAAG,EACZ,0BAA0B,CACzB,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EACnC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAC9C,EACD,OAAO,CAAC,IAAI,CAAC,GAAG,EAChB,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;QAC9B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,0BAA0B,CAC1B,OAAO,CAAC,IAAI,CAAC,IAAI,EACjB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAC5B,EACH,OAAO,CAAC,aAAa,CACrB,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/trusted-network",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.131",
|
|
4
4
|
"description": "Access controller that operates on a DB",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,12 @@
|
|
|
26
26
|
"dist",
|
|
27
27
|
"!src/v2-resource-fence-anchor.ts",
|
|
28
28
|
"!src/v2-resource-fence-engine.ts",
|
|
29
|
+
"!src/v2-resource-operation-entry.ts",
|
|
30
|
+
"!src/v2-resource-operation-engine.ts",
|
|
29
31
|
"!dist/src/v2-resource-fence-anchor.*",
|
|
30
32
|
"!dist/src/v2-resource-fence-engine.*",
|
|
33
|
+
"!dist/src/v2-resource-operation-entry.*",
|
|
34
|
+
"!dist/src/v2-resource-operation-engine.*",
|
|
31
35
|
"!dist/e2e",
|
|
32
36
|
"!dist/test",
|
|
33
37
|
"!**/*.tsbuildinfo"
|
|
@@ -60,17 +64,17 @@
|
|
|
60
64
|
"@libp2p/interface": "^3.2.5",
|
|
61
65
|
"uint8arrays": "^5.1.0",
|
|
62
66
|
"@peerbit/any-store": "2.2.17",
|
|
63
|
-
"@peerbit/blocks-interface": "2.2.0",
|
|
64
67
|
"@peerbit/any-store-interface": "1.1.4",
|
|
68
|
+
"@peerbit/blocks-interface": "2.2.1",
|
|
69
|
+
"@peerbit/document": "15.1.0",
|
|
65
70
|
"@peerbit/crypto": "3.1.6",
|
|
66
|
-
"@peerbit/
|
|
67
|
-
"@peerbit/
|
|
68
|
-
"@peerbit/
|
|
69
|
-
"@peerbit/shared-log": "16.0.29"
|
|
71
|
+
"@peerbit/log": "6.2.33",
|
|
72
|
+
"@peerbit/program": "6.0.60",
|
|
73
|
+
"@peerbit/shared-log": "16.0.30"
|
|
70
74
|
},
|
|
71
75
|
"devDependencies": {
|
|
72
76
|
"ethers": "^6.17.0",
|
|
73
|
-
"@peerbit/test-utils": "3.1.
|
|
77
|
+
"@peerbit/test-utils": "3.1.41",
|
|
74
78
|
"@peerbit/time": "3.0.1"
|
|
75
79
|
},
|
|
76
80
|
"repository": {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { deserialize, serialize } from "@dao-xyz/borsh";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
cidifyString,
|
|
4
|
+
codecMap,
|
|
5
|
+
defaultHasher,
|
|
6
|
+
stringifyCid,
|
|
7
|
+
} from "@peerbit/blocks-interface";
|
|
8
|
+
import { DecryptedThing, type SignatureWithKey, verify } from "@peerbit/crypto";
|
|
9
|
+
import { Entry, EntryV0, type Meta, NO_ENCODING } from "@peerbit/log";
|
|
4
10
|
import { equals } from "uint8arrays";
|
|
5
11
|
import {
|
|
6
12
|
NetworkDescriptorV2,
|
|
@@ -9,35 +15,37 @@ import {
|
|
|
9
15
|
exactUint8ArrayByteLengthV2,
|
|
10
16
|
} from "./v2.js";
|
|
11
17
|
|
|
12
|
-
export
|
|
13
|
-
descriptor: NetworkDescriptorV2;
|
|
14
|
-
entryBytes: Uint8Array;
|
|
15
|
-
entry: EntryV0<Uint8Array>;
|
|
16
|
-
metaBytes: Uint8Array;
|
|
17
|
-
payloadBytes: Uint8Array;
|
|
18
|
-
reservedBytes: Uint8Array;
|
|
19
|
-
hasHash: boolean;
|
|
20
|
-
directParentCount: number;
|
|
21
|
-
};
|
|
18
|
+
export const TRUSTED_NETWORK_V2_MAX_CANONICAL_ENTRY_CID_CHARACTERS = 128;
|
|
22
19
|
|
|
23
|
-
export type
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
export type CanonicalPublicEntryV0ScanLimitsV2 = Readonly<{
|
|
21
|
+
label: string;
|
|
22
|
+
minimumSignatures: number;
|
|
23
|
+
maximumSignatures: number;
|
|
24
|
+
maximumDirectParents?: number;
|
|
25
|
+
maximumMetadataBytes?: number;
|
|
26
|
+
}>;
|
|
26
27
|
|
|
27
|
-
type
|
|
28
|
+
export type CanonicalPublicEntryV0ScanV2 = Readonly<{
|
|
29
|
+
entry: EntryV0<Uint8Array>;
|
|
30
|
+
meta: Meta;
|
|
31
|
+
signatures: SignatureWithKey[];
|
|
28
32
|
metaBytes: Uint8Array;
|
|
29
33
|
payloadBytes: Uint8Array;
|
|
30
34
|
signableBytes: Uint8Array;
|
|
31
35
|
reservedBytes: Uint8Array;
|
|
32
36
|
hasHash: boolean;
|
|
33
37
|
directParentCount: number;
|
|
34
|
-
|
|
38
|
+
signatureCount: number;
|
|
39
|
+
}>;
|
|
35
40
|
|
|
36
41
|
class BoundsReaderV2 {
|
|
37
42
|
private offset = 0;
|
|
38
43
|
private readonly view: DataView;
|
|
39
44
|
|
|
40
|
-
constructor(
|
|
45
|
+
constructor(
|
|
46
|
+
private readonly bytes: Uint8Array,
|
|
47
|
+
private readonly label: string,
|
|
48
|
+
) {
|
|
41
49
|
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
42
50
|
}
|
|
43
51
|
|
|
@@ -49,47 +57,47 @@ class BoundsReaderV2 {
|
|
|
49
57
|
return this.bytes.byteLength - this.offset;
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
readU8(
|
|
53
|
-
return this.readExact(1,
|
|
60
|
+
readU8(field: string): number {
|
|
61
|
+
return this.readExact(1, field)[0]!;
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
readU32(
|
|
57
|
-
this.requireRemaining(4,
|
|
64
|
+
readU32(field: string): number {
|
|
65
|
+
this.requireRemaining(4, field);
|
|
58
66
|
const value = this.view.getUint32(this.offset, true);
|
|
59
67
|
this.offset += 4;
|
|
60
68
|
return value;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
|
-
readBytes(
|
|
64
|
-
return this.readExact(this.readU32(`${
|
|
71
|
+
readBytes(field: string): Uint8Array {
|
|
72
|
+
return this.readExact(this.readU32(`${field} length`), field);
|
|
65
73
|
}
|
|
66
74
|
|
|
67
|
-
readExact(byteLength: number,
|
|
68
|
-
this.requireRemaining(byteLength,
|
|
75
|
+
readExact(byteLength: number, field: string): Uint8Array {
|
|
76
|
+
this.requireRemaining(byteLength, field);
|
|
69
77
|
const start = this.offset;
|
|
70
78
|
this.offset += byteLength;
|
|
71
79
|
return this.bytes.subarray(start, this.offset);
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
expectU8(expected: number,
|
|
75
|
-
if (this.readU8(
|
|
76
|
-
throw new Error(
|
|
82
|
+
expectU8(expected: number, field: string): void {
|
|
83
|
+
if (this.readU8(field) !== expected) {
|
|
84
|
+
throw new Error(`${this.label} EntryV0 has invalid ${field}`);
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
expectDone(
|
|
88
|
+
expectDone(field: string): void {
|
|
81
89
|
if (this.offset !== this.bytes.byteLength) {
|
|
82
|
-
throw new Error(
|
|
90
|
+
throw new Error(`${this.label} EntryV0 has trailing ${field} bytes`);
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
|
|
86
|
-
private requireRemaining(byteLength: number,
|
|
94
|
+
private requireRemaining(byteLength: number, field: string): void {
|
|
87
95
|
if (
|
|
88
96
|
!Number.isSafeInteger(byteLength) ||
|
|
89
97
|
byteLength < 0 ||
|
|
90
98
|
byteLength > this.bytes.byteLength - this.offset
|
|
91
99
|
) {
|
|
92
|
-
throw new Error(
|
|
100
|
+
throw new Error(`${this.label} EntryV0 has truncated ${field}`);
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
}
|
|
@@ -97,18 +105,22 @@ class BoundsReaderV2 {
|
|
|
97
105
|
const readPublicWrapperV2 = (
|
|
98
106
|
reader: BoundsReaderV2,
|
|
99
107
|
label: string,
|
|
108
|
+
field: string,
|
|
100
109
|
): Uint8Array => {
|
|
101
110
|
if (
|
|
102
|
-
reader.readU8(`${
|
|
103
|
-
reader.readU8(`${
|
|
111
|
+
reader.readU8(`${field} MaybeEncrypted variant`) !== 0 ||
|
|
112
|
+
reader.readU8(`${field} DecryptedThing variant`) !== 0
|
|
104
113
|
) {
|
|
105
|
-
throw new Error(
|
|
114
|
+
throw new Error(`${label} EntryV0 ${field} must be public`);
|
|
106
115
|
}
|
|
107
|
-
return reader.readBytes(
|
|
116
|
+
return reader.readBytes(field);
|
|
108
117
|
};
|
|
109
118
|
|
|
110
|
-
const
|
|
111
|
-
|
|
119
|
+
const scanMetaV2 = (
|
|
120
|
+
bytes: Uint8Array,
|
|
121
|
+
limits: CanonicalPublicEntryV0ScanLimitsV2,
|
|
122
|
+
): number => {
|
|
123
|
+
const reader = new BoundsReaderV2(bytes, limits.label);
|
|
112
124
|
reader.expectU8(0, "metadata variant");
|
|
113
125
|
reader.expectU8(0, "clock variant");
|
|
114
126
|
reader.readBytes("clock id");
|
|
@@ -116,91 +128,275 @@ const scanMetaStructureV2 = (metaBytes: Uint8Array): number => {
|
|
|
116
128
|
reader.readExact(8, "timestamp wall time");
|
|
117
129
|
reader.readExact(4, "timestamp logical time");
|
|
118
130
|
reader.readBytes("gid");
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
const parentCount = reader.readU32("direct-parent count");
|
|
132
|
+
if (parentCount > Math.floor(reader.remaining / 4)) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`${limits.label} EntryV0 has impossible direct-parent count`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (
|
|
138
|
+
limits.maximumDirectParents !== undefined &&
|
|
139
|
+
parentCount > limits.maximumDirectParents
|
|
140
|
+
) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`${limits.label} EntryV0 may contain at most ${limits.maximumDirectParents} direct parents`,
|
|
143
|
+
);
|
|
125
144
|
}
|
|
126
|
-
for (let
|
|
145
|
+
for (let index = 0; index < parentCount; index++) {
|
|
127
146
|
reader.readBytes("direct parent");
|
|
128
147
|
}
|
|
129
|
-
|
|
130
148
|
reader.readU8("entry type");
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
reader.readBytes("metadata data");
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
const metadataOption = reader.readU8("metadata data option");
|
|
150
|
+
if (metadataOption === 1) {
|
|
151
|
+
const metadata = reader.readBytes("metadata data");
|
|
152
|
+
if (
|
|
153
|
+
limits.maximumMetadataBytes !== undefined &&
|
|
154
|
+
metadata.byteLength > limits.maximumMetadataBytes
|
|
155
|
+
) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`${limits.label} EntryV0 metadata may contain at most ${limits.maximumMetadataBytes} bytes`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
} else if (metadataOption !== 0) {
|
|
161
|
+
throw new Error(`${limits.label} EntryV0 has invalid metadata data option`);
|
|
136
162
|
}
|
|
137
163
|
reader.expectDone("metadata");
|
|
138
|
-
return
|
|
164
|
+
return parentCount;
|
|
139
165
|
};
|
|
140
166
|
|
|
141
|
-
const
|
|
142
|
-
const reader = new BoundsReaderV2(
|
|
167
|
+
const scanPayloadV2 = (bytes: Uint8Array, label: string): Uint8Array => {
|
|
168
|
+
const reader = new BoundsReaderV2(bytes, label);
|
|
143
169
|
reader.expectU8(0, "payload variant");
|
|
144
170
|
const data = reader.readBytes("payload data");
|
|
145
171
|
reader.expectDone("payload");
|
|
146
172
|
return data;
|
|
147
173
|
};
|
|
148
174
|
|
|
149
|
-
const
|
|
150
|
-
const reader = new BoundsReaderV2(
|
|
175
|
+
const scanSignatureV2 = (bytes: Uint8Array, label: string): void => {
|
|
176
|
+
const reader = new BoundsReaderV2(bytes, label);
|
|
151
177
|
reader.expectU8(0, "signature variant");
|
|
152
178
|
reader.readBytes("signature data");
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
throw new Error("Authority EntryV0 uses an unsupported signing key");
|
|
179
|
+
const keyVariant = reader.readU8("signature public-key variant");
|
|
180
|
+
const keyLength = keyVariant === 0 ? 32 : keyVariant === 1 ? 33 : undefined;
|
|
181
|
+
if (keyLength === undefined) {
|
|
182
|
+
throw new Error(`${label} EntryV0 uses an unsupported signing key`);
|
|
158
183
|
}
|
|
159
|
-
reader.readExact(
|
|
184
|
+
reader.readExact(keyLength, "signature public key");
|
|
160
185
|
reader.readU8("signature prehash");
|
|
161
186
|
reader.expectDone("signature");
|
|
162
187
|
};
|
|
163
188
|
|
|
164
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Bounds-scans and canonically decodes one already-captured public EntryV0.
|
|
191
|
+
* Record meaning, signer authority, reserved bytes, hash option, and causal
|
|
192
|
+
* semantics remain the responsibility of the caller's domain profile.
|
|
193
|
+
*/
|
|
194
|
+
export const scanCanonicalPublicEntryV0V2 = (
|
|
165
195
|
entryBytes: Uint8Array,
|
|
166
|
-
|
|
167
|
-
|
|
196
|
+
limits: CanonicalPublicEntryV0ScanLimitsV2,
|
|
197
|
+
): CanonicalPublicEntryV0ScanV2 => {
|
|
198
|
+
if (
|
|
199
|
+
!Number.isSafeInteger(limits.minimumSignatures) ||
|
|
200
|
+
!Number.isSafeInteger(limits.maximumSignatures) ||
|
|
201
|
+
limits.minimumSignatures < 1 ||
|
|
202
|
+
limits.maximumSignatures < limits.minimumSignatures
|
|
203
|
+
) {
|
|
204
|
+
throw new Error("Invalid internal EntryV0 signature bounds");
|
|
205
|
+
}
|
|
206
|
+
const reader = new BoundsReaderV2(entryBytes, limits.label);
|
|
168
207
|
reader.expectU8(0, "entry variant");
|
|
169
|
-
const metaBytes = readPublicWrapperV2(reader, "metadata");
|
|
170
|
-
const payloadContainerBytes = readPublicWrapperV2(
|
|
208
|
+
const metaBytes = readPublicWrapperV2(reader, limits.label, "metadata");
|
|
209
|
+
const payloadContainerBytes = readPublicWrapperV2(
|
|
210
|
+
reader,
|
|
211
|
+
limits.label,
|
|
212
|
+
"payload",
|
|
213
|
+
);
|
|
171
214
|
const reservedBytes = reader.readExact(4, "reserved bytes");
|
|
172
215
|
const signablePrefixLength = reader.position;
|
|
173
216
|
if (reader.readU8("signatures option") !== 1) {
|
|
174
|
-
throw new Error(
|
|
217
|
+
throw new Error(`${limits.label} EntryV0 must contain signatures`);
|
|
175
218
|
}
|
|
176
219
|
reader.expectU8(0, "signatures variant");
|
|
177
|
-
|
|
178
|
-
|
|
220
|
+
const signatureCount = reader.readU32("signature count");
|
|
221
|
+
if (
|
|
222
|
+
signatureCount < limits.minimumSignatures ||
|
|
223
|
+
signatureCount > limits.maximumSignatures ||
|
|
224
|
+
signatureCount > Math.floor(reader.remaining / 6)
|
|
225
|
+
) {
|
|
226
|
+
const expected =
|
|
227
|
+
limits.minimumSignatures === 1 && limits.maximumSignatures === 1
|
|
228
|
+
? "exactly one signature"
|
|
229
|
+
: limits.minimumSignatures === limits.maximumSignatures
|
|
230
|
+
? `exactly ${limits.minimumSignatures}`
|
|
231
|
+
: `${limits.minimumSignatures}-${limits.maximumSignatures} signatures`;
|
|
232
|
+
throw new Error(`${limits.label} EntryV0 must contain ${expected}`);
|
|
233
|
+
}
|
|
234
|
+
for (let index = 0; index < signatureCount; index++) {
|
|
235
|
+
scanSignatureV2(
|
|
236
|
+
readPublicWrapperV2(reader, limits.label, "signature"),
|
|
237
|
+
limits.label,
|
|
238
|
+
);
|
|
179
239
|
}
|
|
180
|
-
const signatureBytes = readPublicWrapperV2(reader, "signature");
|
|
181
240
|
const hashOption = reader.readU8("hash option");
|
|
182
241
|
if (hashOption === 1) {
|
|
183
242
|
reader.readBytes("hash");
|
|
184
243
|
} else if (hashOption !== 0) {
|
|
185
|
-
throw new Error(
|
|
244
|
+
throw new Error(`${limits.label} EntryV0 has invalid hash option`);
|
|
186
245
|
}
|
|
187
246
|
reader.expectDone("storage");
|
|
188
247
|
|
|
189
|
-
const directParentCount =
|
|
190
|
-
const payloadBytes =
|
|
191
|
-
scanSignatureStructureV2(signatureBytes);
|
|
248
|
+
const directParentCount = scanMetaV2(metaBytes, limits);
|
|
249
|
+
const payloadBytes = scanPayloadV2(payloadContainerBytes, limits.label);
|
|
192
250
|
const signableBytes = new Uint8Array(signablePrefixLength + 2);
|
|
193
251
|
signableBytes.set(entryBytes.subarray(0, signablePrefixLength));
|
|
252
|
+
|
|
253
|
+
const entry = deserialize(entryBytes, Entry);
|
|
254
|
+
if (!(entry instanceof EntryV0)) {
|
|
255
|
+
throw new Error(`${limits.label} entry must use EntryV0`);
|
|
256
|
+
}
|
|
257
|
+
if (!equals(entryBytes, serialize(entry))) {
|
|
258
|
+
throw new Error(`${limits.label} EntryV0 storage is not canonical`);
|
|
259
|
+
}
|
|
260
|
+
if (
|
|
261
|
+
!(entry._meta instanceof DecryptedThing) ||
|
|
262
|
+
!(entry._payload instanceof DecryptedThing)
|
|
263
|
+
) {
|
|
264
|
+
throw new Error(
|
|
265
|
+
`${limits.label} EntryV0 metadata and payload must be public`,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
entry._signatures === undefined ||
|
|
270
|
+
entry._signatures.signatures.length !== signatureCount ||
|
|
271
|
+
entry._signatures.signatures.some(
|
|
272
|
+
(signature) => !(signature instanceof DecryptedThing),
|
|
273
|
+
)
|
|
274
|
+
) {
|
|
275
|
+
throw new Error(`${limits.label} EntryV0 signatures must be public`);
|
|
276
|
+
}
|
|
277
|
+
entry.init({ encoding: NO_ENCODING });
|
|
278
|
+
const meta = entry.meta;
|
|
279
|
+
if (!equals(metaBytes, serialize(meta))) {
|
|
280
|
+
throw new Error(`${limits.label} EntryV0 nested encoding is not canonical`);
|
|
281
|
+
}
|
|
282
|
+
if (!equals(payloadBytes, entry.payload.data)) {
|
|
283
|
+
throw new Error(`${limits.label} EntryV0 payload framing is inconsistent`);
|
|
284
|
+
}
|
|
285
|
+
const signatures = entry.signatures;
|
|
286
|
+
if (signatures.length !== signatureCount) {
|
|
287
|
+
throw new Error(
|
|
288
|
+
`${limits.label} EntryV0 signature framing is inconsistent`,
|
|
289
|
+
);
|
|
290
|
+
}
|
|
194
291
|
return {
|
|
292
|
+
entry,
|
|
293
|
+
meta,
|
|
294
|
+
signatures,
|
|
195
295
|
metaBytes,
|
|
196
296
|
payloadBytes,
|
|
197
297
|
signableBytes,
|
|
198
298
|
reservedBytes,
|
|
199
299
|
hasHash: hashOption === 1,
|
|
200
300
|
directParentCount,
|
|
301
|
+
signatureCount,
|
|
201
302
|
};
|
|
202
303
|
};
|
|
203
304
|
|
|
305
|
+
const SECP256K1_SIGNATURE_TEXT_BYTES = 132;
|
|
306
|
+
const SECP256K1_LOW_S_MAX_HEX =
|
|
307
|
+
"7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0";
|
|
308
|
+
|
|
309
|
+
const isLowerHexByteV2 = (value: number): boolean =>
|
|
310
|
+
(value >= 0x30 && value <= 0x39) || (value >= 0x61 && value <= 0x66);
|
|
311
|
+
|
|
312
|
+
export const assertCanonicalSecp256k1SignatureV2 = (
|
|
313
|
+
signature: Uint8Array,
|
|
314
|
+
label: string,
|
|
315
|
+
): void => {
|
|
316
|
+
if (
|
|
317
|
+
signature.byteLength !== SECP256K1_SIGNATURE_TEXT_BYTES ||
|
|
318
|
+
signature[0] !== 0x30 ||
|
|
319
|
+
signature[1] !== 0x78
|
|
320
|
+
) {
|
|
321
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
322
|
+
}
|
|
323
|
+
for (let index = 2; index < signature.byteLength; index++) {
|
|
324
|
+
if (!isLowerHexByteV2(signature[index]!)) {
|
|
325
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (
|
|
329
|
+
signature[130] !== 0x31 ||
|
|
330
|
+
(signature[131] !== 0x62 && signature[131] !== 0x63)
|
|
331
|
+
) {
|
|
332
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
333
|
+
}
|
|
334
|
+
for (let index = 0; index < SECP256K1_LOW_S_MAX_HEX.length; index++) {
|
|
335
|
+
const actual = signature[66 + index]!;
|
|
336
|
+
const maximum = SECP256K1_LOW_S_MAX_HEX.charCodeAt(index);
|
|
337
|
+
if (actual < maximum) break;
|
|
338
|
+
if (actual > maximum) {
|
|
339
|
+
throw new Error(`${label} EntryV0 secp256k1 signature is not canonical`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export const canonicalDirectParentsV2 = (
|
|
345
|
+
parents: readonly string[],
|
|
346
|
+
label: string,
|
|
347
|
+
): Array<{ cid: string; digest: Uint8Array }> => {
|
|
348
|
+
const seen = new Set<string>();
|
|
349
|
+
return parents.map((cid) => {
|
|
350
|
+
let parsed: ReturnType<typeof cidifyString>;
|
|
351
|
+
try {
|
|
352
|
+
parsed = cidifyString(cid);
|
|
353
|
+
} catch {
|
|
354
|
+
throw new Error(
|
|
355
|
+
`${label} EntryV0 direct parents must use canonical CIDv1/raw/sha2-256`,
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
if (
|
|
359
|
+
!cid ||
|
|
360
|
+
cid.length > TRUSTED_NETWORK_V2_MAX_CANONICAL_ENTRY_CID_CHARACTERS ||
|
|
361
|
+
parsed.version !== 1 ||
|
|
362
|
+
parsed.code !== codecMap.raw.code ||
|
|
363
|
+
parsed.multihash.code !== defaultHasher.code ||
|
|
364
|
+
parsed.multihash.digest.byteLength !== 32 ||
|
|
365
|
+
stringifyCid(parsed) !== cid
|
|
366
|
+
) {
|
|
367
|
+
throw new Error(
|
|
368
|
+
`${label} EntryV0 direct parents must use canonical CIDv1/raw/sha2-256`,
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
if (seen.has(cid)) {
|
|
372
|
+
throw new Error(`${label} EntryV0 direct parents must be unique`);
|
|
373
|
+
}
|
|
374
|
+
seen.add(cid);
|
|
375
|
+
return {
|
|
376
|
+
cid,
|
|
377
|
+
digest: copyUint8ArrayWithLengthV2(
|
|
378
|
+
parsed.multihash.digest,
|
|
379
|
+
parsed.multihash.digest.byteLength,
|
|
380
|
+
),
|
|
381
|
+
};
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export type AuthenticatedAuthorityEntryV0V2 = {
|
|
386
|
+
descriptor: NetworkDescriptorV2;
|
|
387
|
+
entryBytes: Uint8Array;
|
|
388
|
+
entry: CanonicalPublicEntryV0ScanV2["entry"];
|
|
389
|
+
metaBytes: Uint8Array;
|
|
390
|
+
payloadBytes: Uint8Array;
|
|
391
|
+
reservedBytes: Uint8Array;
|
|
392
|
+
hasHash: boolean;
|
|
393
|
+
directParentCount: number;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export type AuthorityEntryV0ProfileV2 = (
|
|
397
|
+
entry: AuthenticatedAuthorityEntryV0V2,
|
|
398
|
+
) => void;
|
|
399
|
+
|
|
204
400
|
const validateMaximumEntryBytesV2 = (maximumEntryBytes: number): void => {
|
|
205
401
|
if (!Number.isSafeInteger(maximumEntryBytes) || maximumEntryBytes < 1) {
|
|
206
402
|
throw new Error("Invalid internal authority EntryV0 byte limit");
|
|
@@ -239,7 +435,11 @@ export const authenticateCapturedAuthorityEntryV0V2 = async (
|
|
|
239
435
|
): Promise<AuthenticatedAuthorityEntryV0V2> => {
|
|
240
436
|
assertNetworkDescriptorV2(descriptor);
|
|
241
437
|
const authorityBytes = serialize(descriptor.policyAuthority);
|
|
242
|
-
const scanned =
|
|
438
|
+
const scanned = scanCanonicalPublicEntryV0V2(capturedEntryBytes, {
|
|
439
|
+
label: "Authority",
|
|
440
|
+
minimumSignatures: 1,
|
|
441
|
+
maximumSignatures: 1,
|
|
442
|
+
});
|
|
243
443
|
const capturedDescriptor = deserialize(
|
|
244
444
|
serialize(descriptor),
|
|
245
445
|
NetworkDescriptorV2,
|
|
@@ -248,45 +448,16 @@ export const authenticateCapturedAuthorityEntryV0V2 = async (
|
|
|
248
448
|
if (!equals(serialize(capturedDescriptor.policyAuthority), authorityBytes)) {
|
|
249
449
|
throw new Error("Network descriptor changed during capture");
|
|
250
450
|
}
|
|
251
|
-
const
|
|
252
|
-
if (!(
|
|
253
|
-
throw new Error("Authority entry must use EntryV0");
|
|
254
|
-
}
|
|
255
|
-
if (!equals(capturedEntryBytes, serialize(entry))) {
|
|
256
|
-
throw new Error("Authority EntryV0 storage is not canonical");
|
|
257
|
-
}
|
|
258
|
-
if (!(entry._meta instanceof DecryptedThing)) {
|
|
259
|
-
throw new Error("Authority EntryV0 metadata must be public");
|
|
260
|
-
}
|
|
261
|
-
if (!(entry._payload instanceof DecryptedThing)) {
|
|
262
|
-
throw new Error("Authority EntryV0 payload must be public");
|
|
263
|
-
}
|
|
264
|
-
if (
|
|
265
|
-
entry._signatures === undefined ||
|
|
266
|
-
entry._signatures.signatures.length !== 1 ||
|
|
267
|
-
!(entry._signatures.signatures[0] instanceof DecryptedThing)
|
|
268
|
-
) {
|
|
269
|
-
throw new Error("Authority EntryV0 must contain one public signature");
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
entry.init({ encoding: NO_ENCODING });
|
|
273
|
-
const payload = entry.payload;
|
|
274
|
-
const signatures = entry.signatures;
|
|
275
|
-
if (
|
|
276
|
-
signatures.length !== 1 ||
|
|
277
|
-
!equals(serialize(signatures[0]!.publicKey), authorityBytes)
|
|
278
|
-
) {
|
|
451
|
+
const signatures = scanned.signatures;
|
|
452
|
+
if (!equals(serialize(signatures[0]!.publicKey), authorityBytes)) {
|
|
279
453
|
throw new Error("Authority EntryV0 signer is not the policy authority");
|
|
280
454
|
}
|
|
281
|
-
if (!equals(scanned.payloadBytes, payload.data)) {
|
|
282
|
-
throw new Error("Authority EntryV0 payload framing is inconsistent");
|
|
283
|
-
}
|
|
284
455
|
const authenticated: AuthenticatedAuthorityEntryV0V2 = {
|
|
285
456
|
descriptor: capturedDescriptor,
|
|
286
457
|
entryBytes: capturedEntryBytes,
|
|
287
|
-
entry,
|
|
458
|
+
entry: scanned.entry,
|
|
288
459
|
metaBytes: scanned.metaBytes,
|
|
289
|
-
payloadBytes:
|
|
460
|
+
payloadBytes: scanned.payloadBytes,
|
|
290
461
|
reservedBytes: scanned.reservedBytes,
|
|
291
462
|
hasHash: scanned.hasHash,
|
|
292
463
|
directParentCount: scanned.directParentCount,
|
|
@@ -302,7 +473,6 @@ export const authenticateCapturedAuthorityEntryV0V2 = async (
|
|
|
302
473
|
if (!signatureIsValid) {
|
|
303
474
|
throw new Error("Authority EntryV0 signature is invalid");
|
|
304
475
|
}
|
|
305
|
-
|
|
306
476
|
return authenticated;
|
|
307
477
|
};
|
|
308
478
|
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { serialize } from "@dao-xyz/borsh";
|
|
2
|
-
import {
|
|
3
|
-
calculateRawCid,
|
|
4
|
-
cidifyString,
|
|
5
|
-
codecMap,
|
|
6
|
-
defaultHasher,
|
|
7
|
-
stringifyCid,
|
|
8
|
-
} from "@peerbit/blocks-interface";
|
|
2
|
+
import { calculateRawCid } from "@peerbit/blocks-interface";
|
|
9
3
|
import { EntryType, type Meta } from "@peerbit/log";
|
|
10
4
|
import { equals } from "uint8arrays";
|
|
11
5
|
import {
|
|
12
6
|
type AuthenticatedAuthorityEntryV0V2,
|
|
7
|
+
assertCanonicalSecp256k1SignatureV2,
|
|
13
8
|
authenticateAuthorityEntryV0V2,
|
|
9
|
+
canonicalDirectParentsV2,
|
|
14
10
|
} from "./v2-authority-entry.js";
|
|
15
11
|
import {
|
|
16
12
|
NetworkDescriptorV2,
|
|
@@ -27,81 +23,6 @@ const RESOURCE_FENCE_AUTHORITY_LIMITS_V2 = Object.freeze({
|
|
|
27
23
|
maximumEntryBytes: TRUSTED_NETWORK_V2_MAX_RESOURCE_FENCE_ENTRY_BYTES,
|
|
28
24
|
});
|
|
29
25
|
|
|
30
|
-
const SECP256K1_SIGNATURE_TEXT_BYTES = 132;
|
|
31
|
-
const SECP256K1_LOW_S_MAX_HEX =
|
|
32
|
-
"7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0";
|
|
33
|
-
|
|
34
|
-
const isLowerHexByteV2 = (value: number): boolean =>
|
|
35
|
-
(value >= 0x30 && value <= 0x39) || (value >= 0x61 && value <= 0x66);
|
|
36
|
-
|
|
37
|
-
const assertCanonicalSecp256k1SignatureV2 = (signature: Uint8Array): void => {
|
|
38
|
-
if (
|
|
39
|
-
signature.byteLength !== SECP256K1_SIGNATURE_TEXT_BYTES ||
|
|
40
|
-
signature[0] !== 0x30 ||
|
|
41
|
-
signature[1] !== 0x78
|
|
42
|
-
) {
|
|
43
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
44
|
-
}
|
|
45
|
-
for (let i = 2; i < signature.byteLength; i++) {
|
|
46
|
-
if (!isLowerHexByteV2(signature[i]!)) {
|
|
47
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (
|
|
51
|
-
signature[130] !== 0x31 ||
|
|
52
|
-
(signature[131] !== 0x62 && signature[131] !== 0x63)
|
|
53
|
-
) {
|
|
54
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
55
|
-
}
|
|
56
|
-
for (let i = 0; i < SECP256K1_LOW_S_MAX_HEX.length; i++) {
|
|
57
|
-
const actual = signature[66 + i]!;
|
|
58
|
-
const maximum = SECP256K1_LOW_S_MAX_HEX.charCodeAt(i);
|
|
59
|
-
if (actual < maximum) break;
|
|
60
|
-
if (actual > maximum) {
|
|
61
|
-
throw new Error("Authority EntryV0 secp256k1 signature is not canonical");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const canonicalDirectParentsV2 = (
|
|
67
|
-
parents: string[],
|
|
68
|
-
): Array<{ cid: string; digest: Uint8Array }> => {
|
|
69
|
-
const seen = new Set<string>();
|
|
70
|
-
return parents.map((cid) => {
|
|
71
|
-
let parsed: ReturnType<typeof cidifyString>;
|
|
72
|
-
try {
|
|
73
|
-
parsed = cidifyString(cid);
|
|
74
|
-
} catch {
|
|
75
|
-
throw new Error(
|
|
76
|
-
"Authority EntryV0 direct parents must use canonical CIDv1/raw/sha2-256",
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
if (
|
|
80
|
-
!cid ||
|
|
81
|
-
parsed.version !== 1 ||
|
|
82
|
-
parsed.code !== codecMap.raw.code ||
|
|
83
|
-
parsed.multihash.code !== defaultHasher.code ||
|
|
84
|
-
parsed.multihash.digest.byteLength !== 32 ||
|
|
85
|
-
stringifyCid(parsed) !== cid
|
|
86
|
-
) {
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Authority EntryV0 direct parents must use canonical CIDv1/raw/sha2-256",
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
if (seen.has(cid)) {
|
|
92
|
-
throw new Error("Authority EntryV0 direct parents must be unique");
|
|
93
|
-
}
|
|
94
|
-
seen.add(cid);
|
|
95
|
-
return {
|
|
96
|
-
cid,
|
|
97
|
-
digest: copyUint8ArrayWithLengthV2(
|
|
98
|
-
parsed.multihash.digest,
|
|
99
|
-
parsed.multihash.digest.byteLength,
|
|
100
|
-
),
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
105
26
|
type ResourceFenceEntryV0ProfileV2 = {
|
|
106
27
|
meta: Meta;
|
|
107
28
|
directParents: Array<{ cid: string; digest: Uint8Array }>;
|
|
@@ -156,9 +77,12 @@ const assertResourceFenceEntryV0ProfileV2 = (
|
|
|
156
77
|
}
|
|
157
78
|
const signature = authenticated.entry.signatures[0]!;
|
|
158
79
|
if (serialize(signature.publicKey)[0] === 1) {
|
|
159
|
-
assertCanonicalSecp256k1SignatureV2(signature.signature);
|
|
80
|
+
assertCanonicalSecp256k1SignatureV2(signature.signature, "Authority");
|
|
160
81
|
}
|
|
161
|
-
return {
|
|
82
|
+
return {
|
|
83
|
+
meta,
|
|
84
|
+
directParents: canonicalDirectParentsV2(meta.next, "Authority"),
|
|
85
|
+
};
|
|
162
86
|
};
|
|
163
87
|
|
|
164
88
|
export type AuthenticatedResourceFenceEntryV2 = Readonly<{
|