@kubun/plugin-credential 0.17.2 → 0.17.4
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/service.d.ts +1 -1
- package/lib/service.js +47 -9
- package/package.json +10 -10
package/lib/service.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { KubunPlugin, PluginFactoryParams } from '@kubun/engine';
|
|
|
4
4
|
* (graph-schema-only, for an engine that consumes credentials), this registers a
|
|
5
5
|
* `service` provider that hosts the vault: it builds the credential seam over
|
|
6
6
|
* this engine's own db/HLC/identity and exposes
|
|
7
|
-
* `credential/get|create|refresh|delete|provenance` over a transport. The mint
|
|
7
|
+
* `credential/get|peek|create|refresh|delete|provenance` over a transport. The mint
|
|
8
8
|
* runs here, resolving a `did:kokuin:` owner-wrapping locally because this engine
|
|
9
9
|
* holds the owner's controller log.
|
|
10
10
|
*
|
package/lib/service.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { isSigningIdentity, normalizeDID } from '@kokuin/token';
|
|
2
|
-
import { CredentialAliasAlreadyBound, CredentialBindNotAuthorized, CredentialEntryAlreadyAliased, CredentialInvalidEntry, CredentialKeyVersionMismatch, CredentialNotFound, CredentialSupersededBranch, createCredentialAPI, createCredentialManager } from '@kubun/credential';
|
|
2
|
+
import { CredentialAliasAlreadyBound, CredentialBindNotAuthorized, CredentialEntryAlreadyAliased, CredentialInvalidEntry, CredentialKeyVersionMismatch, CredentialNotFound, CredentialSupersededBranch, createCredentialAPI, createCredentialManager, wrappableDID } from '@kubun/credential';
|
|
3
3
|
import { authorizeRead, authorizeWrite, ServiceAuthorizationError } from '@kubun/plugin-service-server';
|
|
4
4
|
import { credentialStoreDefinition, getCredentialStore } from '@kubun/store-credential';
|
|
5
|
-
// The spelling of a DID that can be encrypted to. A did:peer:4 identity carries a
|
|
6
|
-
// longForm that resolves the agreement key; its short id resolves none. For
|
|
7
|
-
// did:key the two forms are identical.
|
|
8
|
-
function wrappableDID(identity) {
|
|
9
|
-
const longForm = identity.longForm;
|
|
10
|
-
return typeof longForm === 'string' ? longForm : identity.id;
|
|
11
|
-
}
|
|
12
5
|
// The service boundary has no CREDENTIAL_* → KB* mapping; toHandlerError forwards
|
|
13
6
|
// a thrown error's `code` only when it is already a registered KubunErrorCode,
|
|
14
7
|
// preserving `data`. This maps the known credential outcomes to an envelope code
|
|
@@ -47,12 +40,38 @@ function withCode(cause, code, reason) {
|
|
|
47
40
|
cause
|
|
48
41
|
};
|
|
49
42
|
}
|
|
43
|
+
// The provider account captured in a stored credential's serialized body, or
|
|
44
|
+
// null when it captured none (or the body is not a serialized credential).
|
|
45
|
+
// The token-free part of a stored credential a peek discloses: its provider
|
|
46
|
+
// account and the scopes it was granted.
|
|
47
|
+
function readAccountPeek(raw) {
|
|
48
|
+
let parsed;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(raw);
|
|
51
|
+
} catch {
|
|
52
|
+
return {
|
|
53
|
+
providerAccount: null
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const account = parsed.providerAccount;
|
|
57
|
+
const providerAccount = typeof account?.iss === 'string' && typeof account.sub === 'string' ? {
|
|
58
|
+
iss: account.iss,
|
|
59
|
+
sub: account.sub
|
|
60
|
+
} : null;
|
|
61
|
+
const scopes = parsed.scopes;
|
|
62
|
+
return Array.isArray(scopes) && scopes.every((scope)=>typeof scope === 'string') ? {
|
|
63
|
+
providerAccount,
|
|
64
|
+
scopes: scopes
|
|
65
|
+
} : {
|
|
66
|
+
providerAccount
|
|
67
|
+
};
|
|
68
|
+
}
|
|
50
69
|
/**
|
|
51
70
|
* The credential service provider. Unlike {@link createCredentialPlugin}
|
|
52
71
|
* (graph-schema-only, for an engine that consumes credentials), this registers a
|
|
53
72
|
* `service` provider that hosts the vault: it builds the credential seam over
|
|
54
73
|
* this engine's own db/HLC/identity and exposes
|
|
55
|
-
* `credential/get|create|refresh|delete|provenance` over a transport. The mint
|
|
74
|
+
* `credential/get|peek|create|refresh|delete|provenance` over a transport. The mint
|
|
56
75
|
* runs here, resolving a `did:kokuin:` owner-wrapping locally because this engine
|
|
57
76
|
* holds the owner's controller log.
|
|
58
77
|
*
|
|
@@ -132,6 +151,22 @@ function withCode(cause, code, reason) {
|
|
|
132
151
|
proceed: ()=>readSeam.getCredential(param.providerName, param.ownerDID)
|
|
133
152
|
});
|
|
134
153
|
},
|
|
154
|
+
// The same vault read as `credential/get` — the DB credential API, which
|
|
155
|
+
// never refreshes a token — narrowed to the provider account and the
|
|
156
|
+
// granted scopes: no token material leaves the vault on a peek.
|
|
157
|
+
'credential/peek': (context)=>{
|
|
158
|
+
const param = context.param;
|
|
159
|
+
return authorizeRead({
|
|
160
|
+
context,
|
|
161
|
+
subject: param.ownerDID,
|
|
162
|
+
emptyResult: null,
|
|
163
|
+
proceed: async ()=>{
|
|
164
|
+
const raw = await readSeam.getCredential(param.providerName, param.ownerDID);
|
|
165
|
+
if (raw == null) return null;
|
|
166
|
+
return readAccountPeek(raw);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
},
|
|
135
170
|
'credential/provenance': (context)=>{
|
|
136
171
|
const param = context.param;
|
|
137
172
|
return authorizeRead({
|
|
@@ -206,6 +241,9 @@ function withCode(cause, code, reason) {
|
|
|
206
241
|
'credential/get': {
|
|
207
242
|
allow: true
|
|
208
243
|
},
|
|
244
|
+
'credential/peek': {
|
|
245
|
+
allow: true
|
|
246
|
+
},
|
|
209
247
|
'credential/provenance': {
|
|
210
248
|
allow: true
|
|
211
249
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/plugin-credential",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.4",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@kokuin/token": "^0.5.0",
|
|
18
|
-
"@kubun/credential": "^0.17.
|
|
18
|
+
"@kubun/credential": "^0.17.4",
|
|
19
19
|
"@kubun/db": "^0.17.0",
|
|
20
|
-
"@kubun/engine": "^0.17.
|
|
21
|
-
"@kubun/graphql": "^0.17.
|
|
20
|
+
"@kubun/engine": "^0.17.2",
|
|
21
|
+
"@kubun/graphql": "^0.17.2",
|
|
22
22
|
"@kubun/hlc": "^0.17.0",
|
|
23
23
|
"@kubun/id": "^0.17.0",
|
|
24
|
-
"@kubun/plugin-service-api": "^0.17.
|
|
25
|
-
"@kubun/plugin-service-server": "^0.17.
|
|
26
|
-
"@kubun/protocol": "^0.17.
|
|
27
|
-
"@kubun/store-credential": "^0.17.
|
|
24
|
+
"@kubun/plugin-service-api": "^0.17.1",
|
|
25
|
+
"@kubun/plugin-service-server": "^0.17.1",
|
|
26
|
+
"@kubun/protocol": "^0.17.2",
|
|
27
|
+
"@kubun/store-credential": "^0.17.4",
|
|
28
28
|
"@sozai/codec": "^0.4.0",
|
|
29
29
|
"@sozai/runtime": "^0.1.0",
|
|
30
30
|
"graphql": "^17.0.2"
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@kokuin/capability": "^0.3.0",
|
|
36
36
|
"@kokuin/controller": "^0.1.0",
|
|
37
37
|
"@kubun/db-better-sqlite": "^0.17.0",
|
|
38
|
-
"@kubun/service-credential-api": "^0.17.
|
|
38
|
+
"@kubun/service-credential-api": "^0.17.2",
|
|
39
39
|
"@kubun/store-controller": "^0.17.0",
|
|
40
|
-
"@kubun/store-graph": "^0.17.
|
|
40
|
+
"@kubun/store-graph": "^0.17.1",
|
|
41
41
|
"@kubun/test-utils": "^0.0.0"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|