@midnight-ntwrk/midnight-did 0.5.0-rc1
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/LICENSE +201 -0
- package/README.md +71 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger-to-domain.d.ts +28 -0
- package/dist/ledger-to-domain.d.ts.map +1 -0
- package/dist/ledger-to-domain.js +341 -0
- package/dist/ledger-to-domain.js.map +1 -0
- package/dist/midnight-did-document.d.ts +98 -0
- package/dist/midnight-did-document.d.ts.map +1 -0
- package/dist/midnight-did-document.js +197 -0
- package/dist/midnight-did-document.js.map +1 -0
- package/dist/midnight-did-resolver.d.ts +30 -0
- package/dist/midnight-did-resolver.d.ts.map +1 -0
- package/dist/midnight-did-resolver.js +65 -0
- package/dist/midnight-did-resolver.js.map +1 -0
- package/dist/midnight.d.ts +2 -0
- package/dist/midnight.d.ts.map +1 -0
- package/dist/midnight.js +2 -0
- package/dist/midnight.js.map +1 -0
- package/dist/offchain-midnight-did.d.ts +12 -0
- package/dist/offchain-midnight-did.d.ts.map +1 -0
- package/dist/offchain-midnight-did.js +22 -0
- package/dist/offchain-midnight-did.js.map +1 -0
- package/package.json +66 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger-to-domain.js","sourceRoot":"","sources":["../src/ledger-to-domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,SAAS,EAET,eAAe,EACf,OAAO,EACP,wBAAwB,EAExB,kBAAkB,EAElB,qBAAqB,EAErB,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,uBAAuB,GAGxB,MAAM,eAAe,CAA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CAAC,gBAAgB,CAAC,CAAC;QAChD,IAAI,SAAS,GAAG,OAAO,IAAI,SAAS,GAAG,EAAE;YAAE,OAAO,SAAS,CAAC;QAC5D,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;YAAE,OAAO,SAAS,CAAC;QACjD,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QACjD,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC","sourcesContent":["import { DIDContract } from \"@midnight-ntwrk/midnight-did-contract\";\nimport {\n createService,\n createVerificationMethod,\n CurveType,\n DIDDocumentMetadata,\n encodeBase64Url,\n KeyType,\n normalizeServiceEndpoint,\n PublicKeyJwk,\n PublicKeyJwkSchema,\n Service,\n ServiceEndpointSchema,\n VerificationMethod,\n VerificationMethodRelationType,\n VerificationMethodType,\n} from \"@midnight-ntwrk/midnight-did-domain\";\n\nimport {\n createMidnightDIDString,\n MidnightNetwork,\n parseContractAddress,\n} from \"./midnight.js\";\nimport {\n createMidnightDIDDocument,\n MidnightDIDDocument,\n} from \"./midnight-did-document.js\";\n\nconst bytesToHex = (bytes: Iterable<number>): string => {\n let hex = \"\";\n for (const byte of bytes) {\n hex += Number(byte).toString(16).padStart(2, \"0\");\n }\n return hex;\n};\n\nconst LedgerCurveType = DIDContract.CurveType;\nconst LedgerKeyType = DIDContract.KeyType;\nconst LedgerVerificationMethodType = DIDContract.VerificationMethodType;\nconst LedgerVerificationMethodRelation = DIDContract.VerificationMethodRelation;\n\ntype LedgerKeyTypeValue = (typeof LedgerKeyType)[keyof typeof LedgerKeyType];\ntype LedgerCurveTypeValue =\n (typeof LedgerCurveType)[keyof typeof LedgerCurveType];\ntype LedgerVerificationMethodTypeValue =\n (typeof LedgerVerificationMethodType)[keyof typeof LedgerVerificationMethodType];\ntype LedgerVerificationMethodRelationValue =\n (typeof LedgerVerificationMethodRelation)[keyof typeof LedgerVerificationMethodRelation];\ntype Ledger = DIDContract.Ledger;\ntype LedgerPublicKeyJwk = DIDContract.PublicKeyJwk;\ntype LedgerSchnorrJubjubVerificationMethod =\n DIDContract.SchnorrJubjubVerificationMethod;\ntype LedgerService = DIDContract.Service;\n\nconst bigintTo32Le = (value: bigint): Uint8Array => {\n if (value < 0n) {\n throw new Error(\"Jubjub public key coordinate must be non-negative\");\n }\n const bytes = new Uint8Array(32);\n let remaining = value;\n for (let i = 0; i < bytes.length; i += 1) {\n bytes[i] = Number(remaining & 0xffn);\n remaining >>= 8n;\n }\n if (remaining !== 0n) {\n throw new Error(\"Jubjub public key coordinate does not fit in 32 bytes\");\n }\n return bytes;\n};\n\nexport class LedgerToDomain {\n private static readonly KeyTypeMap: Record<LedgerKeyTypeValue, KeyType> = {\n [LedgerKeyType.EC]: KeyType.EC,\n [LedgerKeyType.RSA]: KeyType.RSA,\n [LedgerKeyType.oct]: KeyType.oct,\n [LedgerKeyType.OKP]: KeyType.OKP,\n };\n\n private static readonly CurveTypeMap: Record<\n LedgerCurveTypeValue,\n CurveType\n > = {\n [LedgerCurveType.Ed25519]: CurveType.Ed25519,\n [LedgerCurveType.X25519]: CurveType.X25519,\n [LedgerCurveType.Jubjub]: CurveType.Jubjub,\n [LedgerCurveType.P256]: CurveType.P256,\n [LedgerCurveType.Secp256k1]: CurveType.Secp256k1,\n [LedgerCurveType.BLS12381G1]: CurveType.BLS12381G1,\n [LedgerCurveType.BLS12381G2]: CurveType.BLS12381G2,\n };\n\n private static readonly VerificationMethodTypeMap: Record<\n LedgerVerificationMethodTypeValue,\n VerificationMethodType\n > = {\n [LedgerVerificationMethodType.Undefined]: VerificationMethodType.Undefined,\n [LedgerVerificationMethodType.JsonWebKey]:\n VerificationMethodType.JsonWebKey,\n };\n\n private static readonly VerificationMethodRelationMap: Record<\n LedgerVerificationMethodRelationValue,\n VerificationMethodRelationType\n > = {\n [LedgerVerificationMethodRelation.Undefined]:\n VerificationMethodRelationType.Undefined,\n [LedgerVerificationMethodRelation.Authentication]:\n VerificationMethodRelationType.Authentication,\n [LedgerVerificationMethodRelation.AssertionMethod]:\n VerificationMethodRelationType.AssertionMethod,\n [LedgerVerificationMethodRelation.KeyAgreement]:\n VerificationMethodRelationType.KeyAgreement,\n [LedgerVerificationMethodRelation.CapabilityInvocation]:\n VerificationMethodRelationType.CapabilityInvocation,\n [LedgerVerificationMethodRelation.CapabilityDelegation]:\n VerificationMethodRelationType.CapabilityDelegation,\n };\n\n static publicKeyJwk(publicKeyJwk: LedgerPublicKeyJwk): PublicKeyJwk {\n const kty = this.KeyTypeMap[publicKeyJwk.kty];\n const crv = this.CurveTypeMap[publicKeyJwk.crv];\n const x = this.ledgerOpaqueString(publicKeyJwk.x, \"publicKeyJwk.x\");\n const y = this.ledgerOpaqueString(publicKeyJwk.y, \"publicKeyJwk.y\");\n\n if (\n kty === KeyType.OKP &&\n (crv === CurveType.Ed25519 ||\n crv === CurveType.X25519 ||\n crv === CurveType.BLS12381G1 ||\n crv === CurveType.BLS12381G2)\n ) {\n if (y !== \"\") {\n throw new Error(\"OKP ledger publicKeyJwk.y must be empty\");\n }\n return PublicKeyJwkSchema.parse({ kty, crv, x });\n }\n\n return PublicKeyJwkSchema.parse({ kty, crv, x, y });\n }\n\n static schnorrJubjubPublicKeyJwk(\n verificationMethod: LedgerSchnorrJubjubVerificationMethod,\n ): PublicKeyJwk {\n return PublicKeyJwkSchema.parse({\n kty: KeyType.EC,\n crv: CurveType.Jubjub,\n x: encodeBase64Url(bigintTo32Le(verificationMethod.publicKey.x)),\n y: encodeBase64Url(bigintTo32Le(verificationMethod.publicKey.y)),\n });\n }\n\n private static ledgerOpaqueString(value: unknown, label: string): string {\n if (typeof value === \"string\") return value;\n if (value instanceof Uint8Array) return new TextDecoder().decode(value);\n if (ArrayBuffer.isView(value)) {\n const view = value as ArrayBufferView;\n return new TextDecoder().decode(\n new Uint8Array(view.buffer, view.byteOffset, view.byteLength),\n );\n }\n const shape =\n value === null\n ? \"null\"\n : typeof value === \"object\"\n ? (value.constructor?.name ?? \"object\")\n : typeof value;\n throw new Error(`${label} has an unsupported runtime shape: ${shape}`);\n }\n\n static service(service: LedgerService): Service {\n const rawId = service.id.trim();\n const needsFragmentPrefix =\n rawId.startsWith(\"//\") ||\n (!rawId.startsWith(\"did:\") &&\n !rawId.startsWith(\"#\") &&\n !rawId.startsWith(\"/\") &&\n !rawId.startsWith(\".\") &&\n !rawId.startsWith(\"?\"));\n const serviceId = needsFragmentPrefix ? `#${rawId}` : rawId;\n\n const serviceEndpoint = this.parseServiceEndpoint(service.serviceEndpoint);\n const serviceType = this.parseServiceType(\n (service as { typ?: string; type?: string }).typ ??\n (service as { typ?: string; type?: string }).type ??\n \"\",\n );\n return {\n id: serviceId,\n type: serviceType,\n serviceEndpoint,\n } as Service;\n }\n\n private static parseServiceType(raw: string): Service[\"type\"] {\n const value = raw.trim();\n if (value.length === 0) {\n throw new Error(\"Invalid service type: empty value\");\n }\n if (value.startsWith(\"[\")) {\n try {\n const parsed = JSON.parse(value);\n if (\n Array.isArray(parsed) &&\n parsed.length > 0 &&\n parsed.every(\n (entry) => typeof entry === \"string\" && entry.trim().length > 0,\n ) &&\n new Set(parsed.map((entry) => entry.trim())).size === parsed.length\n ) {\n return parsed.map((entry) => entry.trim());\n }\n } catch {\n throw new Error(\"Invalid service type: malformed JSON array\");\n }\n throw new Error(\n \"Invalid service type: expected non-empty unique strings\",\n );\n }\n return value;\n }\n\n private static parseServiceEndpoint(\n endpoint: unknown,\n ): Service[\"serviceEndpoint\"] {\n const normalize = (\n value: Service[\"serviceEndpoint\"],\n ): Service[\"serviceEndpoint\"] => normalizeServiceEndpoint(value);\n\n if (Array.isArray(endpoint)) {\n const filtered = endpoint\n .map((value) => (typeof value === \"string\" ? value.trim() : \"\"))\n .filter((value) => value !== \"\");\n if (filtered.length === 0) {\n throw new Error(\"Invalid serviceEndpoint: empty legacy endpoint array\");\n }\n if (filtered.length === 1) return normalize(filtered[0]);\n return normalize(filtered as Service[\"serviceEndpoint\"]);\n }\n\n if (typeof endpoint === \"string\") {\n const raw = endpoint.trim();\n if (raw === \"\") {\n throw new Error(\"Invalid serviceEndpoint: empty value\");\n }\n try {\n const parsed = JSON.parse(raw);\n return normalize(\n ServiceEndpointSchema.parse(parsed) as Service[\"serviceEndpoint\"],\n );\n } catch {\n const direct = ServiceEndpointSchema.safeParse(raw);\n if (direct.success) {\n return normalize(direct.data as Service[\"serviceEndpoint\"]);\n }\n throw new Error(\"Invalid serviceEndpoint: malformed JSON payload\");\n }\n }\n\n const parsed = ServiceEndpointSchema.safeParse(endpoint);\n if (parsed.success) {\n return normalize(parsed.data as Service[\"serviceEndpoint\"]);\n }\n throw new Error(\"Invalid serviceEndpoint: unsupported endpoint shape\");\n }\n\n static verificationMethodId(id: string): string {\n const rawId = id.trim();\n if (rawId.startsWith(\"did:\")) {\n if (rawId.includes(\"#\")) return rawId;\n return `${rawId}#${rawId.slice(rawId.lastIndexOf(\":\") + 1)}`;\n }\n const needsFragmentPrefix =\n !rawId.startsWith(\"#\") &&\n !rawId.startsWith(\"/\") &&\n !rawId.startsWith(\".\") &&\n !rawId.startsWith(\"?\");\n return needsFragmentPrefix ? `#${rawId}` : rawId;\n }\n\n static absoluteDidUrlReference(did: string, id: string): string {\n const normalized = this.verificationMethodId(id);\n if (normalized.startsWith(\"did:\")) return normalized;\n return `${did}${normalized}`;\n }\n\n static toJSON(ledger: Ledger): object {\n const created = this.timestampToIsoString(ledger.created);\n const updated = this.timestampToIsoString(ledger.updated);\n const opaqueVerificationMethods = Array.from(\n ledger.verificationMethods,\n ([id, method]) => ({\n id: this.verificationMethodId(id),\n type: this.VerificationMethodTypeMap[method.typ],\n publicKeyJwk: this.publicKeyJwk(method.publicKeyJwk),\n }),\n );\n const schnorrJubjubVerificationMethods = Array.from(\n ledger.schnorrJubjubVerificationMethods,\n ([id, method]) => ({\n id: this.verificationMethodId(id),\n type: VerificationMethodType.JsonWebKey,\n publicKeyJwk: this.schnorrJubjubPublicKeyJwk(method),\n }),\n );\n\n return {\n id: bytesToHex(ledger.id.bytes),\n version: Number(ledger.version.toString()),\n active: ledger.active,\n operationCount: Number(ledger.operationCount.toString()),\n created,\n updated,\n deactivated: ledger.deactivated,\n alsoKnownAs: Array.from(ledger.alsoKnownAs),\n verificationMethods: [\n ...opaqueVerificationMethods,\n ...schnorrJubjubVerificationMethods,\n ],\n authenticationRelation: Array.from(\n ledger.authenticationRelation,\n (value) => this.verificationMethodId(value),\n ),\n assertionMethodRelation: Array.from(\n ledger.assertionMethodRelation,\n (value) => this.verificationMethodId(value),\n ),\n keyAgreementRelation: Array.from(ledger.keyAgreementRelation, (value) =>\n this.verificationMethodId(value),\n ),\n capabilityInvocationRelation: Array.from(\n ledger.capabilityInvocationRelation,\n (value) => this.verificationMethodId(value),\n ),\n capabilityDelegationRelation: Array.from(\n ledger.capabilityDelegationRelation,\n (value) => this.verificationMethodId(value),\n ),\n services: Array.from(ledger.services, ([, service]) =>\n this.service(service),\n ),\n };\n }\n\n static ledgerStateToDIDDocument(\n ledger: Ledger,\n network: MidnightNetwork,\n contractAddress: ReturnType<typeof parseContractAddress>,\n ): MidnightDIDDocument {\n const did = createMidnightDIDString(contractAddress, network);\n\n const verificationMethod: VerificationMethod[] = [];\n const verificationMethodIds = new Set<string>();\n const registerVerificationMethodId = (id: string): void => {\n const normalizedId = this.verificationMethodId(id);\n if (verificationMethodIds.has(normalizedId)) {\n throw new Error(\n `Duplicate verification method id '${this.absoluteDidUrlReference(did, id)}'`,\n );\n }\n verificationMethodIds.add(normalizedId);\n };\n\n for (const [id, method] of ledger.verificationMethods) {\n const verificationMethodType =\n LedgerToDomain.VerificationMethodTypeMap[method.typ];\n if (verificationMethodType !== VerificationMethodType.JsonWebKey) {\n throw new Error(\n `Unsupported verification method type for id '${id}': ${verificationMethodType}`,\n );\n }\n registerVerificationMethodId(id);\n verificationMethod.push(\n createVerificationMethod({\n id: this.absoluteDidUrlReference(did, id),\n type: verificationMethodType,\n controller: did,\n publicKeyJwk: this.publicKeyJwk(method.publicKeyJwk),\n }),\n );\n }\n\n for (const [id, method] of ledger.schnorrJubjubVerificationMethods) {\n registerVerificationMethodId(id);\n verificationMethod.push(\n createVerificationMethod({\n id: this.absoluteDidUrlReference(did, id),\n type: VerificationMethodType.JsonWebKey,\n controller: did,\n publicKeyJwk: this.schnorrJubjubPublicKeyJwk(method),\n }),\n );\n }\n\n const assertRelationTargetsExist = (\n relationName: string,\n relation: Iterable<string> & { isEmpty(): boolean },\n ) => {\n if (relation.isEmpty()) return;\n for (const methodId of relation) {\n if (!verificationMethodIds.has(this.verificationMethodId(methodId))) {\n throw new Error(\n `${relationName} references missing verification method '${this.absoluteDidUrlReference(did, methodId)}'`,\n );\n }\n }\n };\n\n assertRelationTargetsExist(\"authentication\", ledger.authenticationRelation);\n assertRelationTargetsExist(\n \"assertionMethod\",\n ledger.assertionMethodRelation,\n );\n assertRelationTargetsExist(\"keyAgreement\", ledger.keyAgreementRelation);\n assertRelationTargetsExist(\n \"capabilityInvocation\",\n ledger.capabilityInvocationRelation,\n );\n assertRelationTargetsExist(\n \"capabilityDelegation\",\n ledger.capabilityDelegationRelation,\n );\n\n const mapRelation = (\n relation: Iterable<string> & { isEmpty(): boolean },\n ): string[] | undefined =>\n relation.isEmpty()\n ? undefined\n : Array.from(relation, (value) => this.verificationMethodId(value));\n\n const assertionMethod = mapRelation(ledger.assertionMethodRelation);\n const authentication = mapRelation(ledger.authenticationRelation);\n const capabilityDelegation = mapRelation(\n ledger.capabilityDelegationRelation,\n );\n const capabilityInvocation = mapRelation(\n ledger.capabilityInvocationRelation,\n );\n const keyAgreement = mapRelation(ledger.keyAgreementRelation);\n const service = ledger.services.isEmpty()\n ? undefined\n : Array.from(ledger.services, ([, s]) => {\n const parsed = this.service(s);\n return createService({\n id: this.absoluteDidUrlReference(did, s.id),\n type: parsed.type,\n serviceEndpoint: parsed.serviceEndpoint,\n });\n });\n const alsoKnownAs = ledger.alsoKnownAs.isEmpty()\n ? undefined\n : Array.from(ledger.alsoKnownAs);\n\n return createMidnightDIDDocument({\n id: did,\n verificationMethod,\n authentication,\n assertionMethod,\n keyAgreement,\n capabilityInvocation,\n capabilityDelegation,\n service,\n alsoKnownAs,\n });\n }\n\n static ledgerStateToMetadata(ledger: Ledger): DIDDocumentMetadata {\n const created = this.timestampToIsoString(ledger.created);\n const updated = this.timestampToIsoString(ledger.updated);\n const deactivatedAt = ledger.deactivated\n ? this.timestampToIsoString(ledger.updated)\n : undefined;\n\n const isDeactivated = ledger.deactivated || !ledger.active;\n const metadata: DIDDocumentMetadata = {\n created,\n updated,\n deactivated: isDeactivated ? true : undefined,\n versionId: ledger.version.toString(),\n };\n\n if (isDeactivated && deactivatedAt !== undefined) {\n metadata.updated = deactivatedAt;\n }\n\n return metadata;\n }\n\n private static timestampToIsoString(timestamp: bigint): string | undefined {\n if (timestamp === 0n) return undefined;\n const maxSafe = BigInt(Number.MAX_SAFE_INTEGER);\n if (timestamp > maxSafe || timestamp < 0n) return undefined;\n const milliseconds = Number(timestamp);\n if (Number.isNaN(milliseconds)) return undefined;\n const iso = new Date(milliseconds).toISOString();\n return iso.replace(/\\.\\d{3}Z$/, \"Z\");\n }\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CurveType, DIDKeyID, KeyType, Service, URIString, VerificationMethod, VerificationMethodType } from "@midnight-ntwrk/midnight-did-domain";
|
|
2
|
+
import { z } from "zod/v4-mini";
|
|
3
|
+
import { type MidnightDIDString } from "./midnight.js";
|
|
4
|
+
/** Midnight DID Document Schema with method-specific constraints */
|
|
5
|
+
export declare const MidnightDIDDocumentSchema: z.ZodMiniObject<{
|
|
6
|
+
"@context": z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>;
|
|
7
|
+
id: z.core.$ZodBranded<z.ZodMiniString<string>, "DID", "out">;
|
|
8
|
+
alsoKnownAs: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniArray<z.ZodMiniString<string>>>>;
|
|
9
|
+
controller: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DID", "out">, z.ZodMiniArray<z.core.$ZodBranded<z.ZodMiniString<string>, "DID", "out">>]>>>;
|
|
10
|
+
verificationMethod: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniArray<z.ZodMiniObject<{
|
|
11
|
+
id: z.core.$ZodBranded<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>, "DIDKeyID", "out">;
|
|
12
|
+
type: z.ZodMiniEnum<typeof VerificationMethodType>;
|
|
13
|
+
controller: z.core.$ZodBranded<z.ZodMiniString<string>, "DID", "out">;
|
|
14
|
+
publicKeyJwk: z.ZodMiniObject<{
|
|
15
|
+
kty: z.ZodMiniEnum<typeof KeyType>;
|
|
16
|
+
crv: z.ZodMiniEnum<typeof CurveType>;
|
|
17
|
+
x: z.ZodMiniString<string>;
|
|
18
|
+
y: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
19
|
+
}, z.core.$loose>;
|
|
20
|
+
}, z.core.$strip>>>>;
|
|
21
|
+
authentication: z.ZodMiniOptional<z.ZodMiniArray<z.core.$ZodBranded<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>, "DIDKeyID", "out">>>;
|
|
22
|
+
assertionMethod: z.ZodMiniOptional<z.ZodMiniArray<z.core.$ZodBranded<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>, "DIDKeyID", "out">>>;
|
|
23
|
+
keyAgreement: z.ZodMiniOptional<z.ZodMiniArray<z.core.$ZodBranded<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>, "DIDKeyID", "out">>>;
|
|
24
|
+
capabilityInvocation: z.ZodMiniOptional<z.ZodMiniArray<z.core.$ZodBranded<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>, "DIDKeyID", "out">>>;
|
|
25
|
+
capabilityDelegation: z.ZodMiniOptional<z.ZodMiniArray<z.core.$ZodBranded<z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>, "DIDKeyID", "out">>>;
|
|
26
|
+
service: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniArray<z.ZodMiniObject<{
|
|
27
|
+
id: z.ZodMiniUnion<readonly [z.core.$ZodBranded<z.ZodMiniString<string>, "DIDURL", "out">, z.core.$ZodBranded<z.ZodMiniString<string>, "RelativeURL", "out">]>;
|
|
28
|
+
type: z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>;
|
|
29
|
+
serviceEndpoint: z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>, z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>]>>]>;
|
|
30
|
+
}, z.core.$strip>>>>;
|
|
31
|
+
}, z.core.$loose>;
|
|
32
|
+
/**
|
|
33
|
+
* Midnight DID Document type
|
|
34
|
+
*
|
|
35
|
+
* Extends the generic DIDDocument with Midnight-specific constraints
|
|
36
|
+
*/
|
|
37
|
+
export type MidnightDIDDocument = {
|
|
38
|
+
"@context": [string, string, ...string[]];
|
|
39
|
+
id: MidnightDIDString;
|
|
40
|
+
alsoKnownAs?: URIString[] | null;
|
|
41
|
+
controller?: MidnightDIDString | MidnightDIDString[] | null;
|
|
42
|
+
verificationMethod?: VerificationMethod[] | null;
|
|
43
|
+
authentication?: DIDKeyID[];
|
|
44
|
+
assertionMethod?: DIDKeyID[];
|
|
45
|
+
keyAgreement?: DIDKeyID[];
|
|
46
|
+
capabilityInvocation?: DIDKeyID[];
|
|
47
|
+
capabilityDelegation?: DIDKeyID[];
|
|
48
|
+
service?: Service[] | null;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Create a Midnight DID Document
|
|
52
|
+
*
|
|
53
|
+
* This function creates a DID Document that conforms to the
|
|
54
|
+
* Midnight DID Method Specification.
|
|
55
|
+
*
|
|
56
|
+
* @param params - Document parameters
|
|
57
|
+
* @returns A validated Midnight DID Document
|
|
58
|
+
* @throws {Error} If the document doesn't meet Midnight DID requirements
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const doc = createMidnightDIDDocument({
|
|
63
|
+
* id: "did:midnight:testnet:c569622e7f33d2d020ba1cae242e6077268941327846d62d8cbf0cc923ae41f6",
|
|
64
|
+
* verificationMethod: [{
|
|
65
|
+
* id: "#key-1",
|
|
66
|
+
* type: "JsonWebKey",
|
|
67
|
+
* controller: "did:midnight:testnet:c569622e7f33d2d020ba1cae242e6077268941327846d62d8cbf0cc923ae41f6",
|
|
68
|
+
* publicKeyJwk: {
|
|
69
|
+
* kty: "OKP",
|
|
70
|
+
* crv: "Ed25519",
|
|
71
|
+
* x: "VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ"
|
|
72
|
+
* }
|
|
73
|
+
* }],
|
|
74
|
+
* authentication: ["#key-1"]
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function createMidnightDIDDocument(params: {
|
|
79
|
+
id: MidnightDIDString;
|
|
80
|
+
additionalContexts?: string[];
|
|
81
|
+
alsoKnownAs?: URIString[];
|
|
82
|
+
verificationMethod?: VerificationMethod[];
|
|
83
|
+
authentication?: string[];
|
|
84
|
+
assertionMethod?: string[];
|
|
85
|
+
keyAgreement?: string[];
|
|
86
|
+
capabilityInvocation?: string[];
|
|
87
|
+
capabilityDelegation?: string[];
|
|
88
|
+
service?: Service[];
|
|
89
|
+
}): MidnightDIDDocument;
|
|
90
|
+
/**
|
|
91
|
+
* Parse and validate a Midnight DID Document
|
|
92
|
+
*
|
|
93
|
+
* @param input - The input to parse
|
|
94
|
+
* @returns A validated Midnight DID Document
|
|
95
|
+
* @throws {Error} If the input doesn't meet Midnight DID requirements
|
|
96
|
+
*/
|
|
97
|
+
export declare const parseMidnightDIDDocument: (input: unknown) => MidnightDIDDocument;
|
|
98
|
+
//# sourceMappingURL=midnight-did-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midnight-did-document.d.ts","sourceRoot":"","sources":["../src/midnight-did-document.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAGT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAsE1E,oEAAoE;AACpE,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6CrC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IAC1C,EAAE,EAAE,iBAAiB,CAAC;IACtB,WAAW,CAAC,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAC5D,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;IACjD,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC5B,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,QAAQ,EAAE,CAAC;IAClC,oBAAoB,CAAC,EAAE,QAAQ,EAAE,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,EAAE,EAAE,iBAAiB,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC;IAC1B,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC1C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;CACrB,GAAG,mBAAmB,CAqDtB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,mBAkCF,CAAC"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { CurveType, DIDDocumentSchema, KeyType, VerificationMethodType, } from "@midnight-ntwrk/midnight-did-domain";
|
|
2
|
+
import { z } from "zod/v4-mini";
|
|
3
|
+
import { MidnightDIDSchema } from "./midnight.js";
|
|
4
|
+
/**
|
|
5
|
+
* Midnight DID Document
|
|
6
|
+
*
|
|
7
|
+
* This is a specialized version of DIDDocument that enforces
|
|
8
|
+
* the constraints specified in the Midnight DID Method Specification.
|
|
9
|
+
*
|
|
10
|
+
* Key differences from generic W3C DID Core:
|
|
11
|
+
* - @context MUST be an array with at least 2 specific URIs
|
|
12
|
+
* - id MUST be a valid Midnight DID (did:midnight:<network>:<identifier>)
|
|
13
|
+
* - controller MUST equal the DID subject (single-controller model)
|
|
14
|
+
* - verificationMethod type MUST be JsonWebKey only
|
|
15
|
+
* - Only OKP (Ed25519/X25519/BLS12381G1/BLS12381G2) and EC (Jubjub/P-256/secp256k1) key types are supported
|
|
16
|
+
* - Embedded verification methods are NOT supported (referenced only)
|
|
17
|
+
*/
|
|
18
|
+
const REQUIRED_CONTEXTS = [
|
|
19
|
+
"https://www.w3.org/ns/did/v1",
|
|
20
|
+
"https://w3c.github.io/vc-jws-2020/contexts/v1",
|
|
21
|
+
];
|
|
22
|
+
/** Midnight-specific verification method validation */
|
|
23
|
+
const MidnightVerificationMethodSchema = z
|
|
24
|
+
.looseObject({
|
|
25
|
+
id: z.string(),
|
|
26
|
+
type: z.string(),
|
|
27
|
+
controller: z.string(),
|
|
28
|
+
publicKeyJwk: z.looseObject({
|
|
29
|
+
kty: z.string(),
|
|
30
|
+
crv: z.string(),
|
|
31
|
+
x: z.string(),
|
|
32
|
+
y: z.optional(z.string()),
|
|
33
|
+
}),
|
|
34
|
+
})
|
|
35
|
+
.check(z.refine((vm) => vm.type === VerificationMethodType.JsonWebKey, "Midnight DID only supports JsonWebKey verification method type"), z.refine((vm) => {
|
|
36
|
+
const kty = vm.publicKeyJwk.kty;
|
|
37
|
+
return kty === KeyType.OKP || kty === KeyType.EC;
|
|
38
|
+
}, "Midnight DID only supports OKP (Ed25519/X25519/BLS12381G1/BLS12381G2) or EC (Jubjub/P-256/secp256k1) key types"), z.refine((vm) => {
|
|
39
|
+
const { kty, crv } = vm.publicKeyJwk;
|
|
40
|
+
if (kty === KeyType.OKP) {
|
|
41
|
+
return (crv === CurveType.Ed25519 ||
|
|
42
|
+
crv === CurveType.X25519 ||
|
|
43
|
+
crv === CurveType.BLS12381G1 ||
|
|
44
|
+
crv === CurveType.BLS12381G2);
|
|
45
|
+
}
|
|
46
|
+
if (kty === KeyType.EC) {
|
|
47
|
+
return (crv === CurveType.Jubjub ||
|
|
48
|
+
crv === CurveType.P256 ||
|
|
49
|
+
crv === CurveType.Secp256k1);
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}, "OKP keys must use Ed25519, X25519, BLS12381G1, or BLS12381G2 curve; EC keys must use Jubjub, P-256, or secp256k1 curve"), z.refine((vm) => {
|
|
53
|
+
// Verification methods must be referenced (contain # or be relative)
|
|
54
|
+
const id = vm.id;
|
|
55
|
+
return id.includes("#") || id.startsWith("/") || id.startsWith(".");
|
|
56
|
+
}, "Midnight DID does not support embedded verification methods - use referenced methods with fragments"));
|
|
57
|
+
/** Midnight DID Document Schema with method-specific constraints */
|
|
58
|
+
export const MidnightDIDDocumentSchema = DIDDocumentSchema.check(z.refine((doc) => Array.isArray(doc["@context"]), "@context must be an array for Midnight DID Documents"), z.refine((doc) => Array.isArray(doc["@context"]) && doc["@context"].length >= 2, "@context must contain at least 2 entries for Midnight DID Documents"), z.refine((doc) => Array.isArray(doc["@context"]) &&
|
|
59
|
+
doc["@context"][0] === REQUIRED_CONTEXTS[0], `First @context entry must be '${REQUIRED_CONTEXTS[0]}'`), z.refine((doc) => Array.isArray(doc["@context"]) &&
|
|
60
|
+
doc["@context"][1] === REQUIRED_CONTEXTS[1], `Second @context entry must be '${REQUIRED_CONTEXTS[1]}'`), z.refine((doc) => MidnightDIDSchema.safeParse(doc.id).success, "id must be a valid Midnight DID (did:midnight:<network>:<identifier>)"), z.refine((doc) => {
|
|
61
|
+
// Controller must equal subject (single-controller model)
|
|
62
|
+
if (!doc.controller)
|
|
63
|
+
return true; // Optional, but if present must match
|
|
64
|
+
if (typeof doc.controller === "string") {
|
|
65
|
+
return doc.controller === doc.id;
|
|
66
|
+
}
|
|
67
|
+
// If array, must have exactly one entry equal to id
|
|
68
|
+
return (Array.isArray(doc.controller) &&
|
|
69
|
+
doc.controller.length === 1 &&
|
|
70
|
+
doc.controller[0] === doc.id);
|
|
71
|
+
}, "controller must equal DID subject for Midnight DID (single-controller model)"), z.refine((doc) => {
|
|
72
|
+
// All verification methods must be JsonWebKey and use supported key types
|
|
73
|
+
if (!doc.verificationMethod)
|
|
74
|
+
return true;
|
|
75
|
+
return doc.verificationMethod.every((vm) => MidnightVerificationMethodSchema.safeParse(vm).success);
|
|
76
|
+
}, "All verification methods must meet Midnight DID requirements (JsonWebKey type, OKP/EC keys, referenced only)"));
|
|
77
|
+
/**
|
|
78
|
+
* Create a Midnight DID Document
|
|
79
|
+
*
|
|
80
|
+
* This function creates a DID Document that conforms to the
|
|
81
|
+
* Midnight DID Method Specification.
|
|
82
|
+
*
|
|
83
|
+
* @param params - Document parameters
|
|
84
|
+
* @returns A validated Midnight DID Document
|
|
85
|
+
* @throws {Error} If the document doesn't meet Midnight DID requirements
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const doc = createMidnightDIDDocument({
|
|
90
|
+
* id: "did:midnight:testnet:c569622e7f33d2d020ba1cae242e6077268941327846d62d8cbf0cc923ae41f6",
|
|
91
|
+
* verificationMethod: [{
|
|
92
|
+
* id: "#key-1",
|
|
93
|
+
* type: "JsonWebKey",
|
|
94
|
+
* controller: "did:midnight:testnet:c569622e7f33d2d020ba1cae242e6077268941327846d62d8cbf0cc923ae41f6",
|
|
95
|
+
* publicKeyJwk: {
|
|
96
|
+
* kty: "OKP",
|
|
97
|
+
* crv: "Ed25519",
|
|
98
|
+
* x: "VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ"
|
|
99
|
+
* }
|
|
100
|
+
* }],
|
|
101
|
+
* authentication: ["#key-1"]
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function createMidnightDIDDocument(params) {
|
|
106
|
+
const doc = {
|
|
107
|
+
"@context": [
|
|
108
|
+
REQUIRED_CONTEXTS[0],
|
|
109
|
+
REQUIRED_CONTEXTS[1],
|
|
110
|
+
...(params.additionalContexts ?? []),
|
|
111
|
+
],
|
|
112
|
+
id: params.id,
|
|
113
|
+
alsoKnownAs: params.alsoKnownAs ?? null,
|
|
114
|
+
controller: params.id, // Always equals subject for Midnight DID
|
|
115
|
+
verificationMethod: params.verificationMethod ?? null,
|
|
116
|
+
...(params.authentication === undefined
|
|
117
|
+
? {}
|
|
118
|
+
: { authentication: params.authentication }),
|
|
119
|
+
...(params.assertionMethod === undefined
|
|
120
|
+
? {}
|
|
121
|
+
: { assertionMethod: params.assertionMethod }),
|
|
122
|
+
...(params.keyAgreement === undefined
|
|
123
|
+
? {}
|
|
124
|
+
: { keyAgreement: params.keyAgreement }),
|
|
125
|
+
...(params.capabilityInvocation === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { capabilityInvocation: params.capabilityInvocation }),
|
|
128
|
+
...(params.capabilityDelegation === undefined
|
|
129
|
+
? {}
|
|
130
|
+
: { capabilityDelegation: params.capabilityDelegation }),
|
|
131
|
+
service: params.service ?? null,
|
|
132
|
+
};
|
|
133
|
+
const parsed = MidnightDIDDocumentSchema.parse(doc);
|
|
134
|
+
return {
|
|
135
|
+
"@context": parsed["@context"],
|
|
136
|
+
id: params.id,
|
|
137
|
+
alsoKnownAs: parsed.alsoKnownAs ?? null,
|
|
138
|
+
controller: params.id,
|
|
139
|
+
verificationMethod: parsed.verificationMethod ?? null,
|
|
140
|
+
...(parsed.authentication === undefined
|
|
141
|
+
? {}
|
|
142
|
+
: { authentication: parsed.authentication }),
|
|
143
|
+
...(parsed.assertionMethod === undefined
|
|
144
|
+
? {}
|
|
145
|
+
: { assertionMethod: parsed.assertionMethod }),
|
|
146
|
+
...(parsed.keyAgreement === undefined
|
|
147
|
+
? {}
|
|
148
|
+
: { keyAgreement: parsed.keyAgreement }),
|
|
149
|
+
...(parsed.capabilityInvocation === undefined
|
|
150
|
+
? {}
|
|
151
|
+
: { capabilityInvocation: parsed.capabilityInvocation }),
|
|
152
|
+
...(parsed.capabilityDelegation === undefined
|
|
153
|
+
? {}
|
|
154
|
+
: { capabilityDelegation: parsed.capabilityDelegation }),
|
|
155
|
+
service: parsed.service ?? null,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parse and validate a Midnight DID Document
|
|
160
|
+
*
|
|
161
|
+
* @param input - The input to parse
|
|
162
|
+
* @returns A validated Midnight DID Document
|
|
163
|
+
* @throws {Error} If the input doesn't meet Midnight DID requirements
|
|
164
|
+
*/
|
|
165
|
+
export const parseMidnightDIDDocument = (input) => {
|
|
166
|
+
const parsed = MidnightDIDDocumentSchema.parse(input);
|
|
167
|
+
const id = MidnightDIDSchema.parse(parsed.id);
|
|
168
|
+
const controller = parsed.controller == null
|
|
169
|
+
? parsed.controller
|
|
170
|
+
: Array.isArray(parsed.controller)
|
|
171
|
+
? parsed.controller.map((value) => MidnightDIDSchema.parse(value))
|
|
172
|
+
: MidnightDIDSchema.parse(parsed.controller);
|
|
173
|
+
return {
|
|
174
|
+
"@context": parsed["@context"],
|
|
175
|
+
id,
|
|
176
|
+
alsoKnownAs: parsed.alsoKnownAs ?? null,
|
|
177
|
+
controller,
|
|
178
|
+
verificationMethod: parsed.verificationMethod ?? null,
|
|
179
|
+
...(parsed.authentication === undefined
|
|
180
|
+
? {}
|
|
181
|
+
: { authentication: parsed.authentication }),
|
|
182
|
+
...(parsed.assertionMethod === undefined
|
|
183
|
+
? {}
|
|
184
|
+
: { assertionMethod: parsed.assertionMethod }),
|
|
185
|
+
...(parsed.keyAgreement === undefined
|
|
186
|
+
? {}
|
|
187
|
+
: { keyAgreement: parsed.keyAgreement }),
|
|
188
|
+
...(parsed.capabilityInvocation === undefined
|
|
189
|
+
? {}
|
|
190
|
+
: { capabilityInvocation: parsed.capabilityInvocation }),
|
|
191
|
+
...(parsed.capabilityDelegation === undefined
|
|
192
|
+
? {}
|
|
193
|
+
: { capabilityDelegation: parsed.capabilityDelegation }),
|
|
194
|
+
service: parsed.service ?? null,
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=midnight-did-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midnight-did-document.js","sourceRoot":"","sources":["../src/midnight-did-document.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,iBAAiB,EAEjB,OAAO,EAIP,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAA0B,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;GAaG;AAEH,MAAM,iBAAiB,GAAG;IACxB,8BAA8B;IAC9B,+CAA+C;CACvC,CAAC;AAEX,uDAAuD;AACvD,MAAM,gCAAgC,GAAG,CAAC;KACvC,WAAW,CAAC;IACX,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,YAAY,EAAE,CAAC,CAAC,WAAW,CAAC;QAC1B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;QACb,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KAC1B,CAAC;CACH,CAAC;KACD,KAAK,CACJ,CAAC,CAAC,MAAM,CACN,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,sBAAsB,CAAC,UAAU,EACrD,gE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,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC;QAC9C,GAAG,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS;YACtC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QAChD,GAAG,CAAC,MAAM,CAAC,YAAY,KAAK,SAAS;YACnC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;QAC1C,GAAG,CAAC,MAAM,CAAC,oBAAoB,KAAK,SAAS;YAC3C,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,oBAAoB,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC;QAC1D,GAAG,CAAC,MAAM,CAAC,oBAAoB,KAAK,SAAS;YAC3C,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,oBAAoB,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC;QAC1D,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;KACT,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import {\n CurveType,\n DIDDocument,\n DIDDocumentSchema,\n DIDKeyID,\n KeyType,\n Service,\n URIString,\n VerificationMethod,\n VerificationMethodType,\n} from \"@midnight-ntwrk/midnight-did-domain\";\nimport { z } from \"zod/v4-mini\";\n\nimport { MidnightDIDSchema, type MidnightDIDString } from \"./midnight.js\";\n\n/**\n * Midnight DID Document\n *\n * This is a specialized version of DIDDocument that enforces\n * the constraints specified in the Midnight DID Method Specification.\n *\n * Key differences from generic W3C DID Core:\n * - @context MUST be an array with at least 2 specific URIs\n * - id MUST be a valid Midnight DID (did:midnight:<network>:<identifier>)\n * - controller MUST equal the DID subject (single-controller model)\n * - verificationMethod type MUST be JsonWebKey only\n * - Only OKP (Ed25519/X25519/BLS12381G1/BLS12381G2) and EC (Jubjub/P-256/secp256k1) key types are supported\n * - Embedded verification methods are NOT supported (referenced only)\n */\n\nconst REQUIRED_CONTEXTS = [\n \"https://www.w3.org/ns/did/v1\",\n \"https://w3c.github.io/vc-jws-2020/contexts/v1\",\n] as const;\n\n/** Midnight-specific verification method validation */\nconst MidnightVerificationMethodSchema = z\n .looseObject({\n id: z.string(),\n type: z.string(),\n controller: z.string(),\n publicKeyJwk: z.looseObject({\n kty: z.string(),\n crv: z.string(),\n x: z.string(),\n y: z.optional(z.string()),\n }),\n })\n .check(\n z.refine(\n (vm) => vm.type === VerificationMethodType.JsonWebKey,\n \"Midnight DID only supports JsonWebKey verification method type\",\n ),\n z.refine((vm) => {\n const kty = vm.publicKeyJwk.kty;\n return kty === KeyType.OKP || kty === KeyType.EC;\n }, \"Midnight DID only supports OKP (Ed25519/X25519/BLS12381G1/BLS12381G2) or EC (Jubjub/P-256/secp256k1) key types\"),\n z.refine((vm) => {\n const { kty, crv } = vm.publicKeyJwk;\n if (kty === KeyType.OKP) {\n return (\n crv === CurveType.Ed25519 ||\n crv === CurveType.X25519 ||\n crv === CurveType.BLS12381G1 ||\n crv === CurveType.BLS12381G2\n );\n }\n if (kty === KeyType.EC) {\n return (\n crv === CurveType.Jubjub ||\n crv === CurveType.P256 ||\n crv === CurveType.Secp256k1\n );\n }\n return false;\n }, \"OKP keys must use Ed25519, X25519, BLS12381G1, or BLS12381G2 curve; EC keys must use Jubjub, P-256, or secp256k1 curve\"),\n z.refine((vm) => {\n // Verification methods must be referenced (contain # or be relative)\n const id = vm.id;\n return id.includes(\"#\") || id.startsWith(\"/\") || id.startsWith(\".\");\n }, \"Midnight DID does not support embedded verification methods - use referenced methods with fragments\"),\n );\n\n/** Midnight DID Document Schema with method-specific constraints */\nexport const MidnightDIDDocumentSchema = DIDDocumentSchema.check(\n z.refine(\n (doc) => Array.isArray(doc[\"@context\"]),\n \"@context must be an array for Midnight DID Documents\",\n ),\n z.refine(\n (doc) => Array.isArray(doc[\"@context\"]) && doc[\"@context\"].length >= 2,\n \"@context must contain at least 2 entries for Midnight DID Documents\",\n ),\n z.refine(\n (doc) =>\n Array.isArray(doc[\"@context\"]) &&\n doc[\"@context\"][0] === REQUIRED_CONTEXTS[0],\n `First @context entry must be '${REQUIRED_CONTEXTS[0]}'`,\n ),\n z.refine(\n (doc) =>\n Array.isArray(doc[\"@context\"]) &&\n doc[\"@context\"][1] === REQUIRED_CONTEXTS[1],\n `Second @context entry must be '${REQUIRED_CONTEXTS[1]}'`,\n ),\n z.refine(\n (doc) => MidnightDIDSchema.safeParse(doc.id).success,\n \"id must be a valid Midnight DID (did:midnight:<network>:<identifier>)\",\n ),\n z.refine((doc) => {\n // Controller must equal subject (single-controller model)\n if (!doc.controller) return true; // Optional, but if present must match\n if (typeof doc.controller === \"string\") {\n return doc.controller === doc.id;\n }\n // If array, must have exactly one entry equal to id\n return (\n Array.isArray(doc.controller) &&\n doc.controller.length === 1 &&\n doc.controller[0] === doc.id\n );\n }, \"controller must equal DID subject for Midnight DID (single-controller model)\"),\n z.refine((doc) => {\n // All verification methods must be JsonWebKey and use supported key types\n if (!doc.verificationMethod) return true;\n return doc.verificationMethod.every(\n (vm) => MidnightVerificationMethodSchema.safeParse(vm).success,\n );\n }, \"All verification methods must meet Midnight DID requirements (JsonWebKey type, OKP/EC keys, referenced only)\"),\n);\n\n/**\n * Midnight DID Document type\n *\n * Extends the generic DIDDocument with Midnight-specific constraints\n */\nexport type MidnightDIDDocument = {\n \"@context\": [string, string, ...string[]]; // At least 2 entries required\n id: MidnightDIDString;\n alsoKnownAs?: URIString[] | null;\n controller?: MidnightDIDString | MidnightDIDString[] | null; // Must equal id if present\n verificationMethod?: VerificationMethod[] | null;\n authentication?: DIDKeyID[];\n assertionMethod?: DIDKeyID[];\n keyAgreement?: DIDKeyID[];\n capabilityInvocation?: DIDKeyID[];\n capabilityDelegation?: DIDKeyID[];\n service?: Service[] | null;\n};\n\n/**\n * Create a Midnight DID Document\n *\n * This function creates a DID Document that conforms to the\n * Midnight DID Method Specification.\n *\n * @param params - Document parameters\n * @returns A validated Midnight DID Document\n * @throws {Error} If the document doesn't meet Midnight DID requirements\n *\n * @example\n * ```typescript\n * const doc = createMidnightDIDDocument({\n * id: \"did:midnight:testnet:c569622e7f33d2d020ba1cae242e6077268941327846d62d8cbf0cc923ae41f6\",\n * verificationMethod: [{\n * id: \"#key-1\",\n * type: \"JsonWebKey\",\n * controller: \"did:midnight:testnet:c569622e7f33d2d020ba1cae242e6077268941327846d62d8cbf0cc923ae41f6\",\n * publicKeyJwk: {\n * kty: \"OKP\",\n * crv: \"Ed25519\",\n * x: \"VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ\"\n * }\n * }],\n * authentication: [\"#key-1\"]\n * });\n * ```\n */\nexport function createMidnightDIDDocument(params: {\n id: MidnightDIDString;\n additionalContexts?: string[];\n alsoKnownAs?: URIString[];\n verificationMethod?: VerificationMethod[];\n authentication?: string[];\n assertionMethod?: string[];\n keyAgreement?: string[];\n capabilityInvocation?: string[];\n capabilityDelegation?: string[];\n service?: Service[];\n}): MidnightDIDDocument {\n const doc = {\n \"@context\": [\n REQUIRED_CONTEXTS[0],\n REQUIRED_CONTEXTS[1],\n ...(params.additionalContexts ?? []),\n ],\n id: params.id,\n alsoKnownAs: params.alsoKnownAs ?? null,\n controller: params.id, // Always equals subject for Midnight DID\n verificationMethod: params.verificationMethod ?? null,\n ...(params.authentication === undefined\n ? {}\n : { authentication: params.authentication }),\n ...(params.assertionMethod === undefined\n ? {}\n : { assertionMethod: params.assertionMethod }),\n ...(params.keyAgreement === undefined\n ? {}\n : { keyAgreement: params.keyAgreement }),\n ...(params.capabilityInvocation === undefined\n ? {}\n : { capabilityInvocation: params.capabilityInvocation }),\n ...(params.capabilityDelegation === undefined\n ? {}\n : { capabilityDelegation: params.capabilityDelegation }),\n service: params.service ?? null,\n };\n\n const parsed = MidnightDIDDocumentSchema.parse(doc) as DIDDocument;\n return {\n \"@context\": parsed[\"@context\"] as [string, string, ...string[]],\n id: params.id,\n alsoKnownAs: parsed.alsoKnownAs ?? null,\n controller: params.id,\n verificationMethod: parsed.verificationMethod ?? null,\n ...(parsed.authentication === undefined\n ? {}\n : { authentication: parsed.authentication }),\n ...(parsed.assertionMethod === undefined\n ? {}\n : { assertionMethod: parsed.assertionMethod }),\n ...(parsed.keyAgreement === undefined\n ? {}\n : { keyAgreement: parsed.keyAgreement }),\n ...(parsed.capabilityInvocation === undefined\n ? {}\n : { capabilityInvocation: parsed.capabilityInvocation }),\n ...(parsed.capabilityDelegation === undefined\n ? {}\n : { capabilityDelegation: parsed.capabilityDelegation }),\n service: parsed.service ?? null,\n } as MidnightDIDDocument;\n}\n\n/**\n * Parse and validate a Midnight DID Document\n *\n * @param input - The input to parse\n * @returns A validated Midnight DID Document\n * @throws {Error} If the input doesn't meet Midnight DID requirements\n */\nexport const parseMidnightDIDDocument = (\n input: unknown,\n): MidnightDIDDocument => {\n const parsed = MidnightDIDDocumentSchema.parse(input) as DIDDocument;\n const id = MidnightDIDSchema.parse(parsed.id) as MidnightDIDString;\n const controller =\n parsed.controller == null\n ? parsed.controller\n : Array.isArray(parsed.controller)\n ? parsed.controller.map(\n (value) => MidnightDIDSchema.parse(value) as MidnightDIDString,\n )\n : (MidnightDIDSchema.parse(parsed.controller) as MidnightDIDString);\n return {\n \"@context\": parsed[\"@context\"] as [string, string, ...string[]],\n id,\n alsoKnownAs: parsed.alsoKnownAs ?? null,\n controller,\n verificationMethod: parsed.verificationMethod ?? null,\n ...(parsed.authentication === undefined\n ? {}\n : { authentication: parsed.authentication }),\n ...(parsed.assertionMethod === undefined\n ? {}\n : { assertionMethod: parsed.assertionMethod }),\n ...(parsed.keyAgreement === undefined\n ? {}\n : { keyAgreement: parsed.keyAgreement }),\n ...(parsed.capabilityInvocation === undefined\n ? {}\n : { capabilityInvocation: parsed.capabilityInvocation }),\n ...(parsed.capabilityDelegation === undefined\n ? {}\n : { capabilityDelegation: parsed.capabilityDelegation }),\n service: parsed.service ?? null,\n } as MidnightDIDDocument;\n};\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DIDContract } from "@midnight-ntwrk/midnight-did-contract";
|
|
2
|
+
import { type DIDDocumentMetadata, type DIDResolutionErrorCode } from "@midnight-ntwrk/midnight-did-domain";
|
|
3
|
+
import { MidnightNetwork } from "./midnight.js";
|
|
4
|
+
import { type MidnightDIDDocument } from "./midnight-did-document.js";
|
|
5
|
+
export type MidnightLedgerState = DIDContract.Ledger;
|
|
6
|
+
export type MidnightLedgerReader = (contractAddress: string) => Promise<MidnightLedgerState | null>;
|
|
7
|
+
export type MidnightDIDResolverOptions = {
|
|
8
|
+
ledgerReader: MidnightLedgerReader;
|
|
9
|
+
expectedNetwork?: MidnightNetwork;
|
|
10
|
+
};
|
|
11
|
+
export type MidnightResolutionResult = {
|
|
12
|
+
didDocument: MidnightDIDDocument;
|
|
13
|
+
didDocumentMetadata: DIDDocumentMetadata;
|
|
14
|
+
};
|
|
15
|
+
export type MidnightDIDResolutionResult = {
|
|
16
|
+
didDocument: MidnightDIDDocument | null;
|
|
17
|
+
didDocumentMetadata: DIDDocumentMetadata;
|
|
18
|
+
didResolutionMetadata: {
|
|
19
|
+
error?: DIDResolutionErrorCode;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare class MidnightDIDResolver {
|
|
23
|
+
private readonly ledgerReader;
|
|
24
|
+
private readonly expectedNetwork;
|
|
25
|
+
constructor(options: MidnightDIDResolverOptions);
|
|
26
|
+
resolve(did: string): Promise<MidnightDIDDocument>;
|
|
27
|
+
resolveResult(did: string): Promise<MidnightResolutionResult | null>;
|
|
28
|
+
resolveDIDResolutionResult(did: string): Promise<MidnightDIDResolutionResult>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=midnight-did-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midnight-did-resolver.d.ts","sourceRoot":"","sources":["../src/midnight-did-resolver.ts"],"names":[],"mappings":"AAA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|
+
import { parseMidnightDID, parseMidnightDIDString, } from "@midnight-ntwrk/midnight-did-domain";
|
|
2
|
+
import { LedgerToDomain } from "./ledger-to-domain.js";
|
|
3
|
+
import { MidnightNetwork } from "./midnight.js";
|
|
4
|
+
const resolutionEnvelope = (result, error) => ({
|
|
5
|
+
didDocument: result?.didDocument ?? null,
|
|
6
|
+
didDocumentMetadata: result?.didDocumentMetadata ?? {},
|
|
7
|
+
didResolutionMetadata: error === undefined ? {} : { error },
|
|
8
|
+
});
|
|
9
|
+
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
10
|
+
const resolutionErrorCode = (error) => {
|
|
11
|
+
const message = errorMessage(error);
|
|
12
|
+
if (message.includes("Invalid DID") ||
|
|
13
|
+
message.includes("Invalid method-specific identifier") ||
|
|
14
|
+
message.includes("id must be a valid Midnight DID")) {
|
|
15
|
+
return "invalidDid";
|
|
16
|
+
}
|
|
17
|
+
if (message.includes("Offchain Midnight DIDs") ||
|
|
18
|
+
message.includes("Network mismatch")) {
|
|
19
|
+
return "methodNotSupported";
|
|
20
|
+
}
|
|
21
|
+
return "internalError";
|
|
22
|
+
};
|
|
23
|
+
export class MidnightDIDResolver {
|
|
24
|
+
ledgerReader;
|
|
25
|
+
expectedNetwork;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.ledgerReader = options.ledgerReader;
|
|
28
|
+
this.expectedNetwork = options.expectedNetwork ?? null;
|
|
29
|
+
}
|
|
30
|
+
async resolve(did) {
|
|
31
|
+
const result = await this.resolveResult(did);
|
|
32
|
+
if (result === null) {
|
|
33
|
+
throw new Error(`DID not found: ${did}`);
|
|
34
|
+
}
|
|
35
|
+
return result.didDocument;
|
|
36
|
+
}
|
|
37
|
+
async resolveResult(did) {
|
|
38
|
+
const parsed = parseMidnightDIDString(did);
|
|
39
|
+
const { network, id } = parseMidnightDID(parsed);
|
|
40
|
+
if (network === MidnightNetwork.Offchain) {
|
|
41
|
+
throw new Error("Offchain Midnight DIDs must be resolved from their long-form encoded state, not through the ledger resolver");
|
|
42
|
+
}
|
|
43
|
+
if (this.expectedNetwork !== null && network !== this.expectedNetwork) {
|
|
44
|
+
throw new Error(`Network mismatch: DID network is ${network}, expected ${this.expectedNetwork}`);
|
|
45
|
+
}
|
|
46
|
+
const contractAddress = id;
|
|
47
|
+
const ledgerState = await this.ledgerReader(contractAddress);
|
|
48
|
+
if (ledgerState === null)
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
didDocument: LedgerToDomain.ledgerStateToDIDDocument(ledgerState, network, contractAddress),
|
|
52
|
+
didDocumentMetadata: LedgerToDomain.ledgerStateToMetadata(ledgerState),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async resolveDIDResolutionResult(did) {
|
|
56
|
+
try {
|
|
57
|
+
const result = await this.resolveResult(did);
|
|
58
|
+
return resolutionEnvelope(result, result === null ? "notFound" : undefined);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return resolutionEnvelope(null, resolutionErrorCode(error));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=midnight-did-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midnight-did-resolver.js","sourceRoot":"","sources":["../src/midnight-did-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA2BhD,MAAM,kBAAkB,GAAG,CACzB,MAAuC,EACvC,KAA8B,EACD,EAAE,CAAC,CAAC;IACjC,WAAW,EAAE,MAAM,EAAE,WAAW,IAAI,IAAI;IACxC,mBAAmB,EAAE,MAAM,EAAE,mBAAmB,IAAI,EAAE;IACtD,qBAAqB,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC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ddress,\n type DIDDocumentMetadata,\n type DIDResolutionErrorCode,\n parseMidnightDID,\n parseMidnightDIDString,\n} from \"@midnight-ntwrk/midnight-did-domain\";\n\nimport { LedgerToDomain } from \"./ledger-to-domain.js\";\nimport { MidnightNetwork } from \"./midnight.js\";\nimport { type MidnightDIDDocument } from \"./midnight-did-document.js\";\n\nexport type MidnightLedgerState = DIDContract.Ledger;\n\nexport type MidnightLedgerReader = (\n contractAddress: string,\n) => Promise<MidnightLedgerState | null>;\n\nexport type MidnightDIDResolverOptions = {\n ledgerReader: MidnightLedgerReader;\n expectedNetwork?: MidnightNetwork;\n};\n\nexport type MidnightResolutionResult = {\n didDocument: MidnightDIDDocument;\n didDocumentMetadata: DIDDocumentMetadata;\n};\n\nexport type MidnightDIDResolutionResult = {\n didDocument: MidnightDIDDocument | null;\n didDocumentMetadata: DIDDocumentMetadata;\n didResolutionMetadata: {\n error?: DIDResolutionErrorCode;\n };\n};\n\nconst resolutionEnvelope = (\n result: MidnightResolutionResult | null,\n error?: DIDResolutionErrorCode,\n): MidnightDIDResolutionResult => ({\n didDocument: result?.didDocument ?? null,\n didDocumentMetadata: result?.didDocumentMetadata ?? {},\n didResolutionMetadata: error === undefined ? {} : { error },\n});\n\nconst errorMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error);\n\nconst resolutionErrorCode = (error: unknown): DIDResolutionErrorCode => {\n const message = errorMessage(error);\n if (\n message.includes(\"Invalid DID\") ||\n message.includes(\"Invalid method-specific identifier\") ||\n message.includes(\"id must be a valid Midnight DID\")\n ) {\n return \"invalidDid\";\n }\n if (\n message.includes(\"Offchain Midnight DIDs\") ||\n message.includes(\"Network mismatch\")\n ) {\n return \"methodNotSupported\";\n }\n return \"internalError\";\n};\n\nexport class MidnightDIDResolver {\n private readonly ledgerReader: MidnightLedgerReader;\n private readonly expectedNetwork: MidnightNetwork | null;\n\n constructor(options: MidnightDIDResolverOptions) {\n this.ledgerReader = options.ledgerReader;\n this.expectedNetwork = options.expectedNetwork ?? null;\n }\n\n async resolve(did: string): Promise<MidnightDIDDocument> {\n const result = await this.resolveResult(did);\n if (result === null) {\n throw new Error(`DID not found: ${did}`);\n }\n return result.didDocument;\n }\n\n async resolveResult(did: string): Promise<MidnightResolutionResult | null> {\n const parsed = parseMidnightDIDString(did);\n const { network, id } = parseMidnightDID(parsed);\n\n if (network === MidnightNetwork.Offchain) {\n throw new Error(\n \"Offchain Midnight DIDs must be resolved from their long-form encoded state, not through the ledger resolver\",\n );\n }\n\n if (this.expectedNetwork !== null && network !== this.expectedNetwork) {\n throw new Error(\n `Network mismatch: DID network is ${network}, expected ${this.expectedNetwork}`,\n );\n }\n\n const contractAddress = id as ContractAddress;\n const ledgerState = await this.ledgerReader(contractAddress);\n if (ledgerState === null) return null;\n\n return {\n didDocument: LedgerToDomain.ledgerStateToDIDDocument(\n ledgerState,\n network,\n contractAddress,\n ),\n didDocumentMetadata: LedgerToDomain.ledgerStateToMetadata(ledgerState),\n };\n }\n\n async resolveDIDResolutionResult(\n did: string,\n ): Promise<MidnightDIDResolutionResult> {\n try {\n const result = await this.resolveResult(did);\n return resolutionEnvelope(\n result,\n result === null ? \"notFound\" : undefined,\n );\n } catch (error) {\n return resolutionEnvelope(null, resolutionErrorCode(error));\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midnight.d.ts","sourceRoot":"","sources":["../src/midnight.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,8CAA8C,CAAC"}
|
package/dist/midnight.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midnight.js","sourceRoot":"","sources":["../src/midnight.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACvB,iBAAiB,EAEjB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,8CAA8C,CAAC","sourcesContent":["export {\n ContractAddress,\n createMidnightDIDString,\n MidnightDIDSchema,\n MidnightDIDString,\n MidnightNetwork,\n parseContractAddress,\n parseMidnightDID,\n parseMidnightDIDString,\n} from \"@midnight-ntwrk/midnight-did-domain/midnight\";\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createOffchainMidnightDidDocumentMetadata, type OffchainMidnightDIDState, type ParsedLongFormOffchainMidnightDID } from "@midnight-ntwrk/midnight-did-domain";
|
|
2
|
+
import { type MidnightDIDDocument } from "./midnight-did-document.js";
|
|
3
|
+
export type ResolvedLongFormOffchainMidnightDID = {
|
|
4
|
+
readonly did: string;
|
|
5
|
+
readonly parsed: ParsedLongFormOffchainMidnightDID;
|
|
6
|
+
readonly state: OffchainMidnightDIDState;
|
|
7
|
+
readonly didDocument: MidnightDIDDocument;
|
|
8
|
+
readonly didDocumentMetadata: ReturnType<typeof createOffchainMidnightDidDocumentMetadata>;
|
|
9
|
+
};
|
|
10
|
+
export declare const resolveLongFormOffchainMidnightDID: (input: string) => ResolvedLongFormOffchainMidnightDID;
|
|
11
|
+
export declare const assertOffchainMidnightDID: (did: string) => string;
|
|
12
|
+
//# sourceMappingURL=offchain-midnight-did.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offchain-midnight-did.d.ts","sourceRoot":"","sources":["../src/offchain-midnight-did.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EAGzC,KAAK,wBAAwB,EAE7B,KAAK,iCAAiC,EAIvC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,iCAAiC,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,wBAAwB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,mBAAmB,EAAE,UAAU,CACtC,OAAO,yCAAyC,CACjD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAC7C,OAAO,MAAM,KACZ,mCAaF,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,MAMvD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createOffchainMidnightDidDocumentMetadata, decodeOffchainMidnightDIDState, MidnightNetwork, offchainStateToDidDocument, parseLongFormOffchainMidnightDIDString, parseMidnightDID, parseMidnightDIDString, } from "@midnight-ntwrk/midnight-did-domain";
|
|
2
|
+
import { parseMidnightDIDDocument, } from "./midnight-did-document.js";
|
|
3
|
+
export const resolveLongFormOffchainMidnightDID = (input) => {
|
|
4
|
+
const parsed = parseLongFormOffchainMidnightDIDString(input);
|
|
5
|
+
const state = decodeOffchainMidnightDIDState(parsed.encodedState);
|
|
6
|
+
const didDocument = parseMidnightDIDDocument(offchainStateToDidDocument(parsed.did, state));
|
|
7
|
+
return {
|
|
8
|
+
did: parsed.did,
|
|
9
|
+
parsed,
|
|
10
|
+
state,
|
|
11
|
+
didDocument,
|
|
12
|
+
didDocumentMetadata: createOffchainMidnightDidDocumentMetadata(state),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export const assertOffchainMidnightDID = (did) => {
|
|
16
|
+
const parsed = parseMidnightDID(parseMidnightDIDString(did));
|
|
17
|
+
if (parsed.network !== MidnightNetwork.Offchain) {
|
|
18
|
+
throw new Error("Expected an offchain Midnight DID");
|
|
19
|
+
}
|
|
20
|
+
return did;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=offchain-midnight-did.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offchain-midnight-did.js","sourceRoot":"","sources":["../src/offchain-midnight-did.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,8BAA8B,EAC9B,eAAe,EAEf,0BAA0B,EAE1B,sCAAsC,EACtC,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAEL,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAYpC,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,KAAa,EACwB,EAAE;IACvC,MAAM,MAAM,GAAG,sCAAsC,CAAC,KAAK,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,8BAA8B,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAClE,MAAM,WAAW,GAAG,wBAAwB,CAC1C,0BAA0B,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAC9C,CAAC;IACF,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,MAAM;QACN,KAAK;QACL,WAAW;QACX,mBAAmB,EAAE,yCAAyC,CAAC,KAAK,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAU,EAAE;IAC/D,MAAM,MAAM,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,IAAI,MAAM,CAAC,OAAO,KAAK,eAAe,CAAC,QAAQ,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","sourcesContent":["import {\n createOffchainMidnightDidDocumentMetadata,\n decodeOffchainMidnightDIDState,\n MidnightNetwork,\n type OffchainMidnightDIDState,\n offchainStateToDidDocument,\n type ParsedLongFormOffchainMidnightDID,\n parseLongFormOffchainMidnightDIDString,\n parseMidnightDID,\n parseMidnightDIDString,\n} from \"@midnight-ntwrk/midnight-did-domain\";\n\nimport {\n type MidnightDIDDocument,\n parseMidnightDIDDocument,\n} from \"./midnight-did-document.js\";\n\nexport type ResolvedLongFormOffchainMidnightDID = {\n readonly did: string;\n readonly parsed: ParsedLongFormOffchainMidnightDID;\n readonly state: OffchainMidnightDIDState;\n readonly didDocument: MidnightDIDDocument;\n readonly didDocumentMetadata: ReturnType<\n typeof createOffchainMidnightDidDocumentMetadata\n >;\n};\n\nexport const resolveLongFormOffchainMidnightDID = (\n input: string,\n): ResolvedLongFormOffchainMidnightDID => {\n const parsed = parseLongFormOffchainMidnightDIDString(input);\n const state = decodeOffchainMidnightDIDState(parsed.encodedState);\n const didDocument = parseMidnightDIDDocument(\n offchainStateToDidDocument(parsed.did, state),\n );\n return {\n did: parsed.did,\n parsed,\n state,\n didDocument,\n didDocumentMetadata: createOffchainMidnightDidDocumentMetadata(state),\n };\n};\n\nexport const assertOffchainMidnightDID = (did: string): string => {\n const parsed = parseMidnightDID(parseMidnightDIDString(did));\n if (parsed.network !== MidnightNetwork.Offchain) {\n throw new Error(\"Expected an offchain Midnight DID\");\n }\n return did;\n};\n"]}
|