@kubun/credential-types 0.17.1 → 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 CHANGED
@@ -1,3 +1,9 @@
1
+ export type ProviderAccount = {
2
+ /** OpenID issuer, e.g. `https://accounts.google.com`. */
3
+ iss: string;
4
+ /** Stable, opaque provider subject id. Never projected to the graph. */
5
+ sub: string;
6
+ };
1
7
  export type Credential = {
2
8
  accessToken: string;
3
9
  refreshToken?: string;
@@ -5,7 +11,35 @@ export type Credential = {
5
11
  scopes: Array<string>;
6
12
  accountLabel?: string;
7
13
  metadata?: Record<string, unknown>;
14
+ /**
15
+ * Verified stable provider-account identity captured at OAuth completion.
16
+ * Lives only in the encrypted credential body; the graph sees only a derived
17
+ * non-reversible key. Preserved verbatim across token refresh.
18
+ */
19
+ providerAccount?: ProviderAccount;
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;
8
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
+ }
9
43
  export type CredentialProvider = {
10
44
  get(providerName: string, ownerDID: string): Promise<Credential | null>;
11
45
  /**
@@ -27,6 +61,7 @@ export type CredentialProvider = {
27
61
  controllerWrappableDID?: string;
28
62
  }): Promise<void>;
29
63
  delete(providerName: string, ownerDID: string): Promise<void>;
64
+ update?(address: GrantAddress, change: (current: Credential | null) => Credential): Promise<void>;
30
65
  };
31
66
  /**
32
67
  * Opt-in capability: point `(providerName, ownerDID)` at an entry the
@@ -54,3 +89,26 @@ export type EntryPairedCredentialProvider = {
54
89
  credential: Credential;
55
90
  }): Promise<'updated' | 'absent'>;
56
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
- * Opt-in capability: read and write a credential together with the entryID
7
- * it resolves to, so a caller can target that entry directly on a
8
- * subsequent write without re-resolving the alias.
9
- */ export { };
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/credential-types",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,