@kubun/plugin-credential 0.17.2 → 0.17.3

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 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
@@ -47,12 +47,38 @@ function withCode(cause, code, reason) {
47
47
  cause
48
48
  };
49
49
  }
50
+ // The provider account captured in a stored credential's serialized body, or
51
+ // null when it captured none (or the body is not a serialized credential).
52
+ // The token-free part of a stored credential a peek discloses: its provider
53
+ // account and the scopes it was granted.
54
+ function readAccountPeek(raw) {
55
+ let parsed;
56
+ try {
57
+ parsed = JSON.parse(raw);
58
+ } catch {
59
+ return {
60
+ providerAccount: null
61
+ };
62
+ }
63
+ const account = parsed.providerAccount;
64
+ const providerAccount = typeof account?.iss === 'string' && typeof account.sub === 'string' ? {
65
+ iss: account.iss,
66
+ sub: account.sub
67
+ } : null;
68
+ const scopes = parsed.scopes;
69
+ return Array.isArray(scopes) && scopes.every((scope)=>typeof scope === 'string') ? {
70
+ providerAccount,
71
+ scopes: scopes
72
+ } : {
73
+ providerAccount
74
+ };
75
+ }
50
76
  /**
51
77
  * The credential service provider. Unlike {@link createCredentialPlugin}
52
78
  * (graph-schema-only, for an engine that consumes credentials), this registers a
53
79
  * `service` provider that hosts the vault: it builds the credential seam over
54
80
  * this engine's own db/HLC/identity and exposes
55
- * `credential/get|create|refresh|delete|provenance` over a transport. The mint
81
+ * `credential/get|peek|create|refresh|delete|provenance` over a transport. The mint
56
82
  * runs here, resolving a `did:kokuin:` owner-wrapping locally because this engine
57
83
  * holds the owner's controller log.
58
84
  *
@@ -132,6 +158,22 @@ function withCode(cause, code, reason) {
132
158
  proceed: ()=>readSeam.getCredential(param.providerName, param.ownerDID)
133
159
  });
134
160
  },
161
+ // The same vault read as `credential/get` — the DB credential API, which
162
+ // never refreshes a token — narrowed to the provider account and the
163
+ // granted scopes: no token material leaves the vault on a peek.
164
+ 'credential/peek': (context)=>{
165
+ const param = context.param;
166
+ return authorizeRead({
167
+ context,
168
+ subject: param.ownerDID,
169
+ emptyResult: null,
170
+ proceed: async ()=>{
171
+ const raw = await readSeam.getCredential(param.providerName, param.ownerDID);
172
+ if (raw == null) return null;
173
+ return readAccountPeek(raw);
174
+ }
175
+ });
176
+ },
135
177
  'credential/provenance': (context)=>{
136
178
  const param = context.param;
137
179
  return authorizeRead({
@@ -206,6 +248,9 @@ function withCode(cause, code, reason) {
206
248
  'credential/get': {
207
249
  allow: true
208
250
  },
251
+ 'credential/peek': {
252
+ allow: true
253
+ },
209
254
  'credential/provenance': {
210
255
  allow: true
211
256
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/plugin-credential",
3
- "version": "0.17.2",
3
+ "version": "0.17.3",
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.1",
18
+ "@kubun/credential": "^0.17.3",
19
19
  "@kubun/db": "^0.17.0",
20
- "@kubun/engine": "^0.17.1",
21
- "@kubun/graphql": "^0.17.1",
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.0",
25
- "@kubun/plugin-service-server": "^0.17.0",
26
- "@kubun/protocol": "^0.17.0",
27
- "@kubun/store-credential": "^0.17.3",
24
+ "@kubun/plugin-service-api": "^0.17.1",
25
+ "@kubun/plugin-service-server": "^0.17.1",
26
+ "@kubun/protocol": "^0.17.1",
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.1",
38
+ "@kubun/service-credential-api": "^0.17.2",
39
39
  "@kubun/store-controller": "^0.17.0",
40
- "@kubun/store-graph": "^0.17.0",
40
+ "@kubun/store-graph": "^0.17.1",
41
41
  "@kubun/test-utils": "^0.0.0"
42
42
  },
43
43
  "publishConfig": {