@tinycloud/sdk-services 2.2.0 → 2.3.0-beta.2
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/encryption/index.cjs +42 -25
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +25 -25
- package/dist/encryption/index.d.ts +25 -25
- package/dist/encryption/index.js +42 -25
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +42 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -100,12 +100,12 @@ interface InlineEncryptedEnvelope {
|
|
|
100
100
|
/**
|
|
101
101
|
* Node-published network descriptor. The node DB is authoritative; a
|
|
102
102
|
* cached copy may also live under
|
|
103
|
-
* `.well-known/encryption/network/<name>` in the
|
|
103
|
+
* `.well-known/encryption/network/<name>` in the owner's account
|
|
104
104
|
* space (a discovery record only).
|
|
105
105
|
*/
|
|
106
106
|
interface NetworkDescriptor {
|
|
107
107
|
networkId: string;
|
|
108
|
-
|
|
108
|
+
ownerDid: string;
|
|
109
109
|
name: string;
|
|
110
110
|
members: ReadonlyArray<{
|
|
111
111
|
nodeId: string;
|
|
@@ -234,7 +234,7 @@ interface ReceiverKeySigner {
|
|
|
234
234
|
}
|
|
235
235
|
/** Capability proof material accompanying a decrypt invocation. */
|
|
236
236
|
interface DecryptCapabilityProof {
|
|
237
|
-
/** Delegation chain CIDs rooted at the network
|
|
237
|
+
/** Delegation chain CIDs rooted at the network owner DID. */
|
|
238
238
|
proofs: ReadonlyArray<string>;
|
|
239
239
|
/** Optional Authorization header value to use instead of building one. */
|
|
240
240
|
authorization?: string;
|
|
@@ -334,7 +334,7 @@ type CanonicalJson = Json;
|
|
|
334
334
|
* descriptor (`state`, `publicEncryptionKey`, `keyVersion`, ...).
|
|
335
335
|
* 2. If the node is unreachable, fall back to the cached discovery
|
|
336
336
|
* record at `.well-known/encryption/network/<name>` inside the
|
|
337
|
-
*
|
|
337
|
+
* owner's public space.
|
|
338
338
|
*
|
|
339
339
|
* The node DB is authoritative on conflict; cached records are
|
|
340
340
|
* advisory only.
|
|
@@ -351,16 +351,16 @@ interface NodeDescriptorFetcher {
|
|
|
351
351
|
}
|
|
352
352
|
interface WellKnownDescriptorFetcher {
|
|
353
353
|
/**
|
|
354
|
-
* Read the cached well-known descriptor by
|
|
354
|
+
* Read the cached well-known descriptor by owner DID + network name.
|
|
355
355
|
* Returns null if no record exists or the record is unreadable.
|
|
356
356
|
*/
|
|
357
|
-
fetchWellKnown(
|
|
357
|
+
fetchWellKnown(ownerDid: string, discoveryKey: string): Promise<NetworkDescriptor | null>;
|
|
358
358
|
}
|
|
359
359
|
interface DiscoverNetworkInput {
|
|
360
|
-
/** Either a networkId URN or a bare network name (paired with `
|
|
360
|
+
/** Either a networkId URN or a bare network name (paired with `ownerDid`). */
|
|
361
361
|
identifier: string;
|
|
362
362
|
/** Required when identifier is a bare name. */
|
|
363
|
-
|
|
363
|
+
ownerDid?: string;
|
|
364
364
|
node?: NodeDescriptorFetcher;
|
|
365
365
|
wellKnown?: WellKnownDescriptorFetcher;
|
|
366
366
|
}
|
|
@@ -368,7 +368,7 @@ interface DiscoverNetworkInput {
|
|
|
368
368
|
* Resolve a network descriptor. The node fetcher is preferred; the
|
|
369
369
|
* well-known fallback is used only on transport failure.
|
|
370
370
|
*
|
|
371
|
-
* The returned descriptor is sanity-checked: `networkId`, `
|
|
371
|
+
* The returned descriptor is sanity-checked: `networkId`, `ownerDid`,
|
|
372
372
|
* and `name` must agree with the URN, and the public key field must
|
|
373
373
|
* be non-empty.
|
|
374
374
|
*/
|
|
@@ -431,10 +431,10 @@ interface IEncryptionService extends IService {
|
|
|
431
431
|
*
|
|
432
432
|
* `identifier` may be either a full networkId URN
|
|
433
433
|
* (`urn:tinycloud:encryption:did:key:...:default`) or a bare network
|
|
434
|
-
* name. The bare name form requires the
|
|
435
|
-
* `
|
|
434
|
+
* name. The bare name form requires the owner DID to be supplied via
|
|
435
|
+
* `ownerDid`.
|
|
436
436
|
*/
|
|
437
|
-
discoverNetwork(identifier: string,
|
|
437
|
+
discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
|
|
438
438
|
/**
|
|
439
439
|
* Encrypt plaintext to the network's public key locally. The result
|
|
440
440
|
* is an inline envelope ready to persist (KV/SQL).
|
|
@@ -447,7 +447,7 @@ interface IEncryptionService extends IService {
|
|
|
447
447
|
* decrypt invocation, POST it to the node, verify the signed
|
|
448
448
|
* response, open `wrappedKey`, and decrypt the payload locally.
|
|
449
449
|
*
|
|
450
|
-
* The capability proof must root at the network
|
|
450
|
+
* The capability proof must root at the network owner DID embedded
|
|
451
451
|
* in the envelope's networkId.
|
|
452
452
|
*/
|
|
453
453
|
decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
|
|
@@ -497,7 +497,7 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
|
|
|
497
497
|
constructor(config: EncryptionServiceConfig);
|
|
498
498
|
get config(): EncryptionServiceConfig;
|
|
499
499
|
private get crypto();
|
|
500
|
-
discoverNetwork(identifier: string,
|
|
500
|
+
discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
|
|
501
501
|
encryptToNetwork(networkId: string, plaintext: Uint8Array, options?: EncryptToNetworkOptions): Promise<Result<InlineEncryptedEnvelope, EncryptionError>>;
|
|
502
502
|
decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
|
|
503
503
|
}
|
|
@@ -505,27 +505,27 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
|
|
|
505
505
|
/**
|
|
506
506
|
* TinyCloud encryption network identifiers.
|
|
507
507
|
*
|
|
508
|
-
* A network id is `urn:tinycloud:encryption:<
|
|
509
|
-
* `
|
|
508
|
+
* A network id is `urn:tinycloud:encryption:<ownerDid>:<network>` where
|
|
509
|
+
* `ownerDid` is the owner's DID and `network` is a
|
|
510
510
|
* non-empty label drawn from `[a-z0-9][a-z0-9-]*`.
|
|
511
511
|
*
|
|
512
|
-
* The embedded
|
|
512
|
+
* The embedded owner DID is the root authority for the network: any
|
|
513
513
|
* delegation chain ending in a `tinycloud.encryption/decrypt` grant on
|
|
514
|
-
* the network must root at this
|
|
514
|
+
* the network must root at this owner DID.
|
|
515
515
|
*/
|
|
516
516
|
interface ParsedNetworkId {
|
|
517
517
|
/** The full URN string. */
|
|
518
518
|
networkId: string;
|
|
519
|
-
/**
|
|
520
|
-
|
|
521
|
-
/** Network label (the suffix after the
|
|
519
|
+
/** Owner DID embedded in the URN (the network's root authority). */
|
|
520
|
+
ownerDid: string;
|
|
521
|
+
/** Network label (the suffix after the owner DID). */
|
|
522
522
|
name: string;
|
|
523
523
|
}
|
|
524
524
|
declare class NetworkIdError extends Error {
|
|
525
525
|
constructor(message: string);
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
528
|
-
* Parse a network id string into its
|
|
528
|
+
* Parse a network id string into its owner DID and name components.
|
|
529
529
|
*
|
|
530
530
|
* Throws {@link NetworkIdError} when the input does not match
|
|
531
531
|
* `urn:tinycloud:encryption:<did>:<name>`, when the embedded DID is
|
|
@@ -533,17 +533,17 @@ declare class NetworkIdError extends Error {
|
|
|
533
533
|
*/
|
|
534
534
|
declare function parseNetworkId(networkId: string): ParsedNetworkId;
|
|
535
535
|
/**
|
|
536
|
-
* Construct a network id URN from
|
|
536
|
+
* Construct a network id URN from an owner DID and a network name.
|
|
537
537
|
* Validates inputs and throws {@link NetworkIdError} on bad shape.
|
|
538
538
|
*/
|
|
539
|
-
declare function buildNetworkId(
|
|
539
|
+
declare function buildNetworkId(ownerDid: string, name: string): string;
|
|
540
540
|
/**
|
|
541
541
|
* Returns true when {@link networkId} is a syntactically valid network URN.
|
|
542
542
|
*/
|
|
543
543
|
declare function isNetworkId(networkId: unknown): networkId is string;
|
|
544
544
|
/**
|
|
545
545
|
* Resolve the discovery key used to look up a network's descriptor under
|
|
546
|
-
*
|
|
546
|
+
* an owner's public account-space.
|
|
547
547
|
*
|
|
548
548
|
* Format: `.well-known/encryption/network/<name>`.
|
|
549
549
|
*/
|
|
@@ -100,12 +100,12 @@ interface InlineEncryptedEnvelope {
|
|
|
100
100
|
/**
|
|
101
101
|
* Node-published network descriptor. The node DB is authoritative; a
|
|
102
102
|
* cached copy may also live under
|
|
103
|
-
* `.well-known/encryption/network/<name>` in the
|
|
103
|
+
* `.well-known/encryption/network/<name>` in the owner's account
|
|
104
104
|
* space (a discovery record only).
|
|
105
105
|
*/
|
|
106
106
|
interface NetworkDescriptor {
|
|
107
107
|
networkId: string;
|
|
108
|
-
|
|
108
|
+
ownerDid: string;
|
|
109
109
|
name: string;
|
|
110
110
|
members: ReadonlyArray<{
|
|
111
111
|
nodeId: string;
|
|
@@ -234,7 +234,7 @@ interface ReceiverKeySigner {
|
|
|
234
234
|
}
|
|
235
235
|
/** Capability proof material accompanying a decrypt invocation. */
|
|
236
236
|
interface DecryptCapabilityProof {
|
|
237
|
-
/** Delegation chain CIDs rooted at the network
|
|
237
|
+
/** Delegation chain CIDs rooted at the network owner DID. */
|
|
238
238
|
proofs: ReadonlyArray<string>;
|
|
239
239
|
/** Optional Authorization header value to use instead of building one. */
|
|
240
240
|
authorization?: string;
|
|
@@ -334,7 +334,7 @@ type CanonicalJson = Json;
|
|
|
334
334
|
* descriptor (`state`, `publicEncryptionKey`, `keyVersion`, ...).
|
|
335
335
|
* 2. If the node is unreachable, fall back to the cached discovery
|
|
336
336
|
* record at `.well-known/encryption/network/<name>` inside the
|
|
337
|
-
*
|
|
337
|
+
* owner's public space.
|
|
338
338
|
*
|
|
339
339
|
* The node DB is authoritative on conflict; cached records are
|
|
340
340
|
* advisory only.
|
|
@@ -351,16 +351,16 @@ interface NodeDescriptorFetcher {
|
|
|
351
351
|
}
|
|
352
352
|
interface WellKnownDescriptorFetcher {
|
|
353
353
|
/**
|
|
354
|
-
* Read the cached well-known descriptor by
|
|
354
|
+
* Read the cached well-known descriptor by owner DID + network name.
|
|
355
355
|
* Returns null if no record exists or the record is unreadable.
|
|
356
356
|
*/
|
|
357
|
-
fetchWellKnown(
|
|
357
|
+
fetchWellKnown(ownerDid: string, discoveryKey: string): Promise<NetworkDescriptor | null>;
|
|
358
358
|
}
|
|
359
359
|
interface DiscoverNetworkInput {
|
|
360
|
-
/** Either a networkId URN or a bare network name (paired with `
|
|
360
|
+
/** Either a networkId URN or a bare network name (paired with `ownerDid`). */
|
|
361
361
|
identifier: string;
|
|
362
362
|
/** Required when identifier is a bare name. */
|
|
363
|
-
|
|
363
|
+
ownerDid?: string;
|
|
364
364
|
node?: NodeDescriptorFetcher;
|
|
365
365
|
wellKnown?: WellKnownDescriptorFetcher;
|
|
366
366
|
}
|
|
@@ -368,7 +368,7 @@ interface DiscoverNetworkInput {
|
|
|
368
368
|
* Resolve a network descriptor. The node fetcher is preferred; the
|
|
369
369
|
* well-known fallback is used only on transport failure.
|
|
370
370
|
*
|
|
371
|
-
* The returned descriptor is sanity-checked: `networkId`, `
|
|
371
|
+
* The returned descriptor is sanity-checked: `networkId`, `ownerDid`,
|
|
372
372
|
* and `name` must agree with the URN, and the public key field must
|
|
373
373
|
* be non-empty.
|
|
374
374
|
*/
|
|
@@ -431,10 +431,10 @@ interface IEncryptionService extends IService {
|
|
|
431
431
|
*
|
|
432
432
|
* `identifier` may be either a full networkId URN
|
|
433
433
|
* (`urn:tinycloud:encryption:did:key:...:default`) or a bare network
|
|
434
|
-
* name. The bare name form requires the
|
|
435
|
-
* `
|
|
434
|
+
* name. The bare name form requires the owner DID to be supplied via
|
|
435
|
+
* `ownerDid`.
|
|
436
436
|
*/
|
|
437
|
-
discoverNetwork(identifier: string,
|
|
437
|
+
discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
|
|
438
438
|
/**
|
|
439
439
|
* Encrypt plaintext to the network's public key locally. The result
|
|
440
440
|
* is an inline envelope ready to persist (KV/SQL).
|
|
@@ -447,7 +447,7 @@ interface IEncryptionService extends IService {
|
|
|
447
447
|
* decrypt invocation, POST it to the node, verify the signed
|
|
448
448
|
* response, open `wrappedKey`, and decrypt the payload locally.
|
|
449
449
|
*
|
|
450
|
-
* The capability proof must root at the network
|
|
450
|
+
* The capability proof must root at the network owner DID embedded
|
|
451
451
|
* in the envelope's networkId.
|
|
452
452
|
*/
|
|
453
453
|
decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
|
|
@@ -497,7 +497,7 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
|
|
|
497
497
|
constructor(config: EncryptionServiceConfig);
|
|
498
498
|
get config(): EncryptionServiceConfig;
|
|
499
499
|
private get crypto();
|
|
500
|
-
discoverNetwork(identifier: string,
|
|
500
|
+
discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
|
|
501
501
|
encryptToNetwork(networkId: string, plaintext: Uint8Array, options?: EncryptToNetworkOptions): Promise<Result<InlineEncryptedEnvelope, EncryptionError>>;
|
|
502
502
|
decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
|
|
503
503
|
}
|
|
@@ -505,27 +505,27 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
|
|
|
505
505
|
/**
|
|
506
506
|
* TinyCloud encryption network identifiers.
|
|
507
507
|
*
|
|
508
|
-
* A network id is `urn:tinycloud:encryption:<
|
|
509
|
-
* `
|
|
508
|
+
* A network id is `urn:tinycloud:encryption:<ownerDid>:<network>` where
|
|
509
|
+
* `ownerDid` is the owner's DID and `network` is a
|
|
510
510
|
* non-empty label drawn from `[a-z0-9][a-z0-9-]*`.
|
|
511
511
|
*
|
|
512
|
-
* The embedded
|
|
512
|
+
* The embedded owner DID is the root authority for the network: any
|
|
513
513
|
* delegation chain ending in a `tinycloud.encryption/decrypt` grant on
|
|
514
|
-
* the network must root at this
|
|
514
|
+
* the network must root at this owner DID.
|
|
515
515
|
*/
|
|
516
516
|
interface ParsedNetworkId {
|
|
517
517
|
/** The full URN string. */
|
|
518
518
|
networkId: string;
|
|
519
|
-
/**
|
|
520
|
-
|
|
521
|
-
/** Network label (the suffix after the
|
|
519
|
+
/** Owner DID embedded in the URN (the network's root authority). */
|
|
520
|
+
ownerDid: string;
|
|
521
|
+
/** Network label (the suffix after the owner DID). */
|
|
522
522
|
name: string;
|
|
523
523
|
}
|
|
524
524
|
declare class NetworkIdError extends Error {
|
|
525
525
|
constructor(message: string);
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
528
|
-
* Parse a network id string into its
|
|
528
|
+
* Parse a network id string into its owner DID and name components.
|
|
529
529
|
*
|
|
530
530
|
* Throws {@link NetworkIdError} when the input does not match
|
|
531
531
|
* `urn:tinycloud:encryption:<did>:<name>`, when the embedded DID is
|
|
@@ -533,17 +533,17 @@ declare class NetworkIdError extends Error {
|
|
|
533
533
|
*/
|
|
534
534
|
declare function parseNetworkId(networkId: string): ParsedNetworkId;
|
|
535
535
|
/**
|
|
536
|
-
* Construct a network id URN from
|
|
536
|
+
* Construct a network id URN from an owner DID and a network name.
|
|
537
537
|
* Validates inputs and throws {@link NetworkIdError} on bad shape.
|
|
538
538
|
*/
|
|
539
|
-
declare function buildNetworkId(
|
|
539
|
+
declare function buildNetworkId(ownerDid: string, name: string): string;
|
|
540
540
|
/**
|
|
541
541
|
* Returns true when {@link networkId} is a syntactically valid network URN.
|
|
542
542
|
*/
|
|
543
543
|
declare function isNetworkId(networkId: unknown): networkId is string;
|
|
544
544
|
/**
|
|
545
545
|
* Resolve the discovery key used to look up a network's descriptor under
|
|
546
|
-
*
|
|
546
|
+
* an owner's public account-space.
|
|
547
547
|
*
|
|
548
548
|
* Format: `.well-known/encryption/network/<name>`.
|
|
549
549
|
*/
|
package/dist/encryption/index.js
CHANGED
|
@@ -406,20 +406,20 @@ function parseNetworkId(networkId) {
|
|
|
406
406
|
const lastColon = body.lastIndexOf(":");
|
|
407
407
|
if (lastColon <= 0 || lastColon === body.length - 1) {
|
|
408
408
|
throw new NetworkIdError(
|
|
409
|
-
`networkId missing
|
|
409
|
+
`networkId missing ownerDid or name segment (got ${JSON.stringify(networkId)})`
|
|
410
410
|
);
|
|
411
411
|
}
|
|
412
|
-
const
|
|
412
|
+
const ownerDid = body.slice(0, lastColon);
|
|
413
413
|
const name = body.slice(lastColon + 1);
|
|
414
|
-
if (!
|
|
414
|
+
if (!ownerDid.startsWith("did:")) {
|
|
415
415
|
throw new NetworkIdError(
|
|
416
|
-
`networkId
|
|
416
|
+
`networkId ownerDid must be a DID (got ${JSON.stringify(ownerDid)})`
|
|
417
417
|
);
|
|
418
418
|
}
|
|
419
|
-
const didParts =
|
|
419
|
+
const didParts = ownerDid.split(":");
|
|
420
420
|
if (didParts.length < 3 || didParts.some((p) => p.length === 0)) {
|
|
421
421
|
throw new NetworkIdError(
|
|
422
|
-
`networkId
|
|
422
|
+
`networkId ownerDid is not a well-formed DID (got ${JSON.stringify(ownerDid)})`
|
|
423
423
|
);
|
|
424
424
|
}
|
|
425
425
|
if (!NETWORK_NAME_RE.test(name)) {
|
|
@@ -427,18 +427,18 @@ function parseNetworkId(networkId) {
|
|
|
427
427
|
`networkId name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
|
|
428
428
|
);
|
|
429
429
|
}
|
|
430
|
-
return { networkId,
|
|
430
|
+
return { networkId, ownerDid, name };
|
|
431
431
|
}
|
|
432
|
-
function buildNetworkId(
|
|
433
|
-
if (typeof
|
|
434
|
-
throw new NetworkIdError("
|
|
432
|
+
function buildNetworkId(ownerDid, name) {
|
|
433
|
+
if (typeof ownerDid !== "string" || !ownerDid.startsWith("did:")) {
|
|
434
|
+
throw new NetworkIdError("ownerDid must be a DID");
|
|
435
435
|
}
|
|
436
436
|
if (typeof name !== "string" || !NETWORK_NAME_RE.test(name)) {
|
|
437
437
|
throw new NetworkIdError(
|
|
438
438
|
`network name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
|
|
439
439
|
);
|
|
440
440
|
}
|
|
441
|
-
const networkId = `${URN_PREFIX}${
|
|
441
|
+
const networkId = `${URN_PREFIX}${ownerDid}:${name}`;
|
|
442
442
|
parseNetworkId(networkId);
|
|
443
443
|
return networkId;
|
|
444
444
|
}
|
|
@@ -515,27 +515,27 @@ function toError(error) {
|
|
|
515
515
|
// src/encryption/discovery.ts
|
|
516
516
|
async function discoverNetwork(input) {
|
|
517
517
|
let networkId;
|
|
518
|
-
let
|
|
518
|
+
let ownerDid;
|
|
519
519
|
let name;
|
|
520
520
|
try {
|
|
521
521
|
if (input.identifier.startsWith("urn:tinycloud:encryption:")) {
|
|
522
522
|
const parsed = parseNetworkId(input.identifier);
|
|
523
523
|
networkId = parsed.networkId;
|
|
524
|
-
|
|
524
|
+
ownerDid = parsed.ownerDid;
|
|
525
525
|
name = parsed.name;
|
|
526
526
|
} else {
|
|
527
|
-
if (input.
|
|
527
|
+
if (input.ownerDid === void 0) {
|
|
528
528
|
return {
|
|
529
529
|
ok: false,
|
|
530
530
|
error: encryptionError({
|
|
531
531
|
code: "INVALID_INPUT",
|
|
532
|
-
message: "discoverNetwork requires `
|
|
532
|
+
message: "discoverNetwork requires `ownerDid` when identifier is a bare network name"
|
|
533
533
|
})
|
|
534
534
|
};
|
|
535
535
|
}
|
|
536
|
-
networkId = `urn:tinycloud:encryption:${input.
|
|
536
|
+
networkId = `urn:tinycloud:encryption:${input.ownerDid}:${input.identifier}`;
|
|
537
537
|
const parsed = parseNetworkId(networkId);
|
|
538
|
-
|
|
538
|
+
ownerDid = parsed.ownerDid;
|
|
539
539
|
name = parsed.name;
|
|
540
540
|
}
|
|
541
541
|
} catch (err2) {
|
|
@@ -554,7 +554,7 @@ async function discoverNetwork(input) {
|
|
|
554
554
|
try {
|
|
555
555
|
const descriptor = await input.node.fetchByNetworkId(networkId);
|
|
556
556
|
if (descriptor !== null) {
|
|
557
|
-
const validated = validateDescriptor(descriptor, networkId,
|
|
557
|
+
const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
|
|
558
558
|
if (!validated.ok) return validated;
|
|
559
559
|
return { ok: true, data: { descriptor: validated.data, source: "node" } };
|
|
560
560
|
}
|
|
@@ -564,11 +564,11 @@ async function discoverNetwork(input) {
|
|
|
564
564
|
if (input.wellKnown !== void 0) {
|
|
565
565
|
try {
|
|
566
566
|
const descriptor = await input.wellKnown.fetchWellKnown(
|
|
567
|
-
|
|
567
|
+
ownerDid,
|
|
568
568
|
networkDiscoveryKey(name)
|
|
569
569
|
);
|
|
570
570
|
if (descriptor !== null) {
|
|
571
|
-
const validated = validateDescriptor(descriptor, networkId,
|
|
571
|
+
const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
|
|
572
572
|
if (!validated.ok) return validated;
|
|
573
573
|
return {
|
|
574
574
|
ok: true,
|
|
@@ -587,7 +587,7 @@ async function discoverNetwork(input) {
|
|
|
587
587
|
})
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
|
-
function validateDescriptor(descriptor, networkId,
|
|
590
|
+
function validateDescriptor(descriptor, networkId, ownerDid, name) {
|
|
591
591
|
if (descriptor.networkId !== networkId) {
|
|
592
592
|
return {
|
|
593
593
|
ok: false,
|
|
@@ -597,12 +597,12 @@ function validateDescriptor(descriptor, networkId, principal, name) {
|
|
|
597
597
|
})
|
|
598
598
|
};
|
|
599
599
|
}
|
|
600
|
-
if (descriptor.
|
|
600
|
+
if (descriptor.ownerDid !== ownerDid) {
|
|
601
601
|
return {
|
|
602
602
|
ok: false,
|
|
603
603
|
error: encryptionError({
|
|
604
604
|
code: "INVALID_NETWORK_ID",
|
|
605
|
-
message: "descriptor
|
|
605
|
+
message: "descriptor ownerDid does not match networkId ownerDid"
|
|
606
606
|
})
|
|
607
607
|
};
|
|
608
608
|
}
|
|
@@ -982,6 +982,15 @@ function verifyDecryptResponse(input) {
|
|
|
982
982
|
})
|
|
983
983
|
};
|
|
984
984
|
}
|
|
985
|
+
if (response.nodeId !== request.targetNode) {
|
|
986
|
+
return {
|
|
987
|
+
ok: false,
|
|
988
|
+
error: encryptionError({
|
|
989
|
+
code: "RESPONSE_BINDING_MISMATCH",
|
|
990
|
+
field: "nodeId"
|
|
991
|
+
})
|
|
992
|
+
};
|
|
993
|
+
}
|
|
985
994
|
if (response.alg !== request.alg) {
|
|
986
995
|
return {
|
|
987
996
|
ok: false,
|
|
@@ -1085,10 +1094,10 @@ var EncryptionService = class extends BaseService {
|
|
|
1085
1094
|
get crypto() {
|
|
1086
1095
|
return this._config.crypto;
|
|
1087
1096
|
}
|
|
1088
|
-
async discoverNetwork(identifier,
|
|
1097
|
+
async discoverNetwork(identifier, ownerDid) {
|
|
1089
1098
|
const result = await discoverNetwork({
|
|
1090
1099
|
identifier,
|
|
1091
|
-
...
|
|
1100
|
+
...ownerDid !== void 0 ? { ownerDid } : {},
|
|
1092
1101
|
...this._config.node !== void 0 ? { node: this._config.node } : {},
|
|
1093
1102
|
...this._config.wellKnown !== void 0 ? { wellKnown: this._config.wellKnown } : {}
|
|
1094
1103
|
});
|
|
@@ -1126,6 +1135,14 @@ var EncryptionService = class extends BaseService {
|
|
|
1126
1135
|
try {
|
|
1127
1136
|
const validated = validateEnvelope(this.crypto, envelope);
|
|
1128
1137
|
if (!validated.ok) return validated;
|
|
1138
|
+
if (options?.aad !== void 0 && validated.data.aad !== base64Encode(options.aad)) {
|
|
1139
|
+
return encErr(
|
|
1140
|
+
encryptionError({
|
|
1141
|
+
code: "INVALID_INPUT",
|
|
1142
|
+
message: "decryptEnvelope aad does not match the envelope"
|
|
1143
|
+
})
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1129
1146
|
let descriptor;
|
|
1130
1147
|
if (options?.descriptor !== void 0) {
|
|
1131
1148
|
descriptor = options.descriptor;
|