@bcts/envelope 1.0.0-alpha.18 → 1.0.0-alpha.20
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/index.cjs +32 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +32 -11
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +31 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
- package/src/base/error.ts +6 -0
- package/src/extension/edge.ts +39 -17
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ARID, COMPRESSED, Digest, Digest as Digest$1, ENCRYPTED, ENVELOPE, EncapsulationPublicKey as PublicKeyBase, EncapsulationScheme, EncryptedKey, LEAF, Nonce, PrivateKeyBase as PrivateKeyBase$1, PrivateKeys, PrivateKeys as PrivateKeyBase, PublicKeys, SSKRSecret, SSKRShareCbor, SSKRShareCbor as SSKRShareCbor$1, Salt, SealedMessage as ComponentsSealedMessage, SealedMessage as SealedMessage$1, Seed, Signature, Signature as Signature$1, SignatureScheme, SigningPrivateKey, SigningPrivateKey as SigningPrivateKey$1, SigningPublicKey, SigningPublicKey as SigningPublicKey$1, SymmetricKey, SymmetricKey as SymmetricKey$1, URI, UUID, XID, isEncrypter, sskrCombineShares, sskrGenerateShares, sskrGenerateUsing } from "@bcts/components";
|
|
2
2
|
import { CborMap, MajorType, TAG_ENCODED_CBOR, TagsStore, asArray, asByteString, asCborArray, asCborMap, asMap, asTaggedValue, asText, cbor, cborData, decodeCbor, diagnosticOpt, getGlobalTagsStore, isArray, isBytes, isMap, isNaN, isNegative, isNull, isNumber, isSimple, isTagged, isText, isUnsigned, tagValue, tagsForValues, toTaggedValue, tryExpectedTaggedValue, tryIntoBool, tryIntoByteString, tryIntoText } from "@bcts/dcbor";
|
|
3
|
-
import { ATTACHMENT, ATTACHMENT as ATTACHMENT$1, BODY, CONFORMS_TO, CONFORMS_TO as CONFORMS_TO$1, CONTENT, DATE, EDGE, EDGE as EDGE$1, ERROR, HAS_RECIPIENT as HAS_RECIPIENT$1, HAS_SECRET, IS_A, IS_A as IS_A$1, KNOWN_VALUES, KnownValue, KnownValuesStore, NOTE, NOTE as NOTE$1, OK_VALUE, POSITION, RESULT, SALT as SALT$1, SIGNED, SIGNED as SIGNED$1, SOURCE, SOURCE as SOURCE$1, SSKR_SHARE, TAG_KNOWN_VALUE, TARGET, TARGET as TARGET$1, UNIT, UNKNOWN_VALUE, VENDOR, VENDOR as VENDOR$1 } from "@bcts/known-values";
|
|
3
|
+
import { ATTACHMENT, ATTACHMENT as ATTACHMENT$1, BODY, CONFORMS_TO, CONFORMS_TO as CONFORMS_TO$1, CONTENT, DATE, EDGE, EDGE as EDGE$1, ERROR, HAS_RECIPIENT as HAS_RECIPIENT$1, HAS_SECRET, IS_A, IS_A as IS_A$1, IS_A_RAW, KNOWN_VALUES, KnownValue, KnownValuesStore, NOTE, NOTE as NOTE$1, OK_VALUE, POSITION, RESULT, SALT as SALT$1, SIGNED, SIGNED as SIGNED$1, SOURCE, SOURCE as SOURCE$1, SOURCE_RAW, SSKR_SHARE, TAG_KNOWN_VALUE, TARGET, TARGET as TARGET$1, TARGET_RAW, UNIT, UNKNOWN_VALUE, VENDOR, VENDOR as VENDOR$1 } from "@bcts/known-values";
|
|
4
4
|
import * as pako from "pako";
|
|
5
5
|
import { SYMMETRIC_NONCE_SIZE, aeadChaCha20Poly1305DecryptWithAad, aeadChaCha20Poly1305EncryptWithAad } from "@bcts/crypto";
|
|
6
6
|
import { SecureRandomNumberGenerator, rngNextInClosedRangeI32, rngRandomData } from "@bcts/rand";
|
|
@@ -34,6 +34,7 @@ let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
|
|
|
34
34
|
ErrorCode["EDGE_DUPLICATE_IS_A"] = "EDGE_DUPLICATE_IS_A";
|
|
35
35
|
ErrorCode["EDGE_DUPLICATE_SOURCE"] = "EDGE_DUPLICATE_SOURCE";
|
|
36
36
|
ErrorCode["EDGE_DUPLICATE_TARGET"] = "EDGE_DUPLICATE_TARGET";
|
|
37
|
+
ErrorCode["EDGE_UNEXPECTED_ASSERTION"] = "EDGE_UNEXPECTED_ASSERTION";
|
|
37
38
|
ErrorCode["NONEXISTENT_EDGE"] = "NONEXISTENT_EDGE";
|
|
38
39
|
ErrorCode["AMBIGUOUS_EDGE"] = "AMBIGUOUS_EDGE";
|
|
39
40
|
ErrorCode["ALREADY_COMPRESSED"] = "ALREADY_COMPRESSED";
|
|
@@ -126,6 +127,9 @@ var EnvelopeError = class EnvelopeError extends Error {
|
|
|
126
127
|
static edgeDuplicateTarget() {
|
|
127
128
|
return new EnvelopeError(ErrorCode.EDGE_DUPLICATE_TARGET, "edge has duplicate 'target' assertions");
|
|
128
129
|
}
|
|
130
|
+
static edgeUnexpectedAssertion() {
|
|
131
|
+
return new EnvelopeError(ErrorCode.EDGE_UNEXPECTED_ASSERTION, "edge has unexpected assertion");
|
|
132
|
+
}
|
|
129
133
|
static nonexistentEdge() {
|
|
130
134
|
return new EnvelopeError(ErrorCode.NONEXISTENT_EDGE, "nonexistent edge");
|
|
131
135
|
}
|
|
@@ -2257,7 +2261,7 @@ Envelope.prototype.edges = function() {
|
|
|
2257
2261
|
*
|
|
2258
2262
|
* An edge may be wrapped (signed) or unwrapped. The inner envelope
|
|
2259
2263
|
* must have exactly three assertion predicates: `'isA'`, `'source'`,
|
|
2260
|
-
* and `'target'`.
|
|
2264
|
+
* and `'target'`. No other assertions are permitted on the edge subject.
|
|
2261
2265
|
*
|
|
2262
2266
|
* Equivalent to Rust's `Envelope::validate_edge()`.
|
|
2263
2267
|
*
|
|
@@ -2265,15 +2269,31 @@ Envelope.prototype.edges = function() {
|
|
|
2265
2269
|
*/
|
|
2266
2270
|
Envelope.prototype.validateEdge = function() {
|
|
2267
2271
|
const inner = this.subject().isWrapped() ? this.subject().tryUnwrap() : this;
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2272
|
+
let seenIsA = false;
|
|
2273
|
+
let seenSource = false;
|
|
2274
|
+
let seenTarget = false;
|
|
2275
|
+
for (const assertion of inner.assertions()) {
|
|
2276
|
+
const kv = assertion.tryPredicate().asKnownValue();
|
|
2277
|
+
if (kv === void 0) throw EnvelopeError.edgeUnexpectedAssertion();
|
|
2278
|
+
switch (kv.valueBigInt()) {
|
|
2279
|
+
case IS_A_RAW:
|
|
2280
|
+
if (seenIsA) throw EnvelopeError.edgeDuplicateIsA();
|
|
2281
|
+
seenIsA = true;
|
|
2282
|
+
break;
|
|
2283
|
+
case SOURCE_RAW:
|
|
2284
|
+
if (seenSource) throw EnvelopeError.edgeDuplicateSource();
|
|
2285
|
+
seenSource = true;
|
|
2286
|
+
break;
|
|
2287
|
+
case TARGET_RAW:
|
|
2288
|
+
if (seenTarget) throw EnvelopeError.edgeDuplicateTarget();
|
|
2289
|
+
seenTarget = true;
|
|
2290
|
+
break;
|
|
2291
|
+
default: throw EnvelopeError.edgeUnexpectedAssertion();
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
if (!seenIsA) throw EnvelopeError.edgeMissingIsA();
|
|
2295
|
+
if (!seenSource) throw EnvelopeError.edgeMissingSource();
|
|
2296
|
+
if (!seenTarget) throw EnvelopeError.edgeMissingTarget();
|
|
2277
2297
|
};
|
|
2278
2298
|
/**
|
|
2279
2299
|
* Extracts the `'isA'` assertion object from an edge envelope.
|