@kubun/credential-types 0.17.2 → 0.18.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/lib/index.d.ts +46 -0
- package/lib/index.js +6 -5
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -18,6 +18,28 @@ export type Credential = {
|
|
|
18
18
|
*/
|
|
19
19
|
providerAccount?: ProviderAccount;
|
|
20
20
|
};
|
|
21
|
+
export type GrantAddress = {
|
|
22
|
+
providerName: string;
|
|
23
|
+
ownerDID: string;
|
|
24
|
+
deviceDID: string;
|
|
25
|
+
};
|
|
26
|
+
export type AdoptGrantParams = {
|
|
27
|
+
providerName: string;
|
|
28
|
+
ownerDID: string;
|
|
29
|
+
fromDeviceDID: string;
|
|
30
|
+
toDeviceDID: string;
|
|
31
|
+
/** Required to resolve a no-alias grant that exists under multiple key owners. */
|
|
32
|
+
sourceKeyOwnerDID?: string;
|
|
33
|
+
};
|
|
34
|
+
export type AdoptGrantResult = {
|
|
35
|
+
adopted: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type AdoptGrantAPI = {
|
|
38
|
+
adoptCredentialGrant(params: AdoptGrantParams): Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
export declare class CredentialUpdateUnavailableError extends Error {
|
|
41
|
+
constructor();
|
|
42
|
+
}
|
|
21
43
|
export type CredentialProvider = {
|
|
22
44
|
get(providerName: string, ownerDID: string): Promise<Credential | null>;
|
|
23
45
|
/**
|
|
@@ -39,6 +61,7 @@ export type CredentialProvider = {
|
|
|
39
61
|
controllerWrappableDID?: string;
|
|
40
62
|
}): Promise<void>;
|
|
41
63
|
delete(providerName: string, ownerDID: string): Promise<void>;
|
|
64
|
+
update?(address: GrantAddress, change: (current: Credential | null) => Credential): Promise<void>;
|
|
42
65
|
};
|
|
43
66
|
/**
|
|
44
67
|
* Opt-in capability: point `(providerName, ownerDID)` at an entry the
|
|
@@ -66,3 +89,26 @@ export type EntryPairedCredentialProvider = {
|
|
|
66
89
|
credential: Credential;
|
|
67
90
|
}): Promise<'updated' | 'absent'>;
|
|
68
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Opt-in capability over {@link EntryPairedCredentialProvider}: a read that also
|
|
94
|
+
* returns the entry's `version`, an opaque token that changes on every write, and
|
|
95
|
+
* a write that lands only while the entry is still at that version. A refresh
|
|
96
|
+
* writes back through it so a credential replaced while the token exchange was in
|
|
97
|
+
* flight (a new consent) is kept rather than overwritten: the write reports
|
|
98
|
+
* `'superseded'` instead. The check and the write are one atomic store call, so no
|
|
99
|
+
* lock spans the two.
|
|
100
|
+
*/
|
|
101
|
+
export type VersionedEntryCredentialProvider = {
|
|
102
|
+
getVersionedCredentialRef(providerName: string, ownerDID: string): Promise<{
|
|
103
|
+
credential: Credential;
|
|
104
|
+
entryID: string;
|
|
105
|
+
version?: string;
|
|
106
|
+
} | null>;
|
|
107
|
+
setCredentialForEntryIfUnchanged(params: {
|
|
108
|
+
providerName: string;
|
|
109
|
+
ownerDID: string;
|
|
110
|
+
entryID: string;
|
|
111
|
+
credential: Credential;
|
|
112
|
+
expectedVersion: string;
|
|
113
|
+
}): Promise<'updated' | 'absent' | 'superseded'>;
|
|
114
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// that stores/refreshes it. Kept in this leaf package so both the low-level
|
|
3
3
|
// `@kubun/connector` (which consumes the port) and `@kubun/credential` (which
|
|
4
4
|
// implements it) can depend on the types without depending on each other.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export class CredentialUpdateUnavailableError extends Error {
|
|
6
|
+
constructor(){
|
|
7
|
+
super('A current credential entry version is required for a conditional update');
|
|
8
|
+
this.name = 'CredentialUpdateUnavailableError';
|
|
9
|
+
}
|
|
10
|
+
}
|