@kubun/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/index.d.ts CHANGED
@@ -24,3 +24,4 @@ export type { Argon2Cost, CredentialSuite, FactorInput, FactorInputs, SecretFact
24
24
  export { DEFAULT_ARGON2_COST, getSuite, isSupportedSuite, SUITE_KUBUN_CRED_1 } from './suite.js';
25
25
  export { assertValidCredentialShape } from './validate.js';
26
26
  export { CREDENTIAL_ADMINISTER_ACTION, credentialUserResource } from './vocabulary.js';
27
+ export { wrappableDID } from './wrappable.js';
package/lib/index.js CHANGED
@@ -12,3 +12,4 @@ export { RefreshingCredentialProvider } from './refreshing-credential-provider.j
12
12
  export { DEFAULT_ARGON2_COST, getSuite, isSupportedSuite, SUITE_KUBUN_CRED_1 } from './suite.js';
13
13
  export { assertValidCredentialShape } from './validate.js';
14
14
  export { CREDENTIAL_ADMINISTER_ACTION, credentialUserResource } from './vocabulary.js';
15
+ export { wrappableDID } from './wrappable.js';
package/lib/manager.js CHANGED
@@ -8,6 +8,7 @@ import { createCredentialOpSigner, selectWinningBranch } from './op.js';
8
8
  import { createPinThrottle } from './pin-throttle.js';
9
9
  import { entryProvenanceFields } from './provenance.js';
10
10
  import { getSuite, isSupportedSuite, SUITE_KUBUN_CRED_1 } from './suite.js';
11
+ import { wrappableDID } from './wrappable.js';
11
12
  /** Kinds a user can be prompted for, as opposed to ones held as key material. */ const SECRET_FACTOR_KINDS = [
12
13
  'passphrase',
13
14
  'pin'
@@ -538,7 +539,7 @@ export function createCredentialManager(params) {
538
539
  if (createParams.factors != null && createParams.wrappings != null) {
539
540
  throw new InvalidCredentialFactors('pass either "factors" or "wrappings", not both');
540
541
  }
541
- // The headless default: one wrapping to this device's own identity. Taking
542
+ // The headless default: one wrapping to this device's wrappable form. Taking
542
543
  // it without a decrypting identity would mint a key whose only wrapping
543
544
  // this device can never open, so it refuses here rather than at first read.
544
545
  const explicit = createParams.wrappings ?? (createParams.factors && [
@@ -548,7 +549,7 @@ export function createCredentialManager(params) {
548
549
  [
549
550
  {
550
551
  kind: 'did',
551
- recipientDID: identity.id
552
+ recipientDID: wrappableDID(identity)
552
553
  }
553
554
  ]
554
555
  ];
package/lib/provider.js CHANGED
@@ -15,6 +15,9 @@ export function serializeCredential(credential) {
15
15
  if (credential.metadata != null) {
16
16
  serialized.metadata = credential.metadata;
17
17
  }
18
+ if (credential.providerAccount != null) {
19
+ serialized.providerAccount = credential.providerAccount;
20
+ }
18
21
  return JSON.stringify(serialized);
19
22
  }
20
23
  export function deserializeCredential(raw) {
@@ -36,6 +39,9 @@ export function deserializeCredential(raw) {
36
39
  if (parsed.metadata != null) {
37
40
  credential.metadata = parsed.metadata;
38
41
  }
42
+ if (parsed.providerAccount != null) {
43
+ credential.providerAccount = parsed.providerAccount;
44
+ }
39
45
  return credential;
40
46
  }
41
47
  export class DBCredentialProvider {
@@ -146,7 +146,8 @@ export class RefreshingCredentialProvider {
146
146
  expiresAt: tokenData.expires_in != null ? new Date(Date.now() + tokenData.expires_in * 1000) : undefined,
147
147
  scopes: tokenData.scope?.split(' ') ?? credential.scopes,
148
148
  accountLabel: credential.accountLabel,
149
- metadata: credential.metadata
149
+ metadata: credential.metadata,
150
+ providerAccount: credential.providerAccount
150
151
  };
151
152
  let write;
152
153
  try {
package/lib/validate.js CHANGED
@@ -27,4 +27,10 @@ export function assertValidCredentialShape(value) {
27
27
  if (c.metadata != null && (typeof c.metadata !== 'object' || Array.isArray(c.metadata))) {
28
28
  throw new CredentialInvalidEntry('metadata must be an object when present');
29
29
  }
30
+ if (c.providerAccount != null) {
31
+ const pa = c.providerAccount;
32
+ if (typeof pa !== 'object' || Array.isArray(c.providerAccount) || typeof pa.iss !== 'string' || pa.iss.length === 0 || typeof pa.sub !== 'string' || pa.sub.length === 0) {
33
+ throw new CredentialInvalidEntry('providerAccount must have non-empty string iss and sub when present');
34
+ }
35
+ }
30
36
  }
@@ -0,0 +1,14 @@
1
+ import type { Identity } from '@kokuin/token';
2
+ /**
3
+ * The spelling of a DID that can be encrypted to.
4
+ *
5
+ * `Identity` declares `id` alone, but a `did:peer:4` identity is a
6
+ * `MultiKeyIdentity` and carries `longForm` on the value. The short form
7
+ * resolves no document and so no agreement key — `deriveSharedSecret` refuses it
8
+ * outright, which is the good failure. The bad one is a key derived from the
9
+ * wrong branch, which throws nothing and yields ciphertext nobody can open.
10
+ *
11
+ * For `did:key` the two forms are the same string, so this is the identity's own
12
+ * `id`.
13
+ */
14
+ export declare function wrappableDID(identity: Identity): string;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The spelling of a DID that can be encrypted to.
3
+ *
4
+ * `Identity` declares `id` alone, but a `did:peer:4` identity is a
5
+ * `MultiKeyIdentity` and carries `longForm` on the value. The short form
6
+ * resolves no document and so no agreement key — `deriveSharedSecret` refuses it
7
+ * outright, which is the good failure. The bad one is a key derived from the
8
+ * wrong branch, which throws nothing and yields ciphertext nobody can open.
9
+ *
10
+ * For `did:key` the two forms are the same string, so this is the identity's own
11
+ * `id`.
12
+ */ export function wrappableDID(identity) {
13
+ const longForm = identity.longForm;
14
+ return typeof longForm === 'string' ? longForm : identity.id;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/credential",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -16,9 +16,9 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@kokuin/jwe": "^0.1.0",
19
- "@kokuin/oauth": "^0.1.0",
19
+ "@kokuin/oauth": "^0.1.1",
20
20
  "@kokuin/token": "^0.5.0",
21
- "@kubun/credential-types": "^0.17.1",
21
+ "@kubun/credential-types": "^0.17.2",
22
22
  "@kubun/db": "^0.17.0",
23
23
  "@kubun/hlc": "^0.17.0",
24
24
  "@kubun/id": "^0.17.0",