@arcblock/did 1.32.2 → 1.32.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/esm/did-domain-resolver.d.mts +47 -2
- package/esm/did-domain-resolver.mjs +382 -34
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/lib/did-domain-resolver.cjs +384 -33
- package/lib/did-domain-resolver.d.cts +47 -2
- package/lib/index.cjs +3 -0
- package/lib/index.d.cts +2 -2
- package/package.json +3 -3
package/esm/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ALIAS_METHODS, ALL_METHODS, AliasMethod, CRYPTO_METHODS, CryptoMethod, DEFAULT_METHOD, DIDMethod, isAliasMethod, isCryptoMethod, isKnownMethod } from "./method.mjs";
|
|
2
2
|
import { InMemoryNameRegistry, NameRegistry } from "./name-registry.mjs";
|
|
3
|
-
import { AccountPreRotationStateData, DEFAULT_DID_DOMAIN_GATEWAY, DIDDomainEdgeRouter, DIDServiceEndpoint, DID_ENDPOINT_DOMAIN_TAG, DNS_NFT_BINDING_DOMAIN_TAG, DidEndpointRecord, DnsDidLabelEncoding, DomainNftAssetSnapshot, DomainNftBindingProof, KEY_ROTATION_DOMAIN_TAG, KeyRotationEvent, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, PRE_ROTATION_DOMAIN_TAG, SynthesizeDidDocumentOptions, ThreeTierResolutionResult, W3CDIDDocument, W3CDIDVerificationMethod, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, encodeDidEndpointDigest, extractAccountPreRotationData, extractDidFromDomainHost, fromDnsDidLabel, isValidPreRotationCommitment, normalizePreRotationCommitment, normalizePublicKeyHex, synthesizeDidDocument, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent } from "./did-domain-resolver.mjs";
|
|
3
|
+
import { AccountPreRotationStateData, DEFAULT_DID_DOMAIN_GATEWAY, DIDDomainEdgeRouter, DIDServiceEndpoint, DID_ENDPOINT_DOMAIN_TAG, DNS_NFT_BINDING_DOMAIN_TAG, DidEndpointRecord, DidTlsResolutionTier, DidTlsTargetResolution, DnsDidLabelEncoding, DomainNftAssetSnapshot, DomainNftBindingProof, KEY_ROTATION_DOMAIN_TAG, KeyRotationEvent, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, PRE_ROTATION_DOMAIN_TAG, ResolveDidTlsTargetOptions, SynthesizeDidDocumentOptions, ThreeTierResolutionResult, W3CDIDDocument, W3CDIDVerificationMethod, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, decodeDidFromDnsLabels, encodeDidEndpointDigest, encodeDidForDnsLabels, extractAccountPreRotationData, extractDidFromDomainHost, fromDnsDidLabel, isValidPreRotationCommitment, isValidStrictDnsHostname, normalizePreRotationCommitment, normalizePublicKeyHex, synthesizeDidDocument, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent } from "./did-domain-resolver.mjs";
|
|
4
4
|
import { getEntityId, isSameEntity } from "./entity.mjs";
|
|
5
5
|
import { DIDType, DIDTypeArg, DIDTypeShortcut, DIDTypeStr, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, DidType, RequiredDIDType, fromTypeInfo, isEthereumDid, isEthereumType, toChecksumAddress, toTypeInfo, toTypeInfoStr } from "./type.mjs";
|
|
6
6
|
import { DID_PREFIX, toStrictHex } from "./util.mjs";
|
|
@@ -68,4 +68,4 @@ declare const isFromPublicKey: (did: string, pk: BytesType) => boolean;
|
|
|
68
68
|
declare const isValid: (did: string) => boolean;
|
|
69
69
|
declare const deriveSubAccountAddress: (parentIdentity: BytesType, scope: string, index?: number, type?: DIDTypeArg) => string, isFromSubAccount: (subAccountDid: string, parentIdentity: BytesType, scope: string, index?: number) => boolean;
|
|
70
70
|
//#endregion
|
|
71
|
-
export { ALIAS_METHODS, ALL_METHODS, type AccountPreRotationStateData, type AliasMethod, CRYPTO_METHODS, type CryptoMethod, DEFAULT_DID_DOMAIN_GATEWAY, DEFAULT_METHOD, DIDDomainEdgeRouter, type DIDMethod, DIDNameResolver, type DIDNameResolverOptions, type DIDServiceEndpoint, type DIDType, type DIDTypeArg, type DIDTypeShortcut, type DIDTypeStr, DID_ENDPOINT_DOMAIN_TAG, DID_PREFIX, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, DNS_NFT_BINDING_DOMAIN_TAG, type DidEndpointRecord, DidType, type DnsDidLabelEncoding, type DomainNftAssetSnapshot, type DomainNftBindingProof, InMemoryNameRegistry, KEY_ROTATION_DOMAIN_TAG, type KeyRotationEvent, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, type NameHierarchy, type NameRegistry, PRE_ROTATION_DOMAIN_TAG, type ParsedDID, type RequiredDIDType, type ResolveRoute, type ResolveTraceResult, SUBACCOUNT_DOMAIN_TAG, type SynthesizeDidDocumentOptions, type ThreeTierResolutionResult, type W3CDIDDocument, type W3CDIDVerificationMethod, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, deriveSubAccountAddress, deriveSubAccountSeed, encodeDidEndpointDigest, encodeLengthPrefixedTuple, expandShortForm, extractAccountPreRotationData, extractDidFromDomainHost, extractIdentifier, extractMethod, formatDid, fromDnsDidLabel, fromHash, fromPublicKey, fromPublicKeyHash, fromSecretKey, fromTypeInfo, getEntityId, getResolveRoute, isAliasMethod, isCryptoMethod, isEthereumDid, isEthereumType, isFromPublicKey, isFromSubAccount, isGlobalName, isKnownDid, isKnownMethod, isLocalName, isSameEntity, isValid, isValidPreRotationCommitment, normalizeName, normalizePreRotationCommitment, normalizePublicKeyHex, parse, parseNameHierarchy, synthesizeDidDocument, toAddress, toChecksumAddress, toDid, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, toShortForm, toStrictHex, toTypeInfo, toTypeInfoStr, types, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent };
|
|
71
|
+
export { ALIAS_METHODS, ALL_METHODS, type AccountPreRotationStateData, type AliasMethod, CRYPTO_METHODS, type CryptoMethod, DEFAULT_DID_DOMAIN_GATEWAY, DEFAULT_METHOD, DIDDomainEdgeRouter, type DIDMethod, DIDNameResolver, type DIDNameResolverOptions, type DIDServiceEndpoint, type DIDType, type DIDTypeArg, type DIDTypeShortcut, type DIDTypeStr, DID_ENDPOINT_DOMAIN_TAG, DID_PREFIX, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, DNS_NFT_BINDING_DOMAIN_TAG, type DidEndpointRecord, type DidTlsResolutionTier, type DidTlsTargetResolution, DidType, type DnsDidLabelEncoding, type DomainNftAssetSnapshot, type DomainNftBindingProof, InMemoryNameRegistry, KEY_ROTATION_DOMAIN_TAG, type KeyRotationEvent, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, type NameHierarchy, type NameRegistry, PRE_ROTATION_DOMAIN_TAG, type ParsedDID, type RequiredDIDType, type ResolveDidTlsTargetOptions, type ResolveRoute, type ResolveTraceResult, SUBACCOUNT_DOMAIN_TAG, type SynthesizeDidDocumentOptions, type ThreeTierResolutionResult, type W3CDIDDocument, type W3CDIDVerificationMethod, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, decodeDidFromDnsLabels, deriveSubAccountAddress, deriveSubAccountSeed, encodeDidEndpointDigest, encodeDidForDnsLabels, encodeLengthPrefixedTuple, expandShortForm, extractAccountPreRotationData, extractDidFromDomainHost, extractIdentifier, extractMethod, formatDid, fromDnsDidLabel, fromHash, fromPublicKey, fromPublicKeyHash, fromSecretKey, fromTypeInfo, getEntityId, getResolveRoute, isAliasMethod, isCryptoMethod, isEthereumDid, isEthereumType, isFromPublicKey, isFromSubAccount, isGlobalName, isKnownDid, isKnownMethod, isLocalName, isSameEntity, isValid, isValidPreRotationCommitment, isValidStrictDnsHostname, normalizeName, normalizePreRotationCommitment, normalizePublicKeyHex, parse, parseNameHierarchy, synthesizeDidDocument, toAddress, toChecksumAddress, toDid, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, toShortForm, toStrictHex, toTypeInfo, toTypeInfoStr, types, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent };
|
package/esm/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { expandShortForm, toShortForm } from "./short-form.mjs";
|
|
|
9
9
|
import { InMemoryNameRegistry } from "./name-registry.mjs";
|
|
10
10
|
import { DIDNameResolver } from "./name-resolver.mjs";
|
|
11
11
|
import { SUBACCOUNT_DOMAIN_TAG, createSubAccountHelpers, deriveSubAccountSeed, encodeLengthPrefixedTuple } from "./subaccount.mjs";
|
|
12
|
-
import { DEFAULT_DID_DOMAIN_GATEWAY, DIDDomainEdgeRouter, DID_ENDPOINT_DOMAIN_TAG, DNS_NFT_BINDING_DOMAIN_TAG, KEY_ROTATION_DOMAIN_TAG, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, PRE_ROTATION_DOMAIN_TAG, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, encodeDidEndpointDigest, extractAccountPreRotationData, extractDidFromDomainHost, fromDnsDidLabel, isValidPreRotationCommitment, normalizePreRotationCommitment, normalizePublicKeyHex, synthesizeDidDocument, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent } from "./did-domain-resolver.mjs";
|
|
12
|
+
import { DEFAULT_DID_DOMAIN_GATEWAY, DIDDomainEdgeRouter, DID_ENDPOINT_DOMAIN_TAG, DNS_NFT_BINDING_DOMAIN_TAG, KEY_ROTATION_DOMAIN_TAG, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, PRE_ROTATION_DOMAIN_TAG, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, decodeDidFromDnsLabels, encodeDidEndpointDigest, encodeDidForDnsLabels, extractAccountPreRotationData, extractDidFromDomainHost, fromDnsDidLabel, isValidPreRotationCommitment, isValidStrictDnsHostname, normalizePreRotationCommitment, normalizePublicKeyHex, synthesizeDidDocument, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent } from "./did-domain-resolver.mjs";
|
|
13
13
|
import { getHasher, getSigner, types } from "@ocap/mcrypto";
|
|
14
14
|
import { stripHexPrefix, toAddress, toBase58, toDid } from "@ocap/util";
|
|
15
15
|
|
|
@@ -107,4 +107,4 @@ const { deriveSubAccountAddress, isFromSubAccount } = createSubAccountHelpers({
|
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
//#endregion
|
|
110
|
-
export { ALIAS_METHODS, ALL_METHODS, CRYPTO_METHODS, DEFAULT_DID_DOMAIN_GATEWAY, DEFAULT_METHOD, DIDDomainEdgeRouter, DIDNameResolver, DID_ENDPOINT_DOMAIN_TAG, DID_PREFIX, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, DNS_NFT_BINDING_DOMAIN_TAG, DidType, InMemoryNameRegistry, KEY_ROTATION_DOMAIN_TAG, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, PRE_ROTATION_DOMAIN_TAG, SUBACCOUNT_DOMAIN_TAG, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, deriveSubAccountAddress, deriveSubAccountSeed, encodeDidEndpointDigest, encodeLengthPrefixedTuple, expandShortForm, extractAccountPreRotationData, extractDidFromDomainHost, extractIdentifier, extractMethod, formatDid, fromDnsDidLabel, fromHash, fromPublicKey, fromPublicKeyHash, fromSecretKey, fromTypeInfo, getEntityId, getResolveRoute, isAliasMethod, isCryptoMethod, isEthereumDid, isEthereumType, isFromPublicKey, isFromSubAccount, isGlobalName, isKnownDid, isKnownMethod, isLocalName, isSameEntity, isValid, isValidPreRotationCommitment, normalizeName, normalizePreRotationCommitment, normalizePublicKeyHex, parse, parseNameHierarchy, synthesizeDidDocument, toAddress, toChecksumAddress, toDid, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, toShortForm, toStrictHex, toTypeInfo, toTypeInfoStr, types, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent };
|
|
110
|
+
export { ALIAS_METHODS, ALL_METHODS, CRYPTO_METHODS, DEFAULT_DID_DOMAIN_GATEWAY, DEFAULT_METHOD, DIDDomainEdgeRouter, DIDNameResolver, DID_ENDPOINT_DOMAIN_TAG, DID_PREFIX, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, DNS_NFT_BINDING_DOMAIN_TAG, DidType, InMemoryNameRegistry, KEY_ROTATION_DOMAIN_TAG, MAX_CUSTOM_DOMAINS_PER_DID, MAX_ROTATION_CHAIN_LENGTH, PRE_ROTATION_DOMAIN_TAG, SUBACCOUNT_DOMAIN_TAG, createAccountMigratePreRotationData, createDomainNftBindingProof, createKeyRotationEvent, createPreRotationCommitment, decodeDidFromDnsLabels, deriveSubAccountAddress, deriveSubAccountSeed, encodeDidEndpointDigest, encodeDidForDnsLabels, encodeLengthPrefixedTuple, expandShortForm, extractAccountPreRotationData, extractDidFromDomainHost, extractIdentifier, extractMethod, formatDid, fromDnsDidLabel, fromHash, fromPublicKey, fromPublicKeyHash, fromSecretKey, fromTypeInfo, getEntityId, getResolveRoute, isAliasMethod, isCryptoMethod, isEthereumDid, isEthereumType, isFromPublicKey, isFromSubAccount, isGlobalName, isKnownDid, isKnownMethod, isLocalName, isSameEntity, isValid, isValidPreRotationCommitment, isValidStrictDnsHostname, normalizeName, normalizePreRotationCommitment, normalizePublicKeyHex, parse, parseNameHierarchy, synthesizeDidDocument, toAddress, toChecksumAddress, toDid, toDidDomainHost, toDidWellKnownUrl, toDnsDidLabel, toShortForm, toStrictHex, toTypeInfo, toTypeInfoStr, types, verifyAccountMigrationChainWithKel, verifyDomainNftBindingProof, verifyKeyRotationChain, verifyPreRotationCommitment, verifySingleKeyRotationEvent };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_method = require('./method.cjs');
|
|
1
2
|
const require_name = require('./name.cjs');
|
|
2
3
|
const require_parse = require('./parse.cjs');
|
|
3
4
|
const require_entity = require('./entity.cjs');
|
|
@@ -100,9 +101,32 @@ function parseBase36ToBigInt(str) {
|
|
|
100
101
|
* - `'hex'`: `f` + 52 lowercase hex chars (53 chars total, <= 63 DNS limit)
|
|
101
102
|
* - For 20-byte Ethereum DIDs (`0x...`): `e` + 31 base36 chars (or `0x` + 40 hex chars).
|
|
102
103
|
*/
|
|
104
|
+
/**
|
|
105
|
+
* Strict RFC 1035 / RFC 1123 DNS hostname validator (`1..253` chars, labels `1..63` matching
|
|
106
|
+
* `/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i`, zero wildcards `*`, ports `:`, slashes `/`,
|
|
107
|
+
* underscores `_`, percent-escapes `%`, IPv4 literals, or numeric-only TLDs).
|
|
108
|
+
*/
|
|
109
|
+
function isValidStrictDnsHostname(host) {
|
|
110
|
+
if (!host || typeof host !== "string" || host.length < 1 || host.length > 253) return false;
|
|
111
|
+
if (host !== host.trim() || host.startsWith(".") || host.endsWith(".") || host.includes("..")) return false;
|
|
112
|
+
const labels = host.toLowerCase().split(".");
|
|
113
|
+
for (const lbl of labels) if (lbl.length < 1 || lbl.length > 63 || !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(lbl)) return false;
|
|
114
|
+
if (/^\d+$/.test(labels[labels.length - 1])) return false;
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
function normalizeStrictGatewayDomain(gatewayDomain) {
|
|
118
|
+
const trimmed = typeof gatewayDomain === "string" ? gatewayDomain.trim().replace(/\.$/, "") : "";
|
|
119
|
+
if (!isValidStrictDnsHostname(trimmed) || !trimmed.includes(".")) throw new Error(`Invalid gatewayDomain "${String(gatewayDomain)}": must be a strict multi-label RFC 1035 hostname`);
|
|
120
|
+
return trimmed.toLowerCase();
|
|
121
|
+
}
|
|
103
122
|
function toDnsDidLabel(did, encoding = "base36") {
|
|
104
123
|
if (!did || typeof did !== "string") throw new Error("DID must be a non-empty string");
|
|
105
|
-
const
|
|
124
|
+
const trimmed = did.trim();
|
|
125
|
+
if (/^did:/i.test(trimmed)) {
|
|
126
|
+
const m = /^did:([a-z0-9]+):([^:]+)$/i.exec(trimmed);
|
|
127
|
+
if (!m || !require_method.isCryptoMethod(m[1].toLowerCase())) throw new Error(`Unsupported or foreign DID method for DNS label: ${did}`);
|
|
128
|
+
} else if (trimmed.includes(":")) throw new Error(`Cannot encode invalid DID to DNS label: ${did}`);
|
|
129
|
+
const address = (0, _ocap_util.toAddress)(trimmed);
|
|
106
130
|
if (!require_index.isValid(address)) throw new Error(`Cannot encode invalid DID to DNS label: ${did}`);
|
|
107
131
|
if (require_type.isEthereumDid(address)) {
|
|
108
132
|
const cleanHex = (0, _ocap_util.stripHexPrefix)(address).toLowerCase();
|
|
@@ -126,9 +150,17 @@ function toDnsDidLabel(did, encoding = "base36") {
|
|
|
126
150
|
*/
|
|
127
151
|
function fromDnsDidLabel(label, method = "abt") {
|
|
128
152
|
if (!label || typeof label !== "string") throw new Error("DNS DID label must be a non-empty string");
|
|
153
|
+
if (!require_method.isCryptoMethod(method)) throw new Error(`Unsupported non-crypto DID method: ${String(method)}`);
|
|
129
154
|
const trimmed = label.trim();
|
|
130
155
|
if (!trimmed) throw new Error("DNS DID label cannot be empty");
|
|
131
|
-
if (
|
|
156
|
+
if (/^did:/i.test(trimmed)) {
|
|
157
|
+
const m = /^did:([a-z0-9]+):([^:]+)$/i.exec(trimmed);
|
|
158
|
+
const explicitMethod = m ? m[1].toLowerCase() : "";
|
|
159
|
+
if (!m || !require_method.isCryptoMethod(explicitMethod) || !require_index.isValid(trimmed)) throw new Error(`Invalid or foreign DID in DNS label: ${label}`);
|
|
160
|
+
const addr = (0, _ocap_util.toAddress)(trimmed);
|
|
161
|
+
return require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, explicitMethod);
|
|
162
|
+
}
|
|
163
|
+
if (!trimmed.includes(":") && require_index.isValid(trimmed)) {
|
|
132
164
|
const addr = (0, _ocap_util.toAddress)(trimmed);
|
|
133
165
|
return require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, method);
|
|
134
166
|
}
|
|
@@ -150,27 +182,164 @@ function fromDnsDidLabel(label, method = "abt") {
|
|
|
150
182
|
}
|
|
151
183
|
throw new Error(`Invalid or unrecognized DNS DID label: ${label}`);
|
|
152
184
|
}
|
|
185
|
+
const DNS_BASE32_LOWER_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
|
|
186
|
+
function encodeBytesToBase32Lower(bytes) {
|
|
187
|
+
let bits = 0;
|
|
188
|
+
let value = 0;
|
|
189
|
+
let out = "";
|
|
190
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
191
|
+
value = value << 8 | bytes[i];
|
|
192
|
+
bits += 8;
|
|
193
|
+
while (bits >= 5) {
|
|
194
|
+
out += DNS_BASE32_LOWER_ALPHABET[value >>> bits - 5 & 31];
|
|
195
|
+
bits -= 5;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (bits > 0) out += DNS_BASE32_LOWER_ALPHABET[value << 5 - bits & 31];
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
function decodeBase32LowerToBytes(input) {
|
|
202
|
+
if (!input || !/^[a-z2-7]+$/.test(input)) return null;
|
|
203
|
+
const outLen = Math.floor(input.length * 5 / 8);
|
|
204
|
+
if (outLen === 0) return null;
|
|
205
|
+
const out = new Uint8Array(outLen);
|
|
206
|
+
let bits = 0;
|
|
207
|
+
let value = 0;
|
|
208
|
+
let idx = 0;
|
|
209
|
+
for (let i = 0; i < input.length; i++) {
|
|
210
|
+
const ch = DNS_BASE32_LOWER_ALPHABET.indexOf(input[i]);
|
|
211
|
+
if (ch < 0) return null;
|
|
212
|
+
value = value << 5 | ch;
|
|
213
|
+
bits += 5;
|
|
214
|
+
if (bits >= 8) {
|
|
215
|
+
out[idx++] = value >>> bits - 8 & 255;
|
|
216
|
+
bits -= 8;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (bits >= 5 || bits > 0 && (value & (1 << bits) - 1) !== 0) return null;
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
function canonicalizeDecodedCryptoDid(candidate, fallbackMethod) {
|
|
223
|
+
if (!candidate || !require_method.isCryptoMethod(fallbackMethod) || /[/?#\s]/.test(candidate)) return null;
|
|
224
|
+
for (let i = 0; i < candidate.length; i++) {
|
|
225
|
+
const code = candidate.charCodeAt(i);
|
|
226
|
+
if (code <= 32 || code >= 127) return null;
|
|
227
|
+
}
|
|
228
|
+
if (/^did:/i.test(candidate)) {
|
|
229
|
+
const m = /^did:([a-z0-9]+):([^:]+)$/.exec(candidate);
|
|
230
|
+
if (!m || !require_method.isCryptoMethod(m[1]) || !require_index.isValid(candidate)) return null;
|
|
231
|
+
const addr$1 = (0, _ocap_util.toAddress)(candidate);
|
|
232
|
+
return require_parse.formatDid(require_type.isEthereumDid(addr$1) ? require_type.toChecksumAddress(addr$1) : addr$1, m[1]);
|
|
233
|
+
}
|
|
234
|
+
if (candidate.includes(":") || !require_index.isValid(candidate)) return null;
|
|
235
|
+
const addr = (0, _ocap_util.toAddress)(candidate);
|
|
236
|
+
return require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, fallbackMethod);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Losslessly encode a W3C/OCAP DID into lowercase RFC 1035 DNS labels (`<= 63` chars per label)
|
|
240
|
+
* using unpadded RFC 4648 base32 (`d0-<b32>` single-label or `d0.<chunk1>.<chunk2>...` multi-label),
|
|
241
|
+
* matching `ArcBlock/arc` `encodeDidForDnsLabels` 1:1 (#2025).
|
|
242
|
+
*/
|
|
243
|
+
function encodeDidForDnsLabels(did, defaultMethod = "abt") {
|
|
244
|
+
if (!did || typeof did !== "string") throw new Error("DID must be a non-empty string");
|
|
245
|
+
if (!require_method.isCryptoMethod(defaultMethod)) throw new Error(`Unsupported defaultMethod for encodeDidForDnsLabels: ${String(defaultMethod)}`);
|
|
246
|
+
const trimmed = did.trim();
|
|
247
|
+
if (!trimmed || /[/?#\s]/.test(trimmed)) throw new Error(`Cannot encode invalid DID for DNS labels: ${did}`);
|
|
248
|
+
let canonicalDid;
|
|
249
|
+
if (/^did:/i.test(trimmed)) {
|
|
250
|
+
const m = /^did:([a-z0-9]+):([^:]+)$/i.exec(trimmed);
|
|
251
|
+
const explicitMethod = m ? m[1].toLowerCase() : "";
|
|
252
|
+
if (!m || !require_method.isCryptoMethod(explicitMethod) || !require_index.isValid(trimmed)) throw new Error(`Cannot encode invalid or foreign DID for DNS labels: ${did}`);
|
|
253
|
+
const addr = (0, _ocap_util.toAddress)(trimmed);
|
|
254
|
+
canonicalDid = require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, explicitMethod);
|
|
255
|
+
} else {
|
|
256
|
+
if (trimmed.includes(":") || !require_index.isValid(trimmed)) throw new Error(`Cannot encode invalid DID for DNS labels: ${did}`);
|
|
257
|
+
const addr = (0, _ocap_util.toAddress)(trimmed);
|
|
258
|
+
canonicalDid = require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, defaultMethod);
|
|
259
|
+
}
|
|
260
|
+
const b32 = encodeBytesToBase32Lower(Uint8Array.from(Buffer.from(canonicalDid, "utf8")));
|
|
261
|
+
if (b32.length <= 60) return `d0-${b32}`;
|
|
262
|
+
const chunks = ["d0"];
|
|
263
|
+
for (let i = 0; i < b32.length; i += 60) chunks.push(b32.slice(i, i + 60));
|
|
264
|
+
return chunks.join(".");
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Decode DNS label(s) back into a canonical, checksum-verified DID (`did:<method>:...`).
|
|
268
|
+
* Supports all cross-repo `ArcBlock/arc` & `@arcblock/did` encodings:
|
|
269
|
+
* - `d0.<base32chunk1>.<base32chunk2>...` and `d0-<base32>` (`ArcBlock/arc` base32 UTF-8 DID)
|
|
270
|
+
* - `did-<method>-<id>` and `<method>.<id>`
|
|
271
|
+
* - `k<41-char-base36>`, `f<52-char-hex>`, `e<31-char-base36>`, and case-preserved `z1...`/`0x...`
|
|
272
|
+
*/
|
|
273
|
+
function decodeDidFromDnsLabels(prefix, defaultMethod = "abt") {
|
|
274
|
+
try {
|
|
275
|
+
if (!prefix || typeof prefix !== "string" || !require_method.isCryptoMethod(defaultMethod)) return null;
|
|
276
|
+
const trimmed = prefix.trim();
|
|
277
|
+
if (!trimmed || trimmed.startsWith(".") || trimmed.endsWith(".") || trimmed.includes("..")) return null;
|
|
278
|
+
const rawLabels = trimmed.split(".");
|
|
279
|
+
for (const lbl of rawLabels) if (!lbl || lbl.length > 63 || lbl.startsWith("-") || lbl.endsWith("-")) return null;
|
|
280
|
+
const lower = trimmed.toLowerCase();
|
|
281
|
+
let b32Payload = null;
|
|
282
|
+
if (lower.startsWith("d0-") && !lower.includes(".")) b32Payload = lower.slice(3);
|
|
283
|
+
else if (lower.startsWith("d0.")) {
|
|
284
|
+
const parts = lower.slice(3).split(".");
|
|
285
|
+
if (parts.length > 0 && parts.every((p) => p.length > 0 && p.length <= 63)) b32Payload = parts.join("");
|
|
286
|
+
}
|
|
287
|
+
if (b32Payload !== null) {
|
|
288
|
+
const decodedBytes = decodeBase32LowerToBytes(b32Payload);
|
|
289
|
+
if (!decodedBytes) return null;
|
|
290
|
+
return canonicalizeDecodedCryptoDid(new TextDecoder("utf-8", { fatal: true }).decode(decodedBytes), defaultMethod);
|
|
291
|
+
}
|
|
292
|
+
if (rawLabels.length === 2) {
|
|
293
|
+
const methodPart = rawLabels[0].toLowerCase();
|
|
294
|
+
const idPart = rawLabels[1];
|
|
295
|
+
if (require_method.isCryptoMethod(methodPart) && idPart && !idPart.includes(":")) {
|
|
296
|
+
const verified = canonicalizeDecodedCryptoDid(`did:${methodPart}:${idPart}`, methodPart);
|
|
297
|
+
if (verified) return verified;
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (rawLabels.length > 1) return null;
|
|
302
|
+
if (lower.startsWith("did-")) {
|
|
303
|
+
const rest = trimmed.slice(4);
|
|
304
|
+
const dashIdx = rest.indexOf("-");
|
|
305
|
+
if (dashIdx > 0) {
|
|
306
|
+
const methodPart = rest.slice(0, dashIdx).toLowerCase();
|
|
307
|
+
const idPart = rest.slice(dashIdx + 1);
|
|
308
|
+
if (require_method.isCryptoMethod(methodPart) && idPart && !idPart.includes(":")) {
|
|
309
|
+
const verified = canonicalizeDecodedCryptoDid(`did:${methodPart}:${idPart}`, methodPart);
|
|
310
|
+
if (verified) return verified;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
if (trimmed.includes(":")) return null;
|
|
316
|
+
return fromDnsDidLabel(trimmed, defaultMethod);
|
|
317
|
+
} catch {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
153
321
|
/**
|
|
154
322
|
* Format the canonical DID Domain hostname (`<label>.did.abtnet.io`).
|
|
155
323
|
*/
|
|
156
324
|
function toDidDomainHost(did, gatewayDomain = DEFAULT_DID_DOMAIN_GATEWAY, encoding = "base36") {
|
|
157
|
-
const cleanGateway =
|
|
325
|
+
const cleanGateway = normalizeStrictGatewayDomain(gatewayDomain);
|
|
158
326
|
return `${toDnsDidLabel(did, encoding)}.${cleanGateway}`;
|
|
159
327
|
}
|
|
160
328
|
/**
|
|
161
|
-
* Extract and verify the canonical DID from a `<label>.did.abtnet.io` hostname.
|
|
329
|
+
* Extract and verify the canonical DID from a `<label>.did.abtnet.io` (or `d0.<chunks>.did.abtnet.io`) hostname.
|
|
162
330
|
*/
|
|
163
331
|
function extractDidFromDomainHost(hostname, gatewayDomain = DEFAULT_DID_DOMAIN_GATEWAY, method = "abt") {
|
|
332
|
+
const cleanGateway = normalizeStrictGatewayDomain(gatewayDomain);
|
|
164
333
|
if (!hostname || typeof hostname !== "string") return null;
|
|
165
334
|
try {
|
|
166
|
-
const cleanGateway = require_name.normalizeName(gatewayDomain);
|
|
167
335
|
const trimmedHost = hostname.trim().replace(/\.$/, "");
|
|
336
|
+
if (!isValidStrictDnsHostname(trimmedHost)) return null;
|
|
168
337
|
const lowerHost = trimmedHost.toLowerCase();
|
|
169
338
|
const suffix = `.${cleanGateway}`;
|
|
170
339
|
if (!lowerHost.endsWith(suffix)) return null;
|
|
171
340
|
const rawLabel = trimmedHost.slice(0, trimmedHost.length - suffix.length);
|
|
172
|
-
if (!rawLabel
|
|
173
|
-
return
|
|
341
|
+
if (!rawLabel) return null;
|
|
342
|
+
return decodeDidFromDnsLabels(rawLabel, method);
|
|
174
343
|
} catch {
|
|
175
344
|
return null;
|
|
176
345
|
}
|
|
@@ -766,6 +935,89 @@ function synthesizeDidDocument(options) {
|
|
|
766
935
|
...options.keyRotationEvents?.length ? { keyRotationHistory: options.keyRotationEvents } : {}
|
|
767
936
|
};
|
|
768
937
|
}
|
|
938
|
+
const MAX_DID_TLS_TARGET_INPUT_LENGTH = 2048;
|
|
939
|
+
const ALLOWED_DID_TLS_URL_SCHEMES = new Set([
|
|
940
|
+
"https",
|
|
941
|
+
"wss",
|
|
942
|
+
"afs",
|
|
943
|
+
"http",
|
|
944
|
+
"ws"
|
|
945
|
+
]);
|
|
946
|
+
function parseValidPortString(portStr) {
|
|
947
|
+
if (!/^[1-9]\d{0,4}$/.test(portStr)) return null;
|
|
948
|
+
const port = Number(portStr);
|
|
949
|
+
return Number.isSafeInteger(port) && port >= 1 && port <= 65535 ? port : null;
|
|
950
|
+
}
|
|
951
|
+
function parseDidTlsTargetCandidate(rawInput) {
|
|
952
|
+
if (!rawInput || typeof rawInput !== "string" || rawInput.length > MAX_DID_TLS_TARGET_INPUT_LENGTH) return null;
|
|
953
|
+
for (let i = 0; i < rawInput.length; i++) {
|
|
954
|
+
const code = rawInput.charCodeAt(i);
|
|
955
|
+
if (code < 32 || code === 127) return null;
|
|
956
|
+
}
|
|
957
|
+
const trimmed = rawInput.trim();
|
|
958
|
+
if (!trimmed || /\s/.test(trimmed)) return null;
|
|
959
|
+
let scheme;
|
|
960
|
+
let hostOrDid;
|
|
961
|
+
if (trimmed.includes("://")) {
|
|
962
|
+
const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/([^/?#]*)(?:[/?#].*)?$/.exec(trimmed);
|
|
963
|
+
if (!match) return null;
|
|
964
|
+
scheme = match[1].toLowerCase();
|
|
965
|
+
if (!ALLOWED_DID_TLS_URL_SCHEMES.has(scheme)) return null;
|
|
966
|
+
const authority = match[2];
|
|
967
|
+
if (!authority || authority.includes("@") || authority.includes("\\") || authority.includes("%") || authority.startsWith("[") || authority.endsWith("]")) return null;
|
|
968
|
+
if (/^did:/i.test(authority)) {
|
|
969
|
+
const didMatch = /^did:([a-zA-Z0-9]+):([^:]+)(?::(\d+))?$/.exec(authority);
|
|
970
|
+
if (!didMatch) return null;
|
|
971
|
+
if (didMatch[3] !== void 0 && parseValidPortString(didMatch[3]) === null) return null;
|
|
972
|
+
hostOrDid = `did:${didMatch[1].toLowerCase()}:${didMatch[2]}`;
|
|
973
|
+
} else if (authority.includes(":")) {
|
|
974
|
+
const parts = authority.split(":");
|
|
975
|
+
if (parts.length !== 2 || !parts[0] || parseValidPortString(parts[1]) === null) return null;
|
|
976
|
+
hostOrDid = parts[0];
|
|
977
|
+
} else hostOrDid = authority;
|
|
978
|
+
} else {
|
|
979
|
+
if (trimmed.includes("@") || trimmed.includes("/") || trimmed.includes("\\") || trimmed.includes("?") || trimmed.includes("#") || trimmed.includes("%") || trimmed.startsWith("[") || trimmed.endsWith("]")) return null;
|
|
980
|
+
if (/^did:/i.test(trimmed)) {
|
|
981
|
+
const didMatch = /^did:([a-zA-Z0-9]+):([^:]+)$/.exec(trimmed);
|
|
982
|
+
if (!didMatch) return null;
|
|
983
|
+
hostOrDid = `did:${didMatch[1].toLowerCase()}:${didMatch[2]}`;
|
|
984
|
+
} else if (trimmed.includes(":")) {
|
|
985
|
+
const parts = trimmed.split(":");
|
|
986
|
+
if (parts.length !== 2 || !parts[0] || parseValidPortString(parts[1]) === null) return null;
|
|
987
|
+
hostOrDid = parts[0];
|
|
988
|
+
} else hostOrDid = trimmed;
|
|
989
|
+
}
|
|
990
|
+
if (hostOrDid.startsWith("did:")) {
|
|
991
|
+
const m = /^did:([a-z0-9]+):([^:]+)$/.exec(hostOrDid);
|
|
992
|
+
if (!m) return null;
|
|
993
|
+
const didMethod = m[1];
|
|
994
|
+
const didId = m[2];
|
|
995
|
+
if (didMethod === "name") {
|
|
996
|
+
const cleanDomain = didId.endsWith(".") ? didId.slice(0, -1) : didId;
|
|
997
|
+
if (!isValidStrictDnsHostname(cleanDomain)) return null;
|
|
998
|
+
return {
|
|
999
|
+
candidate: `did:name:${cleanDomain.toLowerCase()}`,
|
|
1000
|
+
...scheme ? { scheme } : {}
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
if (!require_method.isCryptoMethod(didMethod) || !require_index.isValid(hostOrDid)) return null;
|
|
1004
|
+
return {
|
|
1005
|
+
candidate: hostOrDid,
|
|
1006
|
+
...scheme ? { scheme } : {}
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
const withoutTrailingDot = hostOrDid.endsWith(".") ? hostOrDid.slice(0, -1) : hostOrDid;
|
|
1010
|
+
if (!withoutTrailingDot || IPV4_OR_IPV6_REGEX.test(withoutTrailingDot)) return null;
|
|
1011
|
+
if (!withoutTrailingDot.includes(".") && require_index.isValid(withoutTrailingDot)) return {
|
|
1012
|
+
candidate: withoutTrailingDot,
|
|
1013
|
+
...scheme ? { scheme } : {}
|
|
1014
|
+
};
|
|
1015
|
+
if (!isValidStrictDnsHostname(withoutTrailingDot)) return null;
|
|
1016
|
+
return {
|
|
1017
|
+
candidate: withoutTrailingDot,
|
|
1018
|
+
...scheme ? { scheme } : {}
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
769
1021
|
const IPV4_OR_IPV6_REGEX = /^(?:\d{1,3}\.){3}\d{1,3}$|^\[?[0-9a-fA-F:]+\]?$/;
|
|
770
1022
|
function encodeDidEndpointDigest(params) {
|
|
771
1023
|
const tuple = require_subaccount.encodeLengthPrefixedTuple([
|
|
@@ -893,14 +1145,28 @@ function verifyDomainNftBindingProof(proof, options = {}) {
|
|
|
893
1145
|
if (options.keyRotationEvents && options.keyRotationEvents.length > 0) {
|
|
894
1146
|
const rot = verifyKeyRotationChain({
|
|
895
1147
|
did: proof.ownerDid,
|
|
896
|
-
events: options.keyRotationEvents
|
|
897
|
-
expectedCurrentPublicKey: pkClean
|
|
1148
|
+
events: options.keyRotationEvents
|
|
898
1149
|
});
|
|
899
|
-
if (!rot.valid || rot.activeKeyType === null) return {
|
|
1150
|
+
if (!rot.valid || rot.activeKeyType === null || !rot.activePublicKey) return {
|
|
900
1151
|
valid: false,
|
|
901
1152
|
reason: `KEY_ROTATION_INVALID:${rot.reason}`
|
|
902
1153
|
};
|
|
903
|
-
signerKeyType = rot.activeKeyType;
|
|
1154
|
+
if (pkClean === (0, _ocap_util.stripHexPrefix)(rot.activePublicKey).toLowerCase()) signerKeyType = rot.activeKeyType;
|
|
1155
|
+
else {
|
|
1156
|
+
let matchedPriorKeyType = null;
|
|
1157
|
+
for (let i = 0; i < options.keyRotationEvents.length; i++) {
|
|
1158
|
+
const ev = options.keyRotationEvents[i];
|
|
1159
|
+
if ((0, _ocap_util.stripHexPrefix)(ev.previousPublicKey).toLowerCase() === pkClean && proof.issuedAt <= ev.rotatedAt) {
|
|
1160
|
+
matchedPriorKeyType = i === 0 ? require_type.toTypeInfo(proof.ownerDid).pk ?? _ocap_mcrypto.types.KeyType.ED25519 : options.keyRotationEvents[i - 1].newKeyType;
|
|
1161
|
+
break;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
if (matchedPriorKeyType === null) return {
|
|
1165
|
+
valid: false,
|
|
1166
|
+
reason: "KEY_ROTATION_INVALID:EXPECTED_CURRENT_KEY_MISMATCH"
|
|
1167
|
+
};
|
|
1168
|
+
signerKeyType = matchedPriorKeyType;
|
|
1169
|
+
}
|
|
904
1170
|
} else if (!doesPublicKeyMatchGenesisDid(proof.ownerDid, pkClean)) return {
|
|
905
1171
|
valid: false,
|
|
906
1172
|
reason: "OWNER_PUBLIC_KEY_MISMATCH"
|
|
@@ -937,8 +1203,9 @@ var DIDDomainEdgeRouter = class {
|
|
|
937
1203
|
this.bindingsByDomain = /* @__PURE__ */ new Map();
|
|
938
1204
|
this.nftStateByDomain = /* @__PURE__ */ new Map();
|
|
939
1205
|
this.endpointsByDidAddr = /* @__PURE__ */ new Map();
|
|
1206
|
+
this.kelByDidAddr = /* @__PURE__ */ new Map();
|
|
940
1207
|
this.simpleNameMap = /* @__PURE__ */ new Map();
|
|
941
|
-
this.gatewayDomain =
|
|
1208
|
+
this.gatewayDomain = normalizeStrictGatewayDomain(options.gatewayDomain ?? DEFAULT_DID_DOMAIN_GATEWAY);
|
|
942
1209
|
}
|
|
943
1210
|
/**
|
|
944
1211
|
* Register or update a Tier-3 physical/tunnel endpoint for a DID (`<label>.did.abtnet.io -> endpoint`).
|
|
@@ -960,7 +1227,7 @@ var DIDDomainEdgeRouter = class {
|
|
|
960
1227
|
if (!Number.isSafeInteger(updatedAt) || updatedAt < 0) throw new Error("updatedAt must be a non-negative safe integer");
|
|
961
1228
|
const existing = this.endpointsByDidAddr.get(addr);
|
|
962
1229
|
if (existing && updatedAt < existing.updatedAt) throw new Error("STALE_ENDPOINT_UPDATE: updatedAt cannot regress below existing record");
|
|
963
|
-
const effectiveRotationEvents = input.keyRotationEvents ?? existing?.keyRotationEvents;
|
|
1230
|
+
const effectiveRotationEvents = input.keyRotationEvents ?? existing?.keyRotationEvents ?? this.kelByDidAddr.get(addr);
|
|
964
1231
|
let activeKeyType = require_type.toTypeInfo(canonicalDid).pk ?? _ocap_mcrypto.types.KeyType.ED25519;
|
|
965
1232
|
let verifiedPkHex = input.publicKey ? `0x${(0, _ocap_util.stripHexPrefix)(input.publicKey).toLowerCase()}` : void 0;
|
|
966
1233
|
if (effectiveRotationEvents && effectiveRotationEvents.length > 0) {
|
|
@@ -1015,22 +1282,26 @@ var DIDDomainEdgeRouter = class {
|
|
|
1015
1282
|
updatedAt
|
|
1016
1283
|
};
|
|
1017
1284
|
this.endpointsByDidAddr.set(addr, record);
|
|
1285
|
+
if (effectiveRotationEvents && effectiveRotationEvents.length > 0) this.kelByDidAddr.set(addr, effectiveRotationEvents);
|
|
1018
1286
|
return record;
|
|
1019
1287
|
}
|
|
1020
1288
|
/**
|
|
1021
1289
|
* Register a Tier-1 -> Tier-2 custom domain binding verified by an on-chain DNS Domain NFT proof.
|
|
1022
1290
|
*/
|
|
1023
1291
|
registerDomainNftBinding(proof, options = {}) {
|
|
1292
|
+
const ownerAddr = (0, _ocap_util.toAddress)(proof.ownerDid);
|
|
1293
|
+
const effectiveKel = options.keyRotationEvents ?? this.endpointsByDidAddr.get(ownerAddr)?.keyRotationEvents ?? this.kelByDidAddr.get(ownerAddr);
|
|
1024
1294
|
const check = verifyDomainNftBindingProof(proof, {
|
|
1025
1295
|
gatewayDomain: this.gatewayDomain,
|
|
1026
1296
|
nftAssetState: options.nftAssetState,
|
|
1027
|
-
keyRotationEvents:
|
|
1297
|
+
keyRotationEvents: effectiveKel,
|
|
1028
1298
|
now: options.now
|
|
1029
1299
|
});
|
|
1030
1300
|
if (!check.valid) throw new Error(`Domain NFT binding verification failed: ${check.reason}`);
|
|
1031
1301
|
const cleanDomain = require_name.normalizeName(proof.customDomain);
|
|
1032
1302
|
this.bindingsByDomain.set(cleanDomain, proof);
|
|
1033
1303
|
if (options.nftAssetState) this.nftStateByDomain.set(cleanDomain, options.nftAssetState);
|
|
1304
|
+
if (options.keyRotationEvents && options.keyRotationEvents.length > 0) this.kelByDidAddr.set(ownerAddr, options.keyRotationEvents);
|
|
1034
1305
|
this.simpleNameMap.set(cleanDomain, proof.ownerDid);
|
|
1035
1306
|
return proof;
|
|
1036
1307
|
}
|
|
@@ -1050,28 +1321,33 @@ var DIDDomainEdgeRouter = class {
|
|
|
1050
1321
|
if (!queryInput || typeof queryInput !== "string") return null;
|
|
1051
1322
|
const trimmed = queryInput.trim();
|
|
1052
1323
|
const trace = [];
|
|
1053
|
-
if (trimmed.startsWith("did:") && !trimmed.startsWith("did:name:")) {
|
|
1054
|
-
if (!require_index.isValid(trimmed)) return null;
|
|
1055
|
-
const canonicalDid = require_parse.formatDid((0, _ocap_util.toAddress)(trimmed), require_parse.extractMethod(trimmed) || "abt");
|
|
1056
|
-
const cnameTarget = toDidDomainHost(canonicalDid, this.gatewayDomain);
|
|
1057
|
-
trace.push(`did:${canonicalDid}`, `cname:${cnameTarget}`);
|
|
1058
|
-
return this._buildResult(trimmed, void 0, void 0, cnameTarget, canonicalDid, trace);
|
|
1059
|
-
}
|
|
1060
|
-
const wildcardDid = extractDidFromDomainHost(trimmed, this.gatewayDomain, "abt");
|
|
1061
|
-
if (wildcardDid) {
|
|
1062
|
-
const cnameTarget = toDidDomainHost(wildcardDid, this.gatewayDomain);
|
|
1063
|
-
trace.push(`wildcard_did_domain:${cnameTarget}`, `did:${wildcardDid}`);
|
|
1064
|
-
return this._buildResult(trimmed, void 0, void 0, cnameTarget, wildcardDid, trace);
|
|
1065
|
-
}
|
|
1066
1324
|
try {
|
|
1325
|
+
if (/^did:/i.test(trimmed) && !/^did:name:/i.test(trimmed)) {
|
|
1326
|
+
const m = /^did:([a-z0-9]+):([^:]+)$/i.exec(trimmed);
|
|
1327
|
+
const explicitMethod = m ? m[1].toLowerCase() : "";
|
|
1328
|
+
if (!m || !require_method.isCryptoMethod(explicitMethod) || !require_index.isValid(trimmed)) return null;
|
|
1329
|
+
const addr = (0, _ocap_util.toAddress)(trimmed);
|
|
1330
|
+
const canonicalDid = require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, explicitMethod);
|
|
1331
|
+
const cnameTarget = toDidDomainHost(canonicalDid, this.gatewayDomain);
|
|
1332
|
+
trace.push(`did:${canonicalDid}`, `cname:${cnameTarget}`);
|
|
1333
|
+
return this._buildResult(trimmed, void 0, void 0, cnameTarget, canonicalDid, trace, options.keyRotationEvents);
|
|
1334
|
+
}
|
|
1335
|
+
const wildcardDid = extractDidFromDomainHost(trimmed, this.gatewayDomain, "abt");
|
|
1336
|
+
if (wildcardDid) {
|
|
1337
|
+
const cnameTarget = toDidDomainHost(wildcardDid, this.gatewayDomain);
|
|
1338
|
+
trace.push(`wildcard_did_domain:${cnameTarget}`, `did:${wildcardDid}`);
|
|
1339
|
+
return this._buildResult(trimmed, void 0, void 0, cnameTarget, wildcardDid, trace, options.keyRotationEvents);
|
|
1340
|
+
}
|
|
1067
1341
|
const cleanName = require_name.normalizeName(trimmed.replace(/^did:name:/i, ""));
|
|
1068
1342
|
const binding = this.bindingsByDomain.get(cleanName);
|
|
1069
1343
|
if (binding) {
|
|
1344
|
+
const ownerAddr = (0, _ocap_util.toAddress)(binding.ownerDid);
|
|
1070
1345
|
const effectiveNftState = options.nftAssetState ?? this.nftStateByDomain.get(cleanName);
|
|
1346
|
+
const effectiveKel = options.keyRotationEvents ?? this.endpointsByDidAddr.get(ownerAddr)?.keyRotationEvents ?? this.kelByDidAddr.get(ownerAddr);
|
|
1071
1347
|
const recheck = verifyDomainNftBindingProof(binding, {
|
|
1072
1348
|
gatewayDomain: this.gatewayDomain,
|
|
1073
1349
|
nftAssetState: effectiveNftState,
|
|
1074
|
-
keyRotationEvents:
|
|
1350
|
+
keyRotationEvents: effectiveKel,
|
|
1075
1351
|
now: options.now
|
|
1076
1352
|
});
|
|
1077
1353
|
if (!recheck.valid) {
|
|
@@ -1079,29 +1355,30 @@ var DIDDomainEdgeRouter = class {
|
|
|
1079
1355
|
return null;
|
|
1080
1356
|
}
|
|
1081
1357
|
trace.push(`custom_domain:${cleanName}`, `nft_verified:${binding.domainNftAssetDid}`, `cname:${binding.cnameTargetDidDomain}`, `did:${binding.ownerDid}`);
|
|
1082
|
-
return this._buildResult(trimmed, cleanName, binding.domainNftAssetDid, binding.cnameTargetDidDomain, binding.ownerDid, trace);
|
|
1358
|
+
return this._buildResult(trimmed, cleanName, binding.domainNftAssetDid, binding.cnameTargetDidDomain, binding.ownerDid, trace, options.keyRotationEvents);
|
|
1083
1359
|
}
|
|
1084
1360
|
const fallbackDid = this.simpleNameMap.get(cleanName);
|
|
1085
1361
|
if (fallbackDid && require_index.isValid(fallbackDid)) {
|
|
1086
1362
|
const cnameTarget = toDidDomainHost(fallbackDid, this.gatewayDomain);
|
|
1087
1363
|
trace.push(`name:${cleanName}`, `cname:${cnameTarget}`, `did:${fallbackDid}`);
|
|
1088
|
-
return this._buildResult(trimmed, cleanName, void 0, cnameTarget, fallbackDid, trace);
|
|
1364
|
+
return this._buildResult(trimmed, cleanName, void 0, cnameTarget, fallbackDid, trace, options.keyRotationEvents);
|
|
1089
1365
|
}
|
|
1090
1366
|
} catch {
|
|
1091
1367
|
return null;
|
|
1092
1368
|
}
|
|
1093
1369
|
return null;
|
|
1094
1370
|
}
|
|
1095
|
-
_buildResult(query, customDomain, domainNftAssetDid, cnameTargetDidDomain, did, trace) {
|
|
1371
|
+
_buildResult(query, customDomain, domainNftAssetDid, cnameTargetDidDomain, did, trace, overrideKeyRotationEvents) {
|
|
1096
1372
|
const addr = (0, _ocap_util.toAddress)(did);
|
|
1097
1373
|
const endpoint = this.endpointsByDidAddr.get(addr);
|
|
1098
1374
|
if (endpoint) trace.push(`endpoint:${endpoint.endpointUrl}`);
|
|
1099
1375
|
const customDomainsForDid = [];
|
|
1100
1376
|
for (const [dom, b] of this.bindingsByDomain.entries()) if ((0, _ocap_util.toAddress)(b.ownerDid) === addr && customDomainsForDid.length < MAX_CUSTOM_DOMAINS_PER_DID) customDomainsForDid.push(dom);
|
|
1101
1377
|
if (customDomain && !customDomainsForDid.includes(customDomain)) customDomainsForDid.push(customDomain);
|
|
1378
|
+
const effectiveKel = overrideKeyRotationEvents ?? endpoint?.keyRotationEvents ?? this.kelByDidAddr.get(addr);
|
|
1102
1379
|
const didDocument = synthesizeDidDocument({
|
|
1103
1380
|
did,
|
|
1104
|
-
publicKey: endpoint?.publicKey,
|
|
1381
|
+
publicKey: overrideKeyRotationEvents?.length ? void 0 : endpoint?.publicKey,
|
|
1105
1382
|
x25519PublicKey: endpoint?.x25519PublicKey,
|
|
1106
1383
|
customDomains: customDomainsForDid,
|
|
1107
1384
|
gatewayDomain: this.gatewayDomain,
|
|
@@ -1109,7 +1386,7 @@ var DIDDomainEdgeRouter = class {
|
|
|
1109
1386
|
afsEndpoint: endpoint?.afsEndpoint,
|
|
1110
1387
|
noiseMeshEndpoint: endpoint?.ipOrMeshAddress,
|
|
1111
1388
|
nextKeyCommitment: endpoint?.nextKeyCommitment,
|
|
1112
|
-
keyRotationEvents:
|
|
1389
|
+
keyRotationEvents: effectiveKel
|
|
1113
1390
|
});
|
|
1114
1391
|
return {
|
|
1115
1392
|
found: true,
|
|
@@ -1123,6 +1400,76 @@ var DIDDomainEdgeRouter = class {
|
|
|
1123
1400
|
trace
|
|
1124
1401
|
};
|
|
1125
1402
|
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Resolve any URL (`https://...`, `wss://...`, `afs://...`), `<did>.arc`, `<label>.did.abtnet.io`,
|
|
1405
|
+
* `did:abt:...`, `did:name:...`, or custom DNS-NFT domain into a zero-CA `DID-TLS` target identity
|
|
1406
|
+
* (`targetDid`, active Ed25519/KEL public key, Tier-2 CNAME domain, and physical endpoint URL).
|
|
1407
|
+
*
|
|
1408
|
+
* Fails closed (`null`) on malformed/credentialed URLs, invalid `.arc` DID hosts, expired/sold DNS-NFT bindings,
|
|
1409
|
+
* or broken KEL chains.
|
|
1410
|
+
*/
|
|
1411
|
+
resolveDidTlsTarget(input, options = {}) {
|
|
1412
|
+
try {
|
|
1413
|
+
const parsed = parseDidTlsTargetCandidate(input);
|
|
1414
|
+
if (!parsed) return null;
|
|
1415
|
+
const { candidate, scheme } = parsed;
|
|
1416
|
+
const prefixTrace = scheme ? [`scheme:${scheme}`] : [];
|
|
1417
|
+
let resolved = null;
|
|
1418
|
+
let resolutionTier;
|
|
1419
|
+
if (candidate.startsWith("did:") && !candidate.startsWith("did:name:")) {
|
|
1420
|
+
resolved = this.resolveThreeTier(candidate, options);
|
|
1421
|
+
resolutionTier = "direct-did";
|
|
1422
|
+
} else if (!candidate.includes(".") && require_index.isValid(candidate)) {
|
|
1423
|
+
const addr = (0, _ocap_util.toAddress)(candidate);
|
|
1424
|
+
const canonical = require_parse.formatDid(require_type.isEthereumDid(addr) ? require_type.toChecksumAddress(addr) : addr, "abt");
|
|
1425
|
+
resolved = this.resolveThreeTier(canonical, options);
|
|
1426
|
+
resolutionTier = "direct-did";
|
|
1427
|
+
} else if (candidate.toLowerCase().endsWith(".arc")) {
|
|
1428
|
+
const decodedArcDid = decodeDidFromDnsLabels(candidate.slice(0, candidate.length - 4), "abt");
|
|
1429
|
+
if (!decodedArcDid) return null;
|
|
1430
|
+
prefixTrace.push(`arc_host:${candidate}`);
|
|
1431
|
+
resolved = this.resolveThreeTier(decodedArcDid, options);
|
|
1432
|
+
resolutionTier = "direct-did";
|
|
1433
|
+
} else {
|
|
1434
|
+
const isGatewaySubdomain = !candidate.startsWith("did:name:") && candidate.toLowerCase().endsWith(`.${this.gatewayDomain}`);
|
|
1435
|
+
if (isGatewaySubdomain && !extractDidFromDomainHost(candidate, this.gatewayDomain, "abt")) return null;
|
|
1436
|
+
resolved = this.resolveThreeTier(candidate, options);
|
|
1437
|
+
if (!resolved || !resolved.found) return null;
|
|
1438
|
+
if (isGatewaySubdomain) resolutionTier = "wildcard-fallback";
|
|
1439
|
+
else if (resolved.domainNftAssetDid) resolutionTier = "custom-domain-nft";
|
|
1440
|
+
else resolutionTier = "name-registry";
|
|
1441
|
+
}
|
|
1442
|
+
if (!resolved || !resolved.found) return null;
|
|
1443
|
+
if (!isValidStrictDnsHostname(resolved.cnameTargetDidDomain) || resolved.customDomain !== void 0 && !isValidStrictDnsHostname(resolved.customDomain)) return null;
|
|
1444
|
+
const targetAddr = (0, _ocap_util.toAddress)(resolved.did);
|
|
1445
|
+
const trace = [...prefixTrace, ...resolved.trace];
|
|
1446
|
+
const effectiveKel = options.keyRotationEvents ?? resolved.endpoint?.keyRotationEvents ?? this.kelByDidAddr.get(targetAddr);
|
|
1447
|
+
let activePublicKeyHex = null;
|
|
1448
|
+
if (effectiveKel && effectiveKel.length > 0) {
|
|
1449
|
+
const kelCheck = verifyKeyRotationChain({
|
|
1450
|
+
did: resolved.did,
|
|
1451
|
+
events: effectiveKel
|
|
1452
|
+
});
|
|
1453
|
+
if (!kelCheck.valid || !kelCheck.activePublicKey) return null;
|
|
1454
|
+
activePublicKeyHex = (0, _ocap_util.stripHexPrefix)(kelCheck.activePublicKey).toLowerCase();
|
|
1455
|
+
trace.push(`kel_active_pk:${activePublicKeyHex}`);
|
|
1456
|
+
} else if (resolved.didDocument.verificationMethod[0]?.publicKeyHex) activePublicKeyHex = (0, _ocap_util.stripHexPrefix)(resolved.didDocument.verificationMethod[0].publicKeyHex).toLowerCase();
|
|
1457
|
+
else if (resolved.customDomain) {
|
|
1458
|
+
const binding = this.bindingsByDomain.get(resolved.customDomain);
|
|
1459
|
+
if (binding?.ownerPublicKey) activePublicKeyHex = (0, _ocap_util.stripHexPrefix)(binding.ownerPublicKey).toLowerCase();
|
|
1460
|
+
}
|
|
1461
|
+
return {
|
|
1462
|
+
targetDid: resolved.did,
|
|
1463
|
+
activePublicKeyHex,
|
|
1464
|
+
cnameTargetDidDomain: resolved.cnameTargetDidDomain,
|
|
1465
|
+
endpointUrl: resolved.endpoint?.endpointUrl ?? null,
|
|
1466
|
+
resolutionTier,
|
|
1467
|
+
trace
|
|
1468
|
+
};
|
|
1469
|
+
} catch {
|
|
1470
|
+
return null;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1126
1473
|
resolve(name) {
|
|
1127
1474
|
const res = this.resolveThreeTier(name);
|
|
1128
1475
|
return res ? res.did : null;
|
|
@@ -1156,6 +1503,7 @@ var DIDDomainEdgeRouter = class {
|
|
|
1156
1503
|
this.bindingsByDomain.clear();
|
|
1157
1504
|
this.nftStateByDomain.clear();
|
|
1158
1505
|
this.endpointsByDidAddr.clear();
|
|
1506
|
+
this.kelByDidAddr.clear();
|
|
1159
1507
|
}
|
|
1160
1508
|
};
|
|
1161
1509
|
|
|
@@ -1172,11 +1520,14 @@ exports.createAccountMigratePreRotationData = createAccountMigratePreRotationDat
|
|
|
1172
1520
|
exports.createDomainNftBindingProof = createDomainNftBindingProof;
|
|
1173
1521
|
exports.createKeyRotationEvent = createKeyRotationEvent;
|
|
1174
1522
|
exports.createPreRotationCommitment = createPreRotationCommitment;
|
|
1523
|
+
exports.decodeDidFromDnsLabels = decodeDidFromDnsLabels;
|
|
1175
1524
|
exports.encodeDidEndpointDigest = encodeDidEndpointDigest;
|
|
1525
|
+
exports.encodeDidForDnsLabels = encodeDidForDnsLabels;
|
|
1176
1526
|
exports.extractAccountPreRotationData = extractAccountPreRotationData;
|
|
1177
1527
|
exports.extractDidFromDomainHost = extractDidFromDomainHost;
|
|
1178
1528
|
exports.fromDnsDidLabel = fromDnsDidLabel;
|
|
1179
1529
|
exports.isValidPreRotationCommitment = isValidPreRotationCommitment;
|
|
1530
|
+
exports.isValidStrictDnsHostname = isValidStrictDnsHostname;
|
|
1180
1531
|
exports.normalizePreRotationCommitment = normalizePreRotationCommitment;
|
|
1181
1532
|
exports.normalizePublicKeyHex = normalizePublicKeyHex;
|
|
1182
1533
|
exports.synthesizeDidDocument = synthesizeDidDocument;
|