@interop/wallet-core 0.94.0 → 0.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -20
- package/dist/clientAnnex/mend.js +4 -1
- package/dist/clientAnnex/mend.js.map +1 -1
- package/dist/clients/index.d.ts +3 -2
- package/dist/clients/index.d.ts.map +1 -1
- package/dist/clients/index.js +3 -2
- package/dist/clients/index.js.map +1 -1
- package/dist/clients/listing.d.ts +19 -12
- package/dist/clients/listing.d.ts.map +1 -1
- package/dist/clients/listing.js +69 -22
- package/dist/clients/listing.js.map +1 -1
- package/dist/connections/didKey.d.ts +25 -0
- package/dist/connections/didKey.d.ts.map +1 -0
- package/dist/connections/didKey.js +49 -0
- package/dist/connections/didKey.js.map +1 -0
- package/dist/connections/entry.d.ts +226 -0
- package/dist/connections/entry.d.ts.map +1 -0
- package/dist/connections/entry.js +287 -0
- package/dist/connections/entry.js.map +1 -0
- package/dist/connections/errors.d.ts +33 -0
- package/dist/connections/errors.d.ts.map +1 -0
- package/dist/connections/errors.js +36 -0
- package/dist/connections/errors.js.map +1 -0
- package/dist/connections/grants.d.ts +94 -0
- package/dist/connections/grants.d.ts.map +1 -0
- package/dist/connections/grants.js +120 -0
- package/dist/connections/grants.js.map +1 -0
- package/dist/connections/index.d.ts +47 -0
- package/dist/connections/index.d.ts.map +1 -0
- package/dist/connections/index.js +40 -0
- package/dist/connections/index.js.map +1 -0
- package/dist/connections/read.d.ts +82 -0
- package/dist/connections/read.d.ts.map +1 -0
- package/dist/connections/read.js +100 -0
- package/dist/connections/read.js.map +1 -0
- package/dist/connections/resourceId.d.ts +36 -0
- package/dist/connections/resourceId.d.ts.map +1 -0
- package/dist/connections/resourceId.js +49 -0
- package/dist/connections/resourceId.js.map +1 -0
- package/dist/connections/store.d.ts +103 -0
- package/dist/connections/store.d.ts.map +1 -0
- package/dist/connections/store.js +67 -0
- package/dist/connections/store.js.map +1 -0
- package/dist/connections/upsert.d.ts +214 -0
- package/dist/connections/upsert.d.ts.map +1 -0
- package/dist/connections/upsert.js +468 -0
- package/dist/connections/upsert.js.map +1 -0
- package/dist/connections/writers.d.ts +217 -0
- package/dist/connections/writers.d.ts.map +1 -0
- package/dist/connections/writers.js +485 -0
- package/dist/connections/writers.js.map +1 -0
- package/dist/enrollment/onboardingResponse.d.ts +3 -3
- package/dist/enrollment/onboardingResponse.d.ts.map +1 -1
- package/dist/enrollment/onboardingResponse.js +17 -13
- package/dist/enrollment/onboardingResponse.js.map +1 -1
- package/dist/keys/index.d.ts +0 -7
- package/dist/keys/index.d.ts.map +1 -1
- package/dist/keys/index.js +0 -6
- package/dist/keys/index.js.map +1 -1
- package/dist/labelText.d.ts +30 -3
- package/dist/labelText.d.ts.map +1 -1
- package/dist/labelText.js +35 -3
- package/dist/labelText.js.map +1 -1
- package/dist/menders/ids.d.ts +1 -1
- package/dist/menders/ids.d.ts.map +1 -1
- package/dist/menders/ids.js +7 -2
- package/dist/menders/ids.js.map +1 -1
- package/dist/space/collections.d.ts +15 -25
- package/dist/space/collections.d.ts.map +1 -1
- package/dist/space/collections.js +19 -29
- package/dist/space/collections.js.map +1 -1
- package/dist/space/index.d.ts +4 -3
- package/dist/space/index.d.ts.map +1 -1
- package/dist/space/index.js +4 -3
- package/dist/space/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/keys/clientLabels.d.ts +0 -85
- package/dist/keys/clientLabels.d.ts.map +0 -1
- package/dist/keys/clientLabels.js +0 -96
- package/dist/keys/clientLabels.js.map +0 -1
- package/dist/keys/wasLabelsStore.d.ts +0 -33
- package/dist/keys/wasLabelsStore.d.ts.map +0 -1
- package/dist/keys/wasLabelsStore.js +0 -35
- package/dist/keys/wasLabelsStore.js.map +0 -1
- package/dist/writers/entry.d.ts +0 -95
- package/dist/writers/entry.d.ts.map +0 -1
- package/dist/writers/entry.js +0 -90
- package/dist/writers/entry.js.map +0 -1
- package/dist/writers/index.d.ts +0 -17
- package/dist/writers/index.d.ts.map +0 -1
- package/dist/writers/index.js +0 -14
- package/dist/writers/index.js.map +0 -1
- package/dist/writers/roster.d.ts +0 -152
- package/dist/writers/roster.d.ts.map +0 -1
- package/dist/writers/roster.js +0 -365
- package/dist/writers/roster.js.map +0 -1
- package/dist/writers/store.d.ts +0 -71
- package/dist/writers/store.d.ts.map +0 -1
- package/dist/writers/store.js +0 -55
- package/dist/writers/store.js.map +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2026 Interop Alliance. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The directory's storage seam, and its WAS-backed adapter over the
|
|
6
|
+
* `connections` collection.
|
|
7
|
+
*
|
|
8
|
+
* One resource per party keeps every write off any shared document. Every
|
|
9
|
+
* write the directory logic makes is conditional: a read-modify-write under
|
|
10
|
+
* `ifMatch`, or a create under `ifNoneMatch`. A lost race surfaces as an error
|
|
11
|
+
* named `PreconditionFailedError`, which the logic matches by name, since the
|
|
12
|
+
* seam may raise from a second copy of was-client.
|
|
13
|
+
*
|
|
14
|
+
* The seam reports what it could not read instead of hiding it. A listing
|
|
15
|
+
* names a resource it could not decrypt, an unknown epoch included, and a
|
|
16
|
+
* `get` that cannot decrypt throws. A reader that turned either into an
|
|
17
|
+
* absent body could evict a party at the next rotation or write over a body
|
|
18
|
+
* it never saw.
|
|
19
|
+
*/
|
|
20
|
+
import type { Collection } from '@interop/was-client';
|
|
21
|
+
import type { DocCipher } from '@interop/was-client/edv/cipher';
|
|
22
|
+
/**
|
|
23
|
+
* One resource as a listing read it: its body when it opened, or the error
|
|
24
|
+
* that kept it from opening, and its ETag.
|
|
25
|
+
*/
|
|
26
|
+
export interface StoredConnection {
|
|
27
|
+
resourceId: string;
|
|
28
|
+
etag?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The decrypted body. Absent when `readError` is set.
|
|
31
|
+
*/
|
|
32
|
+
body?: unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Why the body could not be read or opened (an unknown epoch, a key this
|
|
35
|
+
* reader does not hold, an envelope bound to another id). Set only when
|
|
36
|
+
* `body` is absent.
|
|
37
|
+
*/
|
|
38
|
+
readError?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The Space-side seam of the directory.
|
|
42
|
+
*/
|
|
43
|
+
export interface ConnectionsStore {
|
|
44
|
+
/**
|
|
45
|
+
* Every resource in the collection, or `null` when the collection is
|
|
46
|
+
* absent or not visible under this authority. A resource that fails to
|
|
47
|
+
* open is listed with its `readError` rather than failing the list.
|
|
48
|
+
*/
|
|
49
|
+
list(): Promise<StoredConnection[] | null>;
|
|
50
|
+
/**
|
|
51
|
+
* One resource, or `undefined` when it does not exist. A resource that
|
|
52
|
+
* exists and cannot be opened throws.
|
|
53
|
+
*/
|
|
54
|
+
get(options: {
|
|
55
|
+
resourceId: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
body: unknown;
|
|
58
|
+
etag?: string;
|
|
59
|
+
} | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Writes one body: conditional on `ifMatch`, or create-only under
|
|
62
|
+
* `ifNoneMatch`.
|
|
63
|
+
*/
|
|
64
|
+
put(options: {
|
|
65
|
+
resourceId: string;
|
|
66
|
+
body: Record<string, unknown>;
|
|
67
|
+
ifMatch?: string;
|
|
68
|
+
ifNoneMatch?: boolean;
|
|
69
|
+
}): Promise<{
|
|
70
|
+
etag?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Deletes one resource, conditional on `ifMatch` when given.
|
|
74
|
+
*/
|
|
75
|
+
delete(options: {
|
|
76
|
+
resourceId: string;
|
|
77
|
+
ifMatch?: string;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Builds the directory store over the `connections` collection handle.
|
|
82
|
+
*
|
|
83
|
+
* A listing reads the collection's documents feed, bodies and ETags, one
|
|
84
|
+
* request per page, and opens each envelope with `cipher` under the resource
|
|
85
|
+
* id the feed served it at. A `get`, a `put`, and a `delete` go through the
|
|
86
|
+
* handle, whose encryption provider opens a read and seals a write. A `put`
|
|
87
|
+
* at an id with no resource yet creates the resource there, sealed under the
|
|
88
|
+
* collection's current epoch.
|
|
89
|
+
*
|
|
90
|
+
* @param options {object}
|
|
91
|
+
* @param options.collection {Collection} the account data Space's
|
|
92
|
+
* `connections` collection, opened through a storage client whose
|
|
93
|
+
* encryption provider seals and opens it like any other encrypted wallet
|
|
94
|
+
* collection (and carrying the invocation capability, if any)
|
|
95
|
+
* @param options.cipher {object} the collection's document cipher; only its
|
|
96
|
+
* `decrypt` is used, to open the envelopes the documents feed serves
|
|
97
|
+
* @returns {ConnectionsStore}
|
|
98
|
+
*/
|
|
99
|
+
export declare function wasConnectionsStore({ collection, cipher }: {
|
|
100
|
+
collection: Collection;
|
|
101
|
+
cipher: Pick<DocCipher, 'decrypt'>;
|
|
102
|
+
}): ConnectionsStore;
|
|
103
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/connections/store.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,qBAAqB,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE/D;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAA;IAC1C;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE;QACX,UAAU,EAAE,MAAM,CAAA;KACnB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAA;IACzD;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE;QACX,UAAU,EAAE,MAAM,CAAA;QAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,WAAW,CAAC,EAAE,OAAO,CAAA;KACtB,GAAG,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC9B;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACzE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EACV,MAAM,EACP,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;CACnC,GAAG,gBAAgB,CA+CnB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the directory store over the `connections` collection handle.
|
|
3
|
+
*
|
|
4
|
+
* A listing reads the collection's documents feed, bodies and ETags, one
|
|
5
|
+
* request per page, and opens each envelope with `cipher` under the resource
|
|
6
|
+
* id the feed served it at. A `get`, a `put`, and a `delete` go through the
|
|
7
|
+
* handle, whose encryption provider opens a read and seals a write. A `put`
|
|
8
|
+
* at an id with no resource yet creates the resource there, sealed under the
|
|
9
|
+
* collection's current epoch.
|
|
10
|
+
*
|
|
11
|
+
* @param options {object}
|
|
12
|
+
* @param options.collection {Collection} the account data Space's
|
|
13
|
+
* `connections` collection, opened through a storage client whose
|
|
14
|
+
* encryption provider seals and opens it like any other encrypted wallet
|
|
15
|
+
* collection (and carrying the invocation capability, if any)
|
|
16
|
+
* @param options.cipher {object} the collection's document cipher; only its
|
|
17
|
+
* `decrypt` is used, to open the envelopes the documents feed serves
|
|
18
|
+
* @returns {ConnectionsStore}
|
|
19
|
+
*/
|
|
20
|
+
export function wasConnectionsStore({ collection, cipher }) {
|
|
21
|
+
return {
|
|
22
|
+
async list() {
|
|
23
|
+
const documents = await collection.documents();
|
|
24
|
+
if (documents === null) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const context = collection.codecContext();
|
|
28
|
+
return Promise.all(documents.map(async (doc) => {
|
|
29
|
+
const etag = doc.etag !== undefined ? { etag: doc.etag } : {};
|
|
30
|
+
try {
|
|
31
|
+
const body = await cipher.decrypt({
|
|
32
|
+
id: doc.id,
|
|
33
|
+
envelope: doc.data,
|
|
34
|
+
context
|
|
35
|
+
});
|
|
36
|
+
return { resourceId: doc.id, ...etag, body };
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return { resourceId: doc.id, ...etag, readError: err };
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
async get({ resourceId }) {
|
|
44
|
+
const result = await collection.resource(resourceId).getWithEtag();
|
|
45
|
+
if (result === null) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
body: result.data,
|
|
50
|
+
...(result.etag !== undefined && { etag: result.etag })
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
async put({ resourceId, body, ifMatch, ifNoneMatch }) {
|
|
54
|
+
return collection.put(resourceId, body, {
|
|
55
|
+
contentType: 'application/json',
|
|
56
|
+
...(ifMatch !== undefined && { ifMatch }),
|
|
57
|
+
...(ifNoneMatch === true && { ifNoneMatch })
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
async delete({ resourceId, ifMatch }) {
|
|
61
|
+
await collection
|
|
62
|
+
.resource(resourceId)
|
|
63
|
+
.delete(ifMatch !== undefined ? { ifMatch } : {});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/connections/store.ts"],"names":[],"mappings":"AA0EA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,UAAU,EACV,MAAM,EAIP;IACC,OAAO;QACL,KAAK,CAAC,IAAI;YACR,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,SAAS,EAAE,CAAA;YAC9C,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAA;YACb,CAAC;YACD,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,EAAE,CAAA;YACzC,OAAO,OAAO,CAAC,GAAG,CAChB,SAAS,CAAC,GAAG,CAAC,KAAK,EAAC,GAAG,EAAC,EAAE;gBACxB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;gBAC7D,IAAI,CAAC;oBACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;wBAChC,EAAE,EAAE,GAAG,CAAC,EAAE;wBACV,QAAQ,EAAE,GAAG,CAAC,IAAY;wBAC1B,OAAO;qBACR,CAAC,CAAA;oBACF,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAA;gBAC9C,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAA;gBACxD,CAAC;YACH,CAAC,CAAC,CACH,CAAA;QACH,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE;YACtB,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAA;YAClE,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;aACxD,CAAA;QACH,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE;YAClD,OAAO,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,IAAkB,EAAE;gBACpD,WAAW,EAAE,kBAAkB;gBAC/B,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,CAAC;gBACzC,GAAG,CAAC,WAAW,KAAK,IAAI,IAAI,EAAE,WAAW,EAAE,CAAC;aAC7C,CAAC,CAAA;QACJ,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE;YAClC,MAAM,UAAU;iBACb,QAAQ,CAAC,UAAU,CAAC;iBACpB,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACrD,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { ConnectionEntry, ConnectionKind, GrantKind } from './entry.js';
|
|
2
|
+
import type { ConnectionIdKey } from './resourceId.js';
|
|
3
|
+
import type { ConnectionsStore } from './store.js';
|
|
4
|
+
/**
|
|
5
|
+
* What one helper call did at the party's id.
|
|
6
|
+
*
|
|
7
|
+
* - `created` -- no entry stood there, and one was written.
|
|
8
|
+
* - `updated` -- the entry was rewritten.
|
|
9
|
+
* - `unchanged` -- the entry already said what the helper would write.
|
|
10
|
+
* - `absent` -- no entry stood there, and the helper creates none.
|
|
11
|
+
*/
|
|
12
|
+
export type ConnectionWriteOutcome = 'created' | 'updated' | 'unchanged' | 'absent';
|
|
13
|
+
/**
|
|
14
|
+
* A helper's result: where it wrote, and what it did there.
|
|
15
|
+
*/
|
|
16
|
+
export interface ConnectionWriteResult {
|
|
17
|
+
resourceId: string;
|
|
18
|
+
outcome: ConnectionWriteOutcome;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An entry a helper may write over: the members the codec read, and the
|
|
22
|
+
* stored body the write starts from.
|
|
23
|
+
*/
|
|
24
|
+
export interface WritableConnection {
|
|
25
|
+
entry: ConnectionEntry;
|
|
26
|
+
body: Record<string, unknown>;
|
|
27
|
+
etag?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a store write lost a race. Matched by name, since the store is an
|
|
31
|
+
* injected seam that may raise from a second copy of was-client.
|
|
32
|
+
*
|
|
33
|
+
* @param err {unknown}
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
export declare function isLostConnectionRace(err: unknown): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* What a `change` callback asks {@link writeConnection} to do on one
|
|
39
|
+
* attempt: write `body` at the id, or stop with the given outcome and write
|
|
40
|
+
* nothing.
|
|
41
|
+
*/
|
|
42
|
+
export type ConnectionChange<Stop> = {
|
|
43
|
+
body: Record<string, unknown>;
|
|
44
|
+
} | {
|
|
45
|
+
stop: Stop;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The bounded compare-and-swap loop every directory write runs at one
|
|
49
|
+
* resource id: the upsert helpers here and the writer arm in `writers.ts`.
|
|
50
|
+
* Each attempt reads the resource, hands `change` the writable entry (or
|
|
51
|
+
* `undefined` when none stands), and writes the body it returns under
|
|
52
|
+
* `ifMatch` (or creates it under `ifNoneMatch`). A `stop` ends the loop with
|
|
53
|
+
* that outcome and no write. A lost race re-reads and re-applies, and after
|
|
54
|
+
* the last attempt the last `PreconditionFailedError` is thrown. `change`
|
|
55
|
+
* may throw a refusal, which ends the loop the same way.
|
|
56
|
+
*
|
|
57
|
+
* A stored body this build cannot write over (unparseable, misplaced, or
|
|
58
|
+
* from a newer build) throws, unless `unwritable` names the outcome to
|
|
59
|
+
* resolve with instead.
|
|
60
|
+
*
|
|
61
|
+
* @param options {object}
|
|
62
|
+
* @param options.store {ConnectionsStore}
|
|
63
|
+
* @param options.hmacKey {ConnectionIdKey}
|
|
64
|
+
* @param options.resourceId {string}
|
|
65
|
+
* @param options.change {Function}
|
|
66
|
+
* @param [options.unwritable] {Stop} the outcome for a body this build
|
|
67
|
+
* cannot write over; omitted, such a body throws
|
|
68
|
+
* @returns {Promise<object>} the id and the outcome: `created`, `updated`,
|
|
69
|
+
* or the `stop` the callback returned
|
|
70
|
+
*/
|
|
71
|
+
export declare function writeConnection<Stop>({ store, hmacKey, resourceId, change, unwritable }: {
|
|
72
|
+
store: ConnectionsStore;
|
|
73
|
+
hmacKey: ConnectionIdKey;
|
|
74
|
+
resourceId: string;
|
|
75
|
+
change: (current: WritableConnection | undefined) => ConnectionChange<Stop>;
|
|
76
|
+
unwritable?: Stop;
|
|
77
|
+
}): Promise<{
|
|
78
|
+
resourceId: string;
|
|
79
|
+
outcome: 'created' | 'updated' | Stop;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Records a consent on the party's entry: creates the entry, or merges into
|
|
83
|
+
* it. Each new grant is added by its capability id (one already recorded is
|
|
84
|
+
* left as stored), `name` is set when it passes the display-name rule (left
|
|
85
|
+
* as it was otherwise), `origin`, `url`, and `appKey` are set when given,
|
|
86
|
+
* `retired` is cleared, and `lastSeen` moves to `now`. `firstSeen` is set
|
|
87
|
+
* only on create, and `label` is never touched. A zero-grant consent writes
|
|
88
|
+
* too, so an App Connect app with no grants is indexed by its key.
|
|
89
|
+
*
|
|
90
|
+
* Refuses an entry of another kind with {@link ConnectionKindMismatchError},
|
|
91
|
+
* and a grant delegated to another party or targeting another Space with a
|
|
92
|
+
* `TypeError`, before anything is written.
|
|
93
|
+
*
|
|
94
|
+
* @param options {object}
|
|
95
|
+
* @param options.store {ConnectionsStore}
|
|
96
|
+
* @param options.hmacKey {ConnectionIdKey}
|
|
97
|
+
* @param options.did {string} the party's DID, every grant's controller
|
|
98
|
+
* @param options.kind {ConnectionKind} the kind this flow writes
|
|
99
|
+
* @param options.spaceUrl {string} this Space's container URL, every
|
|
100
|
+
* grant's target prefix
|
|
101
|
+
* @param options.grants {Array<object>} `{ zcap, grantKind }` per grant
|
|
102
|
+
* @param [options.name] {string} the party's self-declared name
|
|
103
|
+
* @param [options.origin] {string} the attested Web origin (App Connect)
|
|
104
|
+
* @param [options.url] {string} the canonical app URL (App Connect)
|
|
105
|
+
* @param [options.appKey] {string} the app-key Resource id (App Connect)
|
|
106
|
+
* @param [options.now] {Date}
|
|
107
|
+
* @returns {Promise<ConnectionWriteResult>}
|
|
108
|
+
*/
|
|
109
|
+
export declare function recordGrants({ store, hmacKey, did, kind, spaceUrl, grants, name, origin, url, appKey, now }: {
|
|
110
|
+
store: ConnectionsStore;
|
|
111
|
+
hmacKey: ConnectionIdKey;
|
|
112
|
+
did: string;
|
|
113
|
+
kind: ConnectionKind;
|
|
114
|
+
spaceUrl: string;
|
|
115
|
+
grants: Array<{
|
|
116
|
+
zcap: object;
|
|
117
|
+
grantKind: GrantKind;
|
|
118
|
+
}>;
|
|
119
|
+
name?: string;
|
|
120
|
+
origin?: string;
|
|
121
|
+
url?: string;
|
|
122
|
+
appKey?: string;
|
|
123
|
+
now?: Date;
|
|
124
|
+
}): Promise<ConnectionWriteResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Removes grants from the party's entry by capability id, whatever the
|
|
127
|
+
* entry's kind. Used by an unshare after its revocation, and by a torn
|
|
128
|
+
* consent's rollback. An absent entry, or one holding none of the ids,
|
|
129
|
+
* writes nothing.
|
|
130
|
+
*
|
|
131
|
+
* @param options {object}
|
|
132
|
+
* @param options.store {ConnectionsStore}
|
|
133
|
+
* @param options.hmacKey {ConnectionIdKey}
|
|
134
|
+
* @param options.did {string} the party's DID
|
|
135
|
+
* @param options.zcapIds {Iterable<string>} the capability ids to remove
|
|
136
|
+
* @returns {Promise<ConnectionWriteResult>}
|
|
137
|
+
*/
|
|
138
|
+
export declare function removeGrants({ store, hmacKey, did, zcapIds }: {
|
|
139
|
+
store: ConnectionsStore;
|
|
140
|
+
hmacKey: ConnectionIdKey;
|
|
141
|
+
did: string;
|
|
142
|
+
zcapIds: Iterable<string>;
|
|
143
|
+
}): Promise<ConnectionWriteResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Retires the party's entry, of any kind, once a revocation has handled its
|
|
146
|
+
* grants: empties `grants`, drops `appKey`, and stamps `retired`. `name`,
|
|
147
|
+
* `label`, `origin`, `url`, `firstSeen`, `lastSeen`, and `writers` stay, so a
|
|
148
|
+
* departed party keeps resolving. An entry already retired with nothing left
|
|
149
|
+
* to empty writes nothing, and an absent entry writes nothing.
|
|
150
|
+
*
|
|
151
|
+
* Throws when a read finds a grant that passes the reader checks and is not
|
|
152
|
+
* among `handledZcapIds`: a concurrent consent merged it, and the revocation
|
|
153
|
+
* must run again before the entry may retire. A grant that fails the reader
|
|
154
|
+
* checks (another party's controller, a target outside this Space) is not
|
|
155
|
+
* the party's, and the retirement empties it with the rest.
|
|
156
|
+
*
|
|
157
|
+
* @param options {object}
|
|
158
|
+
* @param options.store {ConnectionsStore}
|
|
159
|
+
* @param options.hmacKey {ConnectionIdKey}
|
|
160
|
+
* @param options.did {string} the party's DID
|
|
161
|
+
* @param options.handledZcapIds {Iterable<string>} the capability ids the
|
|
162
|
+
* revocation POSTed
|
|
163
|
+
* @param options.spaceUrl {string} this Space's container URL
|
|
164
|
+
* @param [options.now] {Date}
|
|
165
|
+
* @returns {Promise<ConnectionWriteResult>}
|
|
166
|
+
*/
|
|
167
|
+
export declare function retireConnection({ store, hmacKey, did, handledZcapIds, spaceUrl, now }: {
|
|
168
|
+
store: ConnectionsStore;
|
|
169
|
+
hmacKey: ConnectionIdKey;
|
|
170
|
+
did: string;
|
|
171
|
+
handledZcapIds: Iterable<string>;
|
|
172
|
+
spaceUrl: string;
|
|
173
|
+
now?: Date;
|
|
174
|
+
}): Promise<ConnectionWriteResult>;
|
|
175
|
+
/**
|
|
176
|
+
* Sets the user's `label` on the party's entry, and its `name` when given.
|
|
177
|
+
* A blank `label` removes the member; an omitted one leaves it, and one
|
|
178
|
+
* outside the display-name rule is refused with a `TypeError`, since the
|
|
179
|
+
* user typed it and can shorten it. A `name` outside the rule is ignored. The enrollment approval writes
|
|
180
|
+
* the code's suggested label as `name` and passes `label` only when the
|
|
181
|
+
* approver edited it.
|
|
182
|
+
*
|
|
183
|
+
* Creates an absent entry only for a wallet client the verified account
|
|
184
|
+
* document lists (`kind: 'wallet-client'`, its did:key's signing-key
|
|
185
|
+
* multibase in `enrolledSigningKeys`), and throws for any other absent
|
|
186
|
+
* party. Refuses an entry of another kind with
|
|
187
|
+
* {@link ConnectionKindMismatchError}.
|
|
188
|
+
*
|
|
189
|
+
* @param options {object}
|
|
190
|
+
* @param options.store {ConnectionsStore}
|
|
191
|
+
* @param options.hmacKey {ConnectionIdKey}
|
|
192
|
+
* @param options.did {string} the party's DID
|
|
193
|
+
* @param options.kind {ConnectionKind} the kind the calling surface lists
|
|
194
|
+
* the party as
|
|
195
|
+
* @param [options.label] {string} the user's name for the party
|
|
196
|
+
* @param [options.name] {string} the party's name (a client's default
|
|
197
|
+
* platform label, or an enrollee's suggested label)
|
|
198
|
+
* @param [options.enrolledSigningKeys] {ReadonlySet<string>} the enrolled
|
|
199
|
+
* clients' signing-key multibases in the verified account document; needed
|
|
200
|
+
* to create a wallet client's entry
|
|
201
|
+
* @param [options.now] {Date}
|
|
202
|
+
* @returns {Promise<ConnectionWriteResult>}
|
|
203
|
+
*/
|
|
204
|
+
export declare function setConnectionLabel({ store, hmacKey, did, kind, label, name, enrolledSigningKeys, now }: {
|
|
205
|
+
store: ConnectionsStore;
|
|
206
|
+
hmacKey: ConnectionIdKey;
|
|
207
|
+
did: string;
|
|
208
|
+
kind: ConnectionKind;
|
|
209
|
+
label?: string;
|
|
210
|
+
name?: string;
|
|
211
|
+
enrolledSigningKeys?: ReadonlySet<string>;
|
|
212
|
+
now?: Date;
|
|
213
|
+
}): Promise<ConnectionWriteResult>;
|
|
214
|
+
//# sourceMappingURL=upsert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../src/connections/upsert.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EAEd,SAAS,EACV,MAAM,YAAY,CAAA;AAKnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAKlD;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAChC,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,sBAAsB,CAAA;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,eAAe,CAAA;IACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAE1D;AAsED;;;;GAIG;AACH,MAAM,MAAM,gBA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