@kubun/plugin-credential 0.17.0 → 0.17.2
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.js +55 -1
- package/package.json +8 -7
package/lib/service.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isSigningIdentity, normalizeDID } from '@kokuin/token';
|
|
2
|
-
import { createCredentialAPI, createCredentialManager } from '@kubun/credential';
|
|
2
|
+
import { CredentialAliasAlreadyBound, CredentialBindNotAuthorized, CredentialEntryAlreadyAliased, CredentialInvalidEntry, CredentialKeyVersionMismatch, CredentialNotFound, CredentialSupersededBranch, createCredentialAPI, createCredentialManager } from '@kubun/credential';
|
|
3
3
|
import { authorizeRead, authorizeWrite, ServiceAuthorizationError } from '@kubun/plugin-service-server';
|
|
4
4
|
import { credentialStoreDefinition, getCredentialStore } from '@kubun/store-credential';
|
|
5
5
|
// The spelling of a DID that can be encrypted to. A did:peer:4 identity carries a
|
|
@@ -9,6 +9,44 @@ function wrappableDID(identity) {
|
|
|
9
9
|
const longForm = identity.longForm;
|
|
10
10
|
return typeof longForm === 'string' ? longForm : identity.id;
|
|
11
11
|
}
|
|
12
|
+
// The service boundary has no CREDENTIAL_* → KB* mapping; toHandlerError forwards
|
|
13
|
+
// a thrown error's `code` only when it is already a registered KubunErrorCode,
|
|
14
|
+
// preserving `data`. This maps the known credential outcomes to an envelope code
|
|
15
|
+
// plus a stable `data.reason`, so a remote caller can branch on it without seeing
|
|
16
|
+
// the internal CREDENTIAL_* code or message. `ServiceAuthorizationError` (Gate A)
|
|
17
|
+
// already carries KB07 on its own `code` getter and never reaches this function —
|
|
18
|
+
// it throws before the try/catch below. An unmapped error stays opaque.
|
|
19
|
+
function translateCredentialError(err) {
|
|
20
|
+
if (err instanceof CredentialBindNotAuthorized) {
|
|
21
|
+
return withCode(err, 'KB07', 'CREDENTIAL_NOT_AUTHORIZED');
|
|
22
|
+
}
|
|
23
|
+
if (err instanceof CredentialAliasAlreadyBound) {
|
|
24
|
+
return withCode(err, 'KB04', 'CREDENTIAL_ALIAS_ALREADY_BOUND');
|
|
25
|
+
}
|
|
26
|
+
if (err instanceof CredentialEntryAlreadyAliased) {
|
|
27
|
+
return withCode(err, 'KB04', 'CREDENTIAL_ENTRY_ALREADY_ALIASED');
|
|
28
|
+
}
|
|
29
|
+
if (err instanceof CredentialNotFound) {
|
|
30
|
+
return withCode(err, 'KB02', 'CREDENTIAL_NOT_FOUND');
|
|
31
|
+
}
|
|
32
|
+
if (err instanceof CredentialInvalidEntry) {
|
|
33
|
+
return withCode(err, 'KB01', 'CREDENTIAL_INVALID_ENTRY');
|
|
34
|
+
}
|
|
35
|
+
if (err instanceof CredentialSupersededBranch || err instanceof CredentialKeyVersionMismatch) {
|
|
36
|
+
return withCode(err, 'KB01', 'CREDENTIAL_INVALID_ENTRY');
|
|
37
|
+
}
|
|
38
|
+
return err;
|
|
39
|
+
}
|
|
40
|
+
function withCode(cause, code, reason) {
|
|
41
|
+
return {
|
|
42
|
+
code,
|
|
43
|
+
message: cause.message,
|
|
44
|
+
data: {
|
|
45
|
+
reason
|
|
46
|
+
},
|
|
47
|
+
cause
|
|
48
|
+
};
|
|
49
|
+
}
|
|
12
50
|
/**
|
|
13
51
|
* The credential service provider. Unlike {@link createCredentialPlugin}
|
|
14
52
|
* (graph-schema-only, for an engine that consumes credentials), this registers a
|
|
@@ -146,6 +184,19 @@ function wrappableDID(identity) {
|
|
|
146
184
|
});
|
|
147
185
|
await writeInTx((seam)=>seam.deleteCredential(param.providerName, param.ownerDID));
|
|
148
186
|
return null;
|
|
187
|
+
},
|
|
188
|
+
'credential/bind-alias': async (context)=>{
|
|
189
|
+
const param = context.param;
|
|
190
|
+
await authorizeWrite({
|
|
191
|
+
context,
|
|
192
|
+
subject: param.ownerDID
|
|
193
|
+
}); // Gate A
|
|
194
|
+
try {
|
|
195
|
+
await writeInTx((seam)=>seam.bindAlias(param.providerName, param.ownerDID, param.entryID));
|
|
196
|
+
} catch (err) {
|
|
197
|
+
throw translateCredentialError(err);
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
149
200
|
}
|
|
150
201
|
};
|
|
151
202
|
params.registerProvider('service', {
|
|
@@ -166,6 +217,9 @@ function wrappableDID(identity) {
|
|
|
166
217
|
},
|
|
167
218
|
'credential/delete': {
|
|
168
219
|
allow: true
|
|
220
|
+
},
|
|
221
|
+
'credential/bind-alias': {
|
|
222
|
+
allow: true
|
|
169
223
|
}
|
|
170
224
|
}
|
|
171
225
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/plugin-credential",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -15,18 +15,19 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@kokuin/token": "^0.5.0",
|
|
18
|
-
"@kubun/credential": "^0.17.
|
|
18
|
+
"@kubun/credential": "^0.17.1",
|
|
19
19
|
"@kubun/db": "^0.17.0",
|
|
20
|
-
"@kubun/engine": "^0.17.
|
|
21
|
-
"@kubun/graphql": "^0.17.
|
|
20
|
+
"@kubun/engine": "^0.17.1",
|
|
21
|
+
"@kubun/graphql": "^0.17.1",
|
|
22
22
|
"@kubun/hlc": "^0.17.0",
|
|
23
23
|
"@kubun/id": "^0.17.0",
|
|
24
24
|
"@kubun/plugin-service-api": "^0.17.0",
|
|
25
25
|
"@kubun/plugin-service-server": "^0.17.0",
|
|
26
|
-
"@kubun/
|
|
26
|
+
"@kubun/protocol": "^0.17.0",
|
|
27
|
+
"@kubun/store-credential": "^0.17.3",
|
|
27
28
|
"@sozai/codec": "^0.4.0",
|
|
28
29
|
"@sozai/runtime": "^0.1.0",
|
|
29
|
-
"graphql": "^
|
|
30
|
+
"graphql": "^17.0.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@enkaku/client": "^0.21.2",
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"@kokuin/capability": "^0.3.0",
|
|
35
36
|
"@kokuin/controller": "^0.1.0",
|
|
36
37
|
"@kubun/db-better-sqlite": "^0.17.0",
|
|
37
|
-
"@kubun/service-credential-api": "^0.17.
|
|
38
|
+
"@kubun/service-credential-api": "^0.17.1",
|
|
38
39
|
"@kubun/store-controller": "^0.17.0",
|
|
39
40
|
"@kubun/store-graph": "^0.17.0",
|
|
40
41
|
"@kubun/test-utils": "^0.0.0"
|