@kokuin/token 0.5.1 → 0.6.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/did.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DIDResolver } from './cache.js';
2
- import { type MethodRegistry } from './method.js';
2
+ import { type MethodRegistry, type ResolvedSigningKey } from './method.js';
3
3
  import type { DIDDoc } from './peer4.js';
4
4
  import type { SignatureAlgorithm } from './schemas.js';
5
5
  import type { DIDString } from './types.js';
@@ -142,3 +142,13 @@ export declare function normalizeDID(did: string): string;
142
142
  * A sender MUST use the published key: the derived one is a different key and will not decrypt.
143
143
  */
144
144
  export declare function getAgreementKey(doc: DIDDoc): Uint8Array | null;
145
+ /**
146
+ * The signing keys a DID carries in its identifier, or `null` when it carries none. `did:key` is its
147
+ * key; a `did:peer:4` long form embeds the document, so its `authentication` keys (signing is what
148
+ * a pin or a membership is for) are readable from the string. Anything network-backed -- a
149
+ * short-form `did:peer:4`, `did:kokuin:` -- answers `null` rather than looking up.
150
+ *
151
+ * Throws on an identifier that claims to carry a key and does not; the caller treats that as no
152
+ * match.
153
+ */
154
+ export declare function signingKeysOf(did: string): Array<ResolvedSigningKey> | null;
package/lib/did.js CHANGED
@@ -365,3 +365,47 @@ function resolveKidFromDoc(doc, kid) {
365
365
  }
366
366
  return null;
367
367
  }
368
+ /** As long as `resolveKidFromDoc` allows: base58 decoding is O(n^2). */ const MAX_KEY_ENCODED = 64;
369
+ /**
370
+ * The signing keys a DID carries in its identifier, or `null` when it carries none. `did:key` is its
371
+ * key; a `did:peer:4` long form embeds the document, so its `authentication` keys (signing is what
372
+ * a pin or a membership is for) are readable from the string. Anything network-backed -- a
373
+ * short-form `did:peer:4`, `did:kokuin:` -- answers `null` rather than looking up.
374
+ *
375
+ * Throws on an identifier that claims to carry a key and does not; the caller treats that as no
376
+ * match.
377
+ */ export function signingKeysOf(did) {
378
+ if (did.startsWith('did:key:')) {
379
+ const [alg, publicKey] = getSignatureInfo(did);
380
+ return [
381
+ {
382
+ alg,
383
+ publicKey
384
+ }
385
+ ];
386
+ }
387
+ if (!isPeer4(did) || did === getPeer4ShortForm(did)) {
388
+ return null;
389
+ }
390
+ const { doc } = decodePeer4(did);
391
+ const keys = [];
392
+ for (const id of doc.authentication ?? []){
393
+ const method = doc.verificationMethod.find((entry)=>entry.id === id);
394
+ if (method == null || method.publicKeyMultibase.length > MAX_KEY_ENCODED) {
395
+ continue;
396
+ }
397
+ let info = null;
398
+ try {
399
+ info = getAlgorithmAndPublicKey(decodeMultibase(method.publicKeyMultibase));
400
+ } catch {
401
+ continue;
402
+ }
403
+ if (info != null) {
404
+ keys.push({
405
+ alg: info[0],
406
+ publicKey: info[1]
407
+ });
408
+ }
409
+ }
410
+ return keys;
411
+ }
package/lib/index.d.ts CHANGED
@@ -10,10 +10,10 @@
10
10
  * @module token
11
11
  */
12
12
  export { type CreateInMemoryDIDCacheOptions, createInMemoryDIDCache, type DIDCache, type DIDResolver, } from './cache.js';
13
- export { CODECS, getAgreementKey, getAlgorithmAndPublicKey, getDID, getSignatureInfo, IssuerKeyNotFoundError, isIssuerKeyNotFoundError, isUnresolvableIssuerError, normalizeDID, type ResolveIssuerHeader, type ResolveIssuerMode, type ResolveIssuerWithDocResult, resolveIssuer, resolveIssuerWithDoc, UnresolvableIssuerError, } from './did.js';
13
+ export { CODECS, getAgreementKey, getAlgorithmAndPublicKey, getDID, getSignatureInfo, IssuerKeyNotFoundError, isIssuerKeyNotFoundError, isUnresolvableIssuerError, normalizeDID, type ResolveIssuerHeader, type ResolveIssuerMode, type ResolveIssuerWithDocResult, resolveIssuer, resolveIssuerWithDoc, signingKeysOf, UnresolvableIssuerError, } from './did.js';
14
14
  export { type CreateIdentityInput, createFullIdentity, createIdentity, createKeyAgreementIdentity, createKeyAgreementIdentityForDID, createSigningIdentity, createSigningIdentityForDID, type FullIdentity, type Identity, type IdentityKeySpec, type IdentityProvider, isFullIdentity, isKeyAgreementIdentity, isOwnIdentity, isSigningIdentity, type KeyAgreementIdentity, type KeyAlg, type KeyPurpose, type MultiKeyIdentity, type OwnIdentity, type ResolvedKey, randomIdentity, type SigningIdentity, type SignTokenOptions, } from './identity.js';
15
15
  export type { KeyEntry, KeyStore, MutableKeyEntry } from './keystore.js';
16
- export { type AgreementAlgorithm, type DIDMethodResolver, findMethodResolver, type MethodRegistry, type ResolvedAgreementKey, type ResolvedSigningKey, } from './method.js';
16
+ export { type AgreementAlgorithm, type DIDMethodResolver, findMethodResolver, type MemberQuery, type MethodRegistry, type ResolvedAgreementKey, type ResolvedMember, type ResolvedSigningKey, } from './method.js';
17
17
  export { decodeMultibase, encodeMultibase, multihashSHA256, verifyMultihash, } from './multibase.js';
18
18
  export { type DecodePeer4Options, type DIDDoc, decodePeer4, encodePeer4, getPeer4ShortForm, isPeer4, type VerificationMethod, validateDIDDoc, } from './peer4.js';
19
19
  export { capabilitySchema, type SignatureAlgorithm, type SignedHeader, type SignedPayload, type SupportedHeader, signedHeaderSchema, signedPayloadSchema, supportedHeaderSchema, type UnsignedHeader, unsignedHeaderSchema, validateAlgorithm, validateSignedHeader, validateSignedPayload, validateUnsignedHeader, } from './schemas.js';
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @module token
11
11
  */ export { createInMemoryDIDCache } from './cache.js';
12
- export { CODECS, getAgreementKey, getAlgorithmAndPublicKey, getDID, getSignatureInfo, IssuerKeyNotFoundError, isIssuerKeyNotFoundError, isUnresolvableIssuerError, normalizeDID, resolveIssuer, resolveIssuerWithDoc, UnresolvableIssuerError } from './did.js';
12
+ export { CODECS, getAgreementKey, getAlgorithmAndPublicKey, getDID, getSignatureInfo, IssuerKeyNotFoundError, isIssuerKeyNotFoundError, isUnresolvableIssuerError, normalizeDID, resolveIssuer, resolveIssuerWithDoc, signingKeysOf, UnresolvableIssuerError } from './did.js';
13
13
  export { createFullIdentity, createIdentity, createKeyAgreementIdentity, createKeyAgreementIdentityForDID, createSigningIdentity, createSigningIdentityForDID, isFullIdentity, isKeyAgreementIdentity, isOwnIdentity, isSigningIdentity, randomIdentity } from './identity.js';
14
14
  export { findMethodResolver } from './method.js';
15
15
  export { decodeMultibase, encodeMultibase, multihashSHA256, verifyMultihash } from './multibase.js';
package/lib/method.d.ts CHANGED
@@ -5,6 +5,17 @@ export type ResolvedSigningKey = {
5
5
  alg: SignatureAlgorithm;
6
6
  publicKey: Uint8Array;
7
7
  };
8
+ /** The member of a subject's management tier being asked about: its DID, `add` digest and generation. */
9
+ export type MemberQuery = {
10
+ did: string;
11
+ add: string;
12
+ gen: number;
13
+ };
14
+ /** The signing key a subject's log pins for a member, and when that membership lapses (unix seconds). */
15
+ export type ResolvedMember = {
16
+ key: ResolvedSigningKey;
17
+ lease: number;
18
+ };
8
19
  export type AgreementAlgorithm = 'X25519';
9
20
  /** A key agreement key a DID method resolved for a recipient. */
10
21
  export type ResolvedAgreementKey = {
@@ -64,6 +75,17 @@ export type DIDMethodResolver = {
64
75
  * break every implementation for a member most methods have no answer for.
65
76
  */
66
77
  resolveDenySet?(did: string): Promise<ReadonlySet<string>>;
78
+ /**
79
+ * The key and lease the subject's log holds for one **member** of its management tier, answered for
80
+ * **now**. A grant issued by a member rather than by the subject's own key is valid only while that
81
+ * membership is live, so the verifier asks the log rather than trusting the grant's claims.
82
+ *
83
+ * Optional, and its **absence fails closed**: a method that cannot answer refuses every
84
+ * member-issued grant rather than falling back to {@link resolve}, which names the subject's own
85
+ * keys and would answer a different question. A member that is unknown, removed or lapsed must
86
+ * reject, never resolve.
87
+ */
88
+ resolveMember?(subject: string, member: MemberQuery): Promise<ResolvedMember>;
67
89
  };
68
90
  export type MethodRegistry = ReadonlyArray<DIDMethodResolver>;
69
91
  /** Total: a malformed DID yields `undefined` rather than throwing. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokuin/token",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "JWT signing and verification",
5
5
  "keywords": [
6
6
  "json",
@@ -30,13 +30,13 @@
30
30
  "@noble/curves": "^2.4.0",
31
31
  "@noble/hashes": "^2.4.0",
32
32
  "@scure/base": "^2.4.0",
33
- "@sozai/codec": "^0.4.2",
34
- "@sozai/otel": "^0.3.3",
33
+ "@sozai/codec": "^0.4.3",
34
+ "@sozai/otel": "^0.3.4",
35
35
  "@sozai/schema": "^0.1.6"
36
36
  },
37
37
  "devDependencies": {
38
- "@opentelemetry/sdk-trace-base": "^2.12.0",
39
- "@opentelemetry/sdk-trace-node": "^2.12.0",
38
+ "@opentelemetry/api": "^1.10.0",
39
+ "@opentelemetry/sdk-trace": "^3.0.0",
40
40
  "uint8arrays": "^6.1.1"
41
41
  },
42
42
  "publishConfig": {