@keetanetwork/anchor 0.0.3 → 0.0.6

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.
Files changed (49) hide show
  1. package/client/index.d.ts +6 -0
  2. package/client/index.d.ts.map +1 -1
  3. package/client/index.js +7 -0
  4. package/client/index.js.map +1 -1
  5. package/lib/error.d.ts +14 -0
  6. package/lib/error.d.ts.map +1 -0
  7. package/lib/error.js +38 -0
  8. package/lib/error.js.map +1 -0
  9. package/lib/http-server.d.ts +59 -0
  10. package/lib/http-server.d.ts.map +1 -0
  11. package/lib/http-server.js +383 -0
  12. package/lib/http-server.js.map +1 -0
  13. package/lib/resolver.d.ts +159 -60
  14. package/lib/resolver.d.ts.map +1 -1
  15. package/lib/resolver.js +3519 -384
  16. package/lib/resolver.js.map +1 -1
  17. package/lib/utils/brand.d.ts +12 -0
  18. package/lib/utils/brand.d.ts.map +1 -0
  19. package/lib/utils/brand.js +2 -0
  20. package/lib/utils/brand.js.map +1 -0
  21. package/lib/utils/never.d.ts +4 -0
  22. package/lib/utils/never.d.ts.map +1 -1
  23. package/lib/utils/never.js.map +1 -1
  24. package/lib/utils/signing.d.ts +17 -0
  25. package/lib/utils/signing.d.ts.map +1 -0
  26. package/lib/utils/signing.js +73 -0
  27. package/lib/utils/signing.js.map +1 -0
  28. package/lib/utils/url.d.ts +2 -0
  29. package/lib/utils/url.d.ts.map +1 -0
  30. package/lib/utils/url.js +8 -0
  31. package/lib/utils/url.js.map +1 -0
  32. package/npm-shrinkwrap.json +529 -16210
  33. package/package.json +31 -40
  34. package/services/fx/client.d.ts +137 -0
  35. package/services/fx/client.d.ts.map +1 -0
  36. package/services/fx/client.js +519 -0
  37. package/services/fx/client.js.map +1 -0
  38. package/services/fx/common.d.ts +133 -0
  39. package/services/fx/common.d.ts.map +1 -0
  40. package/services/fx/common.js +45 -0
  41. package/services/fx/common.js.map +1 -0
  42. package/services/fx/server.d.ts +58 -0
  43. package/services/fx/server.d.ts.map +1 -0
  44. package/services/fx/server.js +349 -0
  45. package/services/fx/server.js.map +1 -0
  46. package/services/kyc/client.d.ts +1 -1
  47. package/services/kyc/client.d.ts.map +1 -1
  48. package/services/kyc/client.js +7 -53
  49. package/services/kyc/client.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/lib/resolver.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAChE,OAAO,YAAY,MAAM,6BAA6B,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAgM/C,SAAS,gCAAgC,CAAC,KAA0B;IACnE,IAAI,YAAY,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;SAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7D,KAAK,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,OAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,+BAA+B,CAAC,KAAyB;IACjE,IAAI,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;SAAM,IAAI,YAAY,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,KAAK,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,OAA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C/B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;IACvB,CAAC;;AAGF,eAAe,QAAQ,CAAC","sourcesContent":["import * as KeetaNetClient from '@keetanetwork/keetanet-client';\nimport CurrencyInfo from '@keetanetwork/currency-info';\nimport type { Logger } from './log/index.ts';\nimport type { JSONSerializable } from './utils/json.ts';\nimport { assertNever } from './utils/never.js';\nimport { Buffer } from './utils/buffer.js';\nimport crypto from './utils/crypto.js';\n\nimport { createIs, createAssert } from 'typia';\n\ntype ExternalURL = { external: '2b828e33-2692-46e9-817e-9b93d63f28fd'; url: string; };\n\ntype KeetaNetAccount = InstanceType<typeof KeetaNetClient.lib.Account>;\n\ntype CurrencySearchInput = CurrencyInfo.ISOCurrencyCode | CurrencyInfo.ISOCurrencyNumber | CurrencyInfo.Currency;\ntype CurrencySearchCanonical = CurrencyInfo.ISOCurrencyCode; /* XXX:TODO */\ntype CountrySearchInput = CurrencyInfo.ISOCountryCode | CurrencyInfo.ISOCountryNumber | CurrencyInfo.Country;\ntype CountrySearchCanonical = CurrencyInfo.ISOCountryCode; /* XXX:TODO */\n\n/**\n * A cache object\n */\ntype URLCacheObject = Map<string, {\n\tpass: true;\n\tvalue: JSONSerializable;\n\texpires: Date;\n} | {\n\tpass: false;\n\terror: unknown;\n\texpires: Date;\n}>;\n\n/**\n * Service Metadata General Structure\n */\ntype ServiceMetadata = {\n\tversion: number;\n\tservices: {\n\t\tbanking?: {\n\t\t\t[id: string]: {\n\t\t\t\toperations: {\n\t\t\t\t\tcreateAccount?: string;\n\t\t\t\t};\n\t\t\t\tcurrencyCodes: string[];\n\t\t\t\tcountryCodes: string[];\n\t\t\t\tkycProviders?: string[];\n\t\t\t};\n\t\t};\n\t\tkyc?: {\n\t\t\t[id: string]: {\n\t\t\t\toperations: {\n\t\t\t\t\t/**\n\t\t\t\t\t * Check if the KYC provider can\n\t\t\t\t\t * service a more specific locality\n\t\t\t\t\t * (optional)\n\t\t\t\t\t */\n\t\t\t\t\tcheckLocality?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Request an estimate for a KYC\n\t\t\t\t\t * verification (optional)\n\t\t\t\t\t */\n\t\t\t\t\tgetEstimate?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Begin the KYC verification process\n\t\t\t\t\t * with this KYC provider\n\t\t\t\t\t */\n\t\t\t\t\tcreateVerification?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Get the certificate for the\n\t\t\t\t\t * KYC verification\n\t\t\t\t\t */\n\t\t\t\t\tgetCertificates?: string;\n\t\t\t\t};\n\t\t\t\t/**\n\t\t\t\t * Country codes which this KYC provider can\n\t\t\t\t * validate accounts in. If this is not\n\t\t\t\t * specified, then the KYC provider can\n\t\t\t\t * validate accounts in any country.\n\t\t\t\t */\n\t\t\t\tcountryCodes?: string[];\n\t\t\t\t/**\n\t\t\t\t * The Certificate Authority (CA) Certificate\n\t\t\t\t * that this KYC provider uses to sign KYC\n\t\t\t\t * certificates. This is used to identify the\n\t\t\t\t * KYC provider.\n\t\t\t\t */\n\t\t\t\tca: string;\n\t\t\t};\n\t\t};\n\t\tfx?: {\n\t\t\tinputCurrencyCodes: {\n\t\t\t\toutputCurrencyCodes: string[];\n\t\t\t\tkycProviders: string[];\n\t\t\t}[];\n\t\t};\n\t\tinbound?: {\n\t\t\t/* XXX:TODO */\n\t\t\tworkInProgress?: true;\n\t\t};\n\t\toutbound?: {\n\t\t\t/* XXX:TODO */\n\t\t\tworkInProgress?: true;\n\t\t};\n\t\tcards?: {\n\t\t\t/* XXX:TODO */\n\t\t\tworkInProgress?: true;\n\t\t};\n\t};\n};\n\n/**\n * Types of services which can be resolved\n */\ntype Services = keyof ServiceMetadata['services'];\n\n/**\n * Search criteria for each service type\n */\ntype ServiceSearchCriteria<T extends Services> = {\n\t'banking': {\n\t\t/**\n\t\t * Search for a banking provider which supports creating\n\t\t * accounts in ALL of the following currencies.\n\t\t */\n\t\tcurrencyCodes?: CurrencySearchInput[];\n\t\t/**\n\t\t * Search for a banking provider which supports creating\n\t\t * accounts in ANY of the following countries.\n\t\t */\n\t\tcountryCodes?: CountrySearchInput[];\n\t\t/**\n\t\t * Search for a banking provider which supports creating\n\t\t * accounts verified by ANY of the following KYC providers\n\t\t * (DN).\n\t\t */\n\t\tkycProviders?: string[]; /* XXX:TODO */\n\t};\n\t'fx': {\n\t\t/**\n\t\t * Search for a provider which can convert from the following\n\t\t * input currency\n\t\t */\n\t\tinputCurrencyCode: CurrencySearchInput;\n\t\t/**\n\t\t * Search for a provider which can convert to the following\n\t\t * output currency\n\t\t */\n\t\toutputCurrencyCode: CurrencySearchInput;\n\t};\n\t'kyc': {\n\t\t/**\n\t\t * Search for a KYC provider which can verify accounts in ALL\n\t\t * of the following countries.\n\t\t */\n\t\tcountryCodes: CountrySearchInput[];\n\t};\n\t'inbound': {\n\t\t/* XXX:TODO */\n\t\tworkInProgress: true;\n\t};\n\t'outbound': {\n\t\t/* XXX:TODO */\n\t\tworkInProgress: true;\n\t};\n\t'cards': {\n\t\t/* XXX:TODO */\n\t\tworkInProgress: true;\n\t};\n}[T];\n\ntype ResolverConfig = {\n\t/**\n\t * The \"root\" account to use as the basis for all lookups. It should\n\t * contain the authoritative information for resolving in its\n\t * Metadata.\n\t */\n\troot: KeetaNetAccount;\n\t/**\n\t * A KeetaNet Client to access the network using.\n\t */\n\tclient: KeetaNetClient.Client | KeetaNetClient.UserClient;\n\t/**\n\t * A list of trusted Certificate Authorities to use when connecting to\n\t * external HTTPS services.\n\t */\n\ttrustedCAs: string[]; /* XXX:TODO */\n\t/**\n\t * Logger to use for debugging\n\t */\n\tlogger?: Logger;\n\t/**\n\t * ID for this instance of the resolver\n\t */\n\tid?: string;\n\t/**\n\t * Caching Parameters\n\t */\n\tcache?: Omit<NonNullable<MetadataConfig['cache']>, 'instance'>;\n}\n\nfunction convertToCurrencySearchCanonical(input: CurrencySearchInput): CurrencySearchCanonical {\n\tif (CurrencyInfo.Currency.isCurrencyCode(input)) {\n\t\treturn(input);\n\t} else if (CurrencyInfo.Currency.isISOCurrencyNumber(input)) {\n\t\tinput = new CurrencyInfo.Currency(input);\n\t}\n\n\treturn(input.code);\n}\n\nfunction convertToCountrySearchCanonical(input: CountrySearchInput): CountrySearchCanonical {\n\tif (CurrencyInfo.Country.isCountryCode(input)) {\n\t\treturn(input);\n\t} else if (CurrencyInfo.Country.isISOCountryNumber(input)) {\n\t\tinput = new CurrencyInfo.Country(input);\n\t}\n\n\treturn(input.code);\n}\n\n/**\n * Check if a value is an ExternalURL\n */\nconst isExternalURL = createIs<ExternalURL>();\n\ntype JSONSerializablePrimitive = Exclude<JSONSerializable, object>;\ntype ValuizeInput = JSONSerializablePrimitive | ValuizableObject | ValuizableArray;\ntype ValuizableArray = (ValuizableMethod | undefined)[];\ntype ValuizableObject = { [key: string]: ValuizableMethod | undefined };\n\ntype ValuizableKind = 'any' | 'object' | 'array' | 'primitive' | 'string' | 'number' | 'boolean';\ninterface ValuizableMethod {\n\t(expect: 'object'): Promise<ValuizableObject>;\n\t(expect: 'array'): Promise<ValuizableArray>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n\t(expect: 'string'): Promise<string>;\n\t(expect: 'number'): Promise<number>;\n\t(expect: 'boolean'): Promise<boolean>;\n\t(expect: 'any'): Promise<ValuizeInput>;\n\t(expect?: ValuizableKind): Promise<ValuizeInput>;\n};\n\ninterface ToValuizableExpectString {\n\t(expect: 'string'): Promise<string>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n};\ninterface ToValuizableExpectNumber {\n\t(expect: 'number'): Promise<number>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n};\ninterface ToValuizableExpectBoolean {\n\t(expect: 'boolean'): Promise<boolean>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n};\n/* eslint-disable @stylistic/indent */\ntype ToValuizableObject<T extends object> = {\n\t[K in keyof T]:\n\t\tT[K] extends string ? ToValuizableExpectString :\n\t\tT[K] extends number ? ToValuizableExpectNumber :\n\t\tT[K] extends boolean ? ToValuizableExpectBoolean :\n\t\tT[K] extends JSONSerializablePrimitive ?\n\t\t\t(expect: 'primitive') => Promise<JSONSerializablePrimitive> :\n\t\tT[K] extends unknown[] ?\n\t\t\t(expect: 'array') => Promise<ToValuizableObject<T[K]>> :\n\t\tT[K] extends object ?\n\t\t\t(expect: 'object') => Promise<ToValuizableObject<T[K]>> :\n\t\tT[K] extends (infer U | undefined) ?\n\t\t\tToValuizable<U> | undefined :\n\t\tnever;\n};\ntype ToValuizable<T> = ToValuizableObject<{ tmp: T }>['tmp'];\n\ntype ToJSONValuizableObject<T extends object> = {\n\t[K in keyof T]: (\n\t\tT[K] extends object ?\n\t\t\tToJSONValuizableObject<T[K]> :\n\t\tT[K] extends (object | undefined) ?\n\t\t\tToJSONValuizableObject<NonNullable<T[K]>> | undefined :\n\t\tT[K]\n\t) | ExternalURL;\n};\ntype ToJSONValuizable<T> = ToJSONValuizableObject<{ tmp: T }>['tmp'];\n\n/*\n * Access token to share with the Metadata object to allow it to\n * access the mutable stats object.\n */\nconst statsAccessToken = Symbol('statsAccessToken');\n\ntype MetadataConfig = {\n\ttrustedCAs: ResolverConfig['trustedCAs'];\n\tclient: KeetaNetClient.Client;\n\tlogger?: ResolverConfig['logger'];\n\tresolver: Resolver;\n\tcache?: {\n\t\tinstance: URLCacheObject;\n\t\tpositiveTTL?: number;\n\t\tnegativeTTL?: number;\n\t};\n\tparent?: Metadata;\n};\n\ntype ValuizableInstance = { value: ValuizableMethod };\n\nconst assertServiceMetadata = createAssert<ToJSONValuizable<ServiceMetadata>>();\n\nclass Metadata implements ValuizableInstance {\n\treadonly #cache: Required<NonNullable<MetadataConfig['cache']>>;\n\treadonly #trustedCAs: ResolverConfig['trustedCAs'];\n\treadonly #client: KeetaNetClient.Client;\n\treadonly #logger: Logger | undefined;\n\treadonly #url: URL;\n\treadonly #resolver: Resolver;\n\treadonly #stats: ResolverStats;\n\tprivate readonly seenURLs: Set<string>;\n\n\tprivate static readonly instanceTypeID = 'Metadata:c85b3d67-9548-4042-9862-f6e6677690ac';\n\n\tstatic isInstance(value: unknown): value is Metadata {\n\t\tif (typeof value !== 'object' || value === null) {\n\t\t\treturn(false);\n\t\t}\n\t\tif (!('instanceID' in value)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(value.instanceID === Metadata.instanceTypeID);\n\t}\n\n\t/**\n\t * Format the supplied Metadata as appropriate to be included\n\t * within the Metadata field of a KeetaNet acccount to serve\n\t * as the Metadata for the Resolver.\n\t */\n\tstatic formatMetadata(metadata: ToJSONValuizable<ServiceMetadata>): string;\n\t// eslint-disable-next-line @typescript-eslint/unified-signatures\n\tstatic formatMetadata(metadata: JSONSerializable): string;\n\tstatic formatMetadata(metadata: JSONSerializable | ToJSONValuizable<ServiceMetadata>): string {\n\t\treturn(Buffer.from(JSON.stringify(metadata)).toString('base64'));\n\t}\n\n\t/**\n\t * Assert that the supplied value is a valid Metadata Root Object\n\t */\n\tstatic assertMetadata(value: unknown): asserts value is ToJSONValuizable<ServiceMetadata> {\n\t\tassertServiceMetadata(value);\n\t}\n\n\tconstructor(url: string | URL, config: MetadataConfig) {\n\t\t/*\n\t\t * Define an \"instanceTypeID\" as an unenumerable property to\n\t\t * ensure that we can identify this object as an instance of\n\t\t * Metadata, but we do not need to serialize it.\n\t\t */\n\t\tObject.defineProperty(this, 'instanceTypeID', {\n\t\t\tvalue: Metadata.instanceTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t\tthis.#url = new URL(url);\n\t\tthis.#cache = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tinstance: config.cache?.instance ?? new Map() satisfies URLCacheObject as URLCacheObject,\n\t\t\tpositiveTTL: config.cache?.positiveTTL ?? 60 * 1000,\n\t\t\tnegativeTTL: config.cache?.negativeTTL ?? 5 * 1000\n\t\t};\n\t\tthis.#trustedCAs = config.trustedCAs;\n\t\tthis.#client = config.client;\n\t\tthis.#logger = config.logger;\n\t\tthis.#resolver = config.resolver;\n\t\tthis.#stats = this.#resolver._mutableStats(statsAccessToken);\n\t\tif (config.parent !== undefined) {\n\t\t\tthis.seenURLs = config.parent.seenURLs;\n\t\t} else {\n\t\t\tthis.seenURLs = new Set();\n\t\t}\n\t}\n\n\tprivate async parseMetadata(metadata: string) {\n\t\t/*\n\t\t * JSON.parse() will always return a JSONSerializable,\n\t\t * and not `unknown`, so we can safely cast it.\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst retval = await this.resolveValue(JSON.parse(metadata) as JSONSerializable);\n\n\t\treturn(retval);\n\t}\n\n\tprivate async readKeetaNetURL(url: URL): Promise<JSONSerializable> {\n\t\tconst accountString = url.hostname;\n\t\tconst path = url.pathname;\n\n\t\tthis.#stats.keetanet.reads++;\n\n\t\tif (path !== '/metadata') {\n\t\t\tthrow(new Error(`Unsupported path: ${path}`));\n\t\t}\n\n\t\tlet account: KeetaNetAccount | string;\n\t\ttry {\n\t\t\taccount = KeetaNetClient.lib.Account.fromPublicKeyString(accountString);\n\t\t} catch {\n\t\t\treturn('');\n\t\t}\n\n\t\tconst accountInfo = await this.#client.getAccountInfo(account);\n\t\tconst metadata = Buffer.from(accountInfo.info.metadata, 'base64').toString('utf-8');\n\t\tif (metadata === '') {\n\t\t\treturn('');\n\t\t}\n\n\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Account info for', accountString, '=', accountInfo.info);\n\t\tconst retval = await this.parseMetadata(metadata);\n\t\treturn(retval);\n\t}\n\n\tprivate async readHTTPSURL(url: URL): Promise<JSONSerializable> {\n\t\tthis.#stats.https.reads++;\n\n\t\tconst results = await fetch(url.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tif (!results.ok) {\n\t\t\tthrow(new Error(`Error HTTP status ${results.status} ${results.statusText} for ${url.toString()}`));\n\t\t}\n\n\t\tif (results.status === 204) {\n\t\t\t/*\n\t\t\t * 204 No Content is a valid response, so we return an empty\n\t\t\t * object.\n\t\t\t */\n\t\t\treturn({});\n\t\t}\n\n\t\tif (results.status !== 200) {\n\t\t\tthrow(new Error(`Unexpected HTTP status ${results.status} for ${url.toString()}`));\n\t\t}\n\n\t\tconst metadata = JSON.stringify(await results.json());\n\n\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Read URL', url.toString(), ':', metadata);\n\n\t\tconst retval = await this.parseMetadata(metadata);\n\n\t\treturn(retval);\n\t}\n\n\tprivate async readURL(url: URL) {\n\t\tthis.#stats.reads++;\n\n\t\tconst cacheKey = url.toString();\n\t\t/*\n\t\t * To ensure any circular references are handled correctly, we\n\t\t * keep track of a chain of accessed URLs. If we see the same\n\t\t * URL twice, then we have a circular reference.\n\t\t */\n\t\tif (this.seenURLs.has(cacheKey)) {\n\t\t\treturn('');\n\t\t}\n\t\tthis.seenURLs.add(cacheKey);\n\n\t\t/*\n\t\t * Verify that the cache entry is still valid. If it is not,\n\t\t * then remove it from the cache.\n\t\t */\n\t\tlet cacheVal = this.#cache.instance.get(cacheKey);\n\n\t\tif (this.#cache.instance.has(cacheKey) && cacheVal !== undefined) {\n\t\t\tif (cacheVal.expires < new Date()) {\n\t\t\t\tthis.#cache.instance.delete(cacheKey);\n\t\t\t\tcacheVal = undefined;\n\t\t\t}\n\t\t}\n\n\t\tif (cacheVal !== undefined) {\n\t\t\tthis.#stats.cache.hit++;\n\n\t\t\tif (cacheVal.pass) {\n\t\t\t\treturn(cacheVal.value);\n\t\t\t} else {\n\t\t\t\tthrow(cacheVal.error);\n\t\t\t}\n\t\t}\n\n\t\tthis.#stats.cache.miss++;\n\n\t\tlet retval: JSONSerializable;\n\t\ttry {\n\t\t\tconst protocol = url.protocol;\n\t\t\tif (protocol === 'keetanet:') {\n\t\t\t\tretval = await this.readKeetaNetURL(url);\n\t\t\t} else if (protocol === 'https:') {\n\t\t\t\tretval = await this.readHTTPSURL(url);\n\t\t\t} else {\n\t\t\t\tthis.#stats.unsupported.reads++;\n\t\t\t\tthrow(new Error(`Unsupported protocol: ${protocol}`));\n\t\t\t}\n\t\t} catch (readError) {\n\t\t\tthis.#cache.instance.set(cacheKey, {\n\t\t\t\tpass: false,\n\t\t\t\terror: readError,\n\t\t\t\texpires: new Date(Date.now() + this.#cache.negativeTTL)\n\t\t\t});\n\n\t\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Read URL', url.toString(), 'failed:', readError);\n\t\t\tthrow(readError);\n\t\t}\n\n\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Read URL', url.toString(), ':', retval);\n\n\t\tthis.#cache.instance.set(cacheKey, {\n\t\t\tpass: true,\n\t\t\tvalue: retval,\n\t\t\texpires: new Date(Date.now() + this.#cache.positiveTTL)\n\t\t});\n\n\t\treturn(retval);\n\t}\n\n\tprivate async resolveValue<T extends ExternalURL | undefined>(value: T): Promise<JSONSerializable>;\n\tprivate async resolveValue<T extends JSONSerializable | undefined>(value: T): Promise<T>;\n\tprivate async resolveValue<T extends JSONSerializable | ExternalURL | undefined>(value: T): Promise<T | JSONSerializable> {\n\t\tif (value === undefined) {\n\t\t\treturn(value);\n\t\t}\n\n\t\t/*\n\t\t * If the value passed in is a reference to an external URL, then\n\t\t * we need to read that URL (and continue to resolve it).\n\t\t */\n\t\tif (isExternalURL(value)) {\n\t\t\tconst url = new URL(value.url);\n\t\t\tconst retval = await this.readURL(url);\n\n\t\t\treturn(await this.resolveValue(retval));\n\t\t}\n\n\t\treturn(value);\n\t}\n\n\tprivate assertValuizableKind(input: ValuizeInput, expect: ValuizableKind) {\n\t\tswitch (expect) {\n\t\t\tcase 'any':\n\t\t\t\treturn(input);\n\t\t\tcase 'object':\n\t\t\t\tif (typeof input !== 'object') {\n\t\t\t\t\tthrow(new Error(`expected an object, got ${typeof input}`));\n\t\t\t\t}\n\n\t\t\t\tif (input === null) {\n\t\t\t\t\tthrow(new Error('expected an object, got null'));\n\t\t\t\t}\n\n\t\t\t\tif (Array.isArray(input)) {\n\t\t\t\t\tthrow(new Error('expected an object, got an array'));\n\t\t\t\t}\n\n\t\t\t\treturn(input);\n\t\t\tcase 'array':\n\t\t\t\tif (!Array.isArray(input)) {\n\t\t\t\t\tthrow(new Error(`expected an array, got ${typeof input}`));\n\t\t\t\t}\n\n\t\t\t\treturn(input);\n\t\t\tcase 'primitive':\n\t\t\t\tif ((typeof input === 'object' && input !== null) || input === undefined) {\n\t\t\t\t\tthrow(new Error(`expected a primitive, got ${typeof input}`));\n\t\t\t\t}\n\n\t\t\t\treturn(input);\n\t\t\tcase 'string':\n\t\t\tcase 'number':\n\t\t\tcase 'boolean':\n\t\t\t\tif (typeof input !== expect) {\n\t\t\t\t\tthrow(new Error(`expected a ${expect}, got ${typeof input}`));\n\t\t\t\t}\n\t\t\t\treturn(input);\n\t\t\tdefault:\n\t\t\t\tassertNever(expect);\n\t\t}\n\t}\n\n\tprivate async valuize(value: JSONSerializable): Promise<ValuizeInput> {\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tlet newValue: ValuizableObject | ValuizableArray;\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tnewValue = [];\n\t\t\t} else {\n\t\t\t\tnewValue = {};\n\t\t\t}\n\t\t\tfor (const key in value) {\n\t\t\t\t/*\n\t\t\t\t * Since `key` is the index of the array or\n\t\t\t\t * object, it is safe to use it to index\n\t\t\t\t * into the array or object.\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst keyValue: JSONSerializable = value[key];\n\n\t\t\t\tif (isExternalURL(keyValue)) {\n\t\t\t\t\tconst newMetadataObject = new Metadata(keyValue.url, {\n\t\t\t\t\t\ttrustedCAs: this.#trustedCAs,\n\t\t\t\t\t\tclient: this.#client,\n\t\t\t\t\t\tlogger: this.#logger,\n\t\t\t\t\t\tresolver: this.#resolver,\n\t\t\t\t\t\tcache: this.#cache,\n\t\t\t\t\t\tparent: this\n\t\t\t\t\t});\n\n\t\t\t\t\tconst newValuizableObject: ValuizableMethod = newMetadataObject.value.bind(newMetadataObject);\n\n\t\t\t\t\tif (Array.isArray(newValue)) {\n\t\t\t\t\t\tthrow(new Error('internal error: newValue is an array, but it should be an object since it is an external field, which can only be an object'));\n\t\t\t\t\t}\n\t\t\t\t\tnewValue[key] = newValuizableObject;\n\t\t\t\t} else {\n\t\t\t\t\t/*\n\t\t\t\t\t * This is safe because `assertValuizableKind` will\n\t\t\t\t\t * ensure the correct output type\n\t\t\t\t\t */\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst newValueEntry: ValuizableMethod = async (expect: ValuizableKind = 'any') => {\n\t\t\t\t\t\tconst retval = this.assertValuizableKind(await this.valuize(keyValue), expect);\n\t\t\t\t\t\treturn(retval);\n\t\t\t\t\t};\n\n\t\t\t\t\t/*\n\t\t\t\t\t * TypeScript doesn't track that `key`\n\t\t\t\t\t * is a valid index regardless of the\n\t\t\t\t\t * type of `newValue` is an array or an\n\t\t\t\t\t * object, so we need to use `@ts-ignore`\n\t\t\t\t\t */\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewValue[key] = newValueEntry;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn(newValue);\n\t\t} else {\n\t\t\treturn(value);\n\t\t}\n\t}\n\n\tasync value(expect: 'object'): Promise<ValuizableObject>;\n\tasync value(expect: 'array'): Promise<ValuizableArray>;\n\tasync value(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n\tasync value(expect: 'string'): Promise<string>;\n\tasync value(expect: 'number'): Promise<number>;\n\tasync value(expect: 'boolean'): Promise<boolean>;\n\tasync value(expect: 'any'): Promise<ValuizeInput>;\n\tasync value(expect?: ValuizableKind): Promise<ValuizeInput>;\n\tasync value(expect: ValuizableKind = 'any'): Promise<ValuizeInput> {\n\t\tconst value = await this.readURL(this.#url);\n\n\t\tconst retval = this.assertValuizableKind(await this.valuize(value), expect);\n\n\t\treturn(retval);\n\t}\n}\n\n\ntype ResolverStats = {\n\tkeetanet: {\n\t\treads: number;\n\t};\n\thttps: {\n\t\treads: number;\n\t};\n\tunsupported: {\n\t\treads: number;\n\t};\n\treads: number;\n\tcache: {\n\t\thit: number;\n\t\tmiss: number;\n\t}\n};\n\nfunction assertValidCountryCodes(input: unknown): asserts input is { countryCodes: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['countryCodes'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('countryCodes' in input)) {\n\t\tthrow(new Error('Expected \"countryCodes\" to be present, but it was not found'));\n\t}\n\n\tif (typeof input.countryCodes !== 'function' && !Array.isArray(input.countryCodes)) {\n\t\tthrow(new Error(`Expected \"countryCodes\" to be an array | function, got ${typeof input.countryCodes}`));\n\t}\n\n\tif (Array.isArray(input.countryCodes)) {\n\t\tfor (const countryCode of input.countryCodes) {\n\t\t\tif (typeof countryCode !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"countryCodes\" to be an array of strings, got ${typeof countryCode}`));\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidOptionalCountryCodes(input: unknown): asserts input is { countryCodes?: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['countryCodes'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('countryCodes' in input)) {\n\t\treturn;\n\t}\n\n\tassertValidCountryCodes(input);\n}\n\nfunction assertValidCurrencyCodes(input: unknown): asserts input is { currencyCodes: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['currencyCodes'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('currencyCodes' in input)) {\n\t\tthrow(new Error('Expected \"currencyCodes\" to be present, but it was not found'));\n\t}\n\n\tif (typeof input.currencyCodes !== 'function' && !Array.isArray(input.currencyCodes)) {\n\t\tthrow(new Error(`Expected \"currencyCodes\" to be an array | function, got ${typeof input.currencyCodes}`));\n\t}\n\n\tif (Array.isArray(input.currencyCodes)) {\n\t\tfor (const currencyCode of input.currencyCodes) {\n\t\t\tif (typeof currencyCode !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"currencyCodes\" to be an array of strings, got ${typeof currencyCode}`));\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidOperationsBanking(input: unknown): asserts input is { operations: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['operations'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('operations' in input)) {\n\t\tthrow(new Error('Expected \"operations\" key in KYC service, but it was not found'));\n\t}\n\n\tif ((typeof input.operations !== 'object' || input.operations === null) && typeof input.operations !== 'function') {\n\t\tthrow(new Error(`Expected \"operations\" to be an object | function, got ${typeof input.operations}`));\n\t}\n\n\tif (typeof input.operations !== 'function') {\n\t\tfor (const [operation, operationValue] of Object.entries(input.operations)) {\n\t\t\tif (typeof operation !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"operations\" to be an object with string keys, got ${typeof operation}`));\n\t\t\t}\n\n\t\t\tif (typeof operationValue !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"operations.${operation}\" to be a string, got ${typeof operationValue}`));\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidOperationsKYC(input: unknown): asserts input is { operations: ToValuizableObject<NonNullable<ServiceMetadata['services']['kyc']>[string]>['operations'] } {\n\tassertValidOperationsBanking(input);\n}\n\nfunction assertValidOptionalKYCProviders(input: unknown): asserts input is { kycProviders?: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['kycProviders'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif ('kycProviders' in input) {\n\t\tif (typeof input.kycProviders !== 'function' && !Array.isArray(input.kycProviders)) {\n\t\t\tthrow(new Error(`Expected \"kycProviders\" to be an array | function, got ${typeof input.kycProviders}`));\n\t\t}\n\n\t\tif (Array.isArray(input.kycProviders)) {\n\t\t\tfor (const kycProvider of input.kycProviders) {\n\t\t\t\tif (typeof kycProvider !== 'string') {\n\t\t\t\t\tthrow(new Error(`Expected \"kycProviders\" to be an array of strings, got ${typeof kycProvider}`));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidCA(input: unknown): asserts input is { ca: ToValuizableObject<NonNullable<ServiceMetadata['services']['kyc']>[string]>['ca'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('ca' in input)) {\n\t\tthrow(new Error('Expected \"ca\" key in KYC service, but it was not found'));\n\t}\n\n\tif (typeof input.ca !== 'string' && typeof input.ca !== 'function') {\n\t\tthrow(new Error(`Expected \"ca\" to be a string | function, got ${typeof input.ca}`));\n\t}\n}\n\ntype ResolverLookupBankingResults = { [id: string]: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]> };\ntype ResolverLookupKYCResults = { [id: string]: ToValuizableObject<NonNullable<ServiceMetadata['services']['kyc']>[string]> };\nconst assertResolverLookupBankingResult = function(input: unknown): ResolverLookupBankingResults[string] {\n\tassertValidOperationsBanking(input);\n\tassertValidCountryCodes(input);\n\tassertValidCurrencyCodes(input);\n\tassertValidOptionalKYCProviders(input);\n\n\treturn(input);\n\n};\nconst assertResolverLookupKYCResult = function(input: unknown): ResolverLookupKYCResults[string] {\n\tassertValidOperationsKYC(input);\n\tassertValidOptionalCountryCodes(input);\n\tassertValidCA(input);\n\n\treturn(input);\n};\n\nclass Resolver {\n\treadonly #root: ResolverConfig['root'];\n\treadonly #trustedCAs: ResolverConfig['trustedCAs'];\n\treadonly #client: KeetaNetClient.Client;\n\treadonly #logger: Logger | undefined;\n\treadonly #stats: ResolverStats;\n\treadonly #metadataCache: NonNullable<MetadataConfig['cache']>;\n\n\treadonly id: string;\n\n\tstatic readonly Metadata: typeof Metadata = Metadata;\n\n\tconstructor(config: ResolverConfig) {\n\t\tthis.#root = config.root;\n\t\tthis.#trustedCAs = config.trustedCAs;\n\t\tthis.#logger = config.logger;\n\t\tthis.#metadataCache = {\n\t\t\t...config.cache,\n\t\t\tinstance: new Map()\n\t\t};\n\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Creating resolver with root account', this.#root.publicKeyString.get());\n\n\t\tif (KeetaNetClient.Client.isInstance(config.client)) {\n\t\t\tthis.#client = config.client;\n\t\t} else {\n\t\t\tthis.#client = config.client.client;\n\t\t}\n\n\t\tthis.#stats = {\n\t\t\tkeetanet: {\n\t\t\t\treads: 0\n\t\t\t},\n\t\t\thttps: {\n\t\t\t\treads: 0\n\t\t\t},\n\t\t\tunsupported: {\n\t\t\t\treads: 0\n\t\t\t},\n\t\t\treads: 0,\n\t\t\tcache: {\n\t\t\t\thit: 0,\n\t\t\t\tmiss: 0\n\t\t\t}\n\t\t};\n\t}\n\n\t/** @internal */\n\t_mutableStats(accessToken: symbol) {\n\t\tif (accessToken !== statsAccessToken) {\n\t\t\tthrow(new Error('Invalid access token'));\n\t\t}\n\n\t\treturn(this.#stats);\n\t}\n\n\tget stats(): ResolverStats {\n\t\treturn(structuredClone(this.#stats));\n\t}\n\n\tprivate async lookupBankingServices(bankingServices: ValuizableObject | undefined, criteria: ServiceSearchCriteria<'banking'>) {\n\t\tif (bankingServices === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst retval: ResolverLookupBankingResults = {};\n\t\tfor (const checkBankingServiceID in bankingServices) {\n\t\t\ttry {\n\t\t\t\tconst checkBankingService = await bankingServices[checkBankingServiceID]?.('object');\n\t\t\t\tif (checkBankingService === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!('operations' in checkBankingService)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (criteria.currencyCodes !== undefined) {\n\t\t\t\t\tconst currencyCodes = await checkBankingService.currencyCodes?.('array') ?? [];\n\t\t\t\t\tconst checkBankingServiceCurrencyCodes = await Promise.all(currencyCodes.map(async function(item) {\n\t\t\t\t\t\treturn(await item?.('primitive'));\n\t\t\t\t\t}));\n\n\t\t\t\t\tlet acceptable = true;\n\t\t\t\t\tfor (const checkCurrencyCode of criteria.currencyCodes) {\n\t\t\t\t\t\tconst checkCurrencyCodeCanonical = convertToCurrencySearchCanonical(checkCurrencyCode);\n\t\t\t\t\t\tif (!checkBankingServiceCurrencyCodes.includes(checkCurrencyCodeCanonical)) {\n\t\t\t\t\t\t\tacceptable = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!acceptable) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (criteria.countryCodes !== undefined) {\n\t\t\t\t\tconst countryCodes = await checkBankingService.countryCodes?.('array') ?? [];\n\t\t\t\t\tconst checkBankingServiceCountryCodes = await Promise.all(countryCodes.map(async function(item) {\n\t\t\t\t\t\treturn(await item?.('primitive'));\n\t\t\t\t\t}));\n\t\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Checking country codes:', criteria.countryCodes, 'against', checkBankingServiceCountryCodes, 'for', checkBankingServiceID);\n\n\t\t\t\t\tlet acceptable = true;\n\t\t\t\t\tfor (const checkCountryCode of criteria.countryCodes) {\n\t\t\t\t\t\tconst checkCountryCodeCanonical = convertToCountrySearchCanonical(checkCountryCode);\n\t\t\t\t\t\tif (!checkBankingServiceCountryCodes.includes(checkCountryCodeCanonical)) {\n\t\t\t\t\t\t\tacceptable = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!acceptable) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tretval[checkBankingServiceID] = assertResolverLookupBankingResult(checkBankingService);\n\t\t\t} catch (checkBankingServiceError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Error checking banking service', checkBankingServiceID, ':', checkBankingServiceError, ' -- ignoring');\n\t\t\t}\n\t\t}\n\n\t\tif (Object.keys(retval).length === 0) {\n\t\t\t/*\n\t\t\t * If we didn't find any banking services, then we return\n\t\t\t * undefined to indicate that no services were found.\n\t\t\t */\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tprivate async lookupKYCServices(kycServices: ValuizableObject | undefined, criteria: ServiceSearchCriteria<'kyc'>) {\n\t\tif (kycServices === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst retval: ResolverLookupKYCResults = {};\n\t\tfor (const checkKYCServiceID in kycServices) {\n\t\t\ttry {\n\t\t\t\tconst checkKYCService = await kycServices[checkKYCServiceID]?.('object');\n\t\t\t\tif (checkKYCService === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!('operations' in checkKYCService)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (criteria.countryCodes !== undefined) {\n\t\t\t\t\tlet acceptable = true;\n\t\t\t\t\t/*\n\t\t\t\t\t * If the KYC service does not have a countryCodes\n\t\t\t\t\t * property, then it can validate accounts in any\n\t\t\t\t\t * country, so we skip this check.\n\t\t\t\t\t */\n\t\t\t\t\tif ('countryCodes' in checkKYCService) {\n\t\t\t\t\t\tconst countryCodes = await checkKYCService.countryCodes?.('array') ?? [];\n\t\t\t\t\t\tconst checkKYCServiceCountryCodes = await Promise.all(countryCodes.map(async function(item) {\n\t\t\t\t\t\t\treturn(await item?.('string'));\n\t\t\t\t\t\t}));\n\t\t\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Checking country codes:', criteria.countryCodes, 'against', checkKYCServiceCountryCodes, 'for', checkKYCServiceID);\n\n\t\t\t\t\t\tfor (const checkCountryCode of criteria.countryCodes) {\n\t\t\t\t\t\t\tconst checkCountryCodeCanonical = convertToCountrySearchCanonical(checkCountryCode);\n\t\t\t\t\t\t\tif (!checkKYCServiceCountryCodes.includes(checkCountryCodeCanonical)) {\n\t\t\t\t\t\t\t\tacceptable = false;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!acceptable) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tretval[checkKYCServiceID] = assertResolverLookupKYCResult(checkKYCService);\n\t\t\t} catch (checkKYCServiceError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Error checking KYC service', checkKYCServiceID, ':', checkKYCServiceError, ' -- ignoring');\n\t\t\t}\n\t\t}\n\n\t\tif (Object.keys(retval).length === 0) {\n\t\t\t/*\n\t\t\t * If we didn't find any banking services, then we return\n\t\t\t * undefined to indicate that no services were found.\n\t\t\t */\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync lookup<T extends 'banking'>(service: T, criteria: ServiceSearchCriteria<'banking'>): Promise<ResolverLookupBankingResults | undefined>;\n\tasync lookup<T extends 'kyc'>(service: T, criteria: ServiceSearchCriteria<'kyc'>): Promise<ResolverLookupKYCResults | undefined>;\n\tasync lookup<T extends Services>(service: T, criteria: ServiceSearchCriteria<T>): Promise<ResolverLookupBankingResults | ResolverLookupKYCResults | undefined>;\n\tasync lookup<T extends Services>(service: T, criteria: ServiceSearchCriteria<T>): Promise<ResolverLookupBankingResults | ResolverLookupKYCResults | undefined> {\n\t\tconst rootURL = new URL(`keetanet://${this.#root.publicKeyString.get()}/metadata`);\n\t\tconst metadata = new Metadata(rootURL, {\n\t\t\ttrustedCAs: this.#trustedCAs,\n\t\t\tclient: this.#client,\n\t\t\tlogger: this.#logger,\n\t\t\tresolver: this,\n\t\t\tcache: this.#metadataCache\n\t\t});\n\t\tconst rootMetadata = await metadata.value('object');\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Root Metadata:', rootMetadata);\n\n\t\tif (!('version' in rootMetadata)) {\n\t\t\tthrow(new Error('Root metadata is missing \"version\" property'));\n\t\t}\n\n\t\tconst rootMetadataVersion = await rootMetadata.version?.('primitive');\n\t\tif (rootMetadataVersion !== 1) {\n\t\t\tthrow(new Error(`Unsupported metadata version: ${rootMetadataVersion}`));\n\t\t}\n\n\t\t/*\n\t\t * Get the services object\n\t\t */\n\t\tconst definedServicesProperty = rootMetadata.services;\n\t\tif (definedServicesProperty === undefined) {\n\t\t\tthrow(new Error('Root metadata is missing \"services\" property'));\n\t\t}\n\t\tconst definedServices = await definedServicesProperty('object');\n\n\t\t/*\n\t\t * We need to create a link between the service type and the\n\t\t * search criteria type, so we can use the correct type\n\t\t * for the criteria -- to do that we create an object\n\t\t * that links them together.\n\t\t */\n\t\ttype LookupArgs = {\n\t\t\t[S in Services]: { service: S; criteria: ServiceSearchCriteria<S> }\n\t\t}[Services];\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst args = { service, criteria } as LookupArgs;\n\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Looking up', args.service, 'with criteria:', args.criteria, 'in', definedServices);\n\t\tswitch (args.service) {\n\t\t\tcase 'banking': {\n\t\t\t\tconst currentCriteria = args.criteria;\n\t\t\t\tconst bankingServices = await definedServices.banking?.('object');\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Banking Services:', bankingServices);\n\n\t\t\t\treturn(await this.lookupBankingServices(bankingServices, currentCriteria));\n\t\t\t}\n\t\t\tcase 'kyc': {\n\t\t\t\tconst currentCriteria = args.criteria;\n\t\t\t\tconst kycServices = await definedServices.kyc?.('object');\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'KYC Services:', kycServices);\n\n\t\t\t\treturn(await this.lookupKYCServices(kycServices, currentCriteria));\n\t\t\t}\n\t\t\tcase 'fx':\n\t\t\tcase 'inbound':\n\t\t\tcase 'outbound':\n\t\t\tcase 'cards':\n\t\t\t\tthrow(new Error('not implemented'));\n\t\t\tdefault:\n\t\t\t\tassertNever(args);\n\t\t}\n\t}\n\n\tclearCache(): void {\n\t\tthis.#metadataCache.instance.clear();\n\t\tthis.#stats.cache.hit = 0;\n\t\tthis.#stats.cache.miss = 0;\n\t\tthis.#stats.https.reads = 0;\n\t\tthis.#stats.keetanet.reads = 0;\n\t\tthis.#stats.unsupported.reads = 0;\n\t\tthis.#stats.reads = 0;\n\t}\n}\n\nexport default Resolver;\nexport type {\n\tServiceMetadata,\n\tServiceSearchCriteria,\n\tServices\n};\n"]}
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/lib/resolver.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK/C,MAAM,eAAe,GAAsC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;AAkBtF,MAAM,yBAAyB,40CAAsC,CAAC;AA8NtE,SAAS,uBAAuB,CAAC,KAAc;IAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjD,MAAK,CAAC,IAAI,KAAK,CAAC,2BAA2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MAAM,CAAC;QACrD,oJAAoJ;QACpJ,OAAM,CAAC,MAAM,aAAa,CAAC,MAAM,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAe,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,UAAU;QACT,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;IACvB,CAAC;;AAGF,eAAe,QAAQ,CAAC","sourcesContent":["import * as KeetaNetClient from '@keetanetwork/keetanet-client';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\nimport type { Logger } from './log/index.ts';\nimport type { JSONSerializable } from './utils/json.ts';\nimport { assertNever } from './utils/never.js';\nimport { Buffer } from './utils/buffer.js';\nimport crypto from './utils/crypto.js';\n\nimport { createIs, createAssert } from 'typia';\n\ntype ExternalURL = { external: '2b828e33-2692-46e9-817e-9b93d63f28fd'; url: string; };\n\ntype KeetaNetAccount = InstanceType<typeof KeetaNetClient.lib.Account>;\nconst KeetaNetAccount: typeof KeetaNetClient.lib.Account = KeetaNetClient.lib.Account;\ntype KeetaNetAccountTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNetClient.lib.Account<typeof KeetaNetAccount.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;\n\n/**\n * Canonical form of a currency code for use in the ServiceMetadata\n * Which is either the ISO currency code (e.g. \"USD\", \"EUR\", \"JPY\")\n * or a cryptocurrency code prefixed with a dollar sign (e.g. \"$BTC\", \"$ETH\")\n */\ntype ServiceMetadataCurrencyCodeCanonical = CurrencyInfo.ISOCurrencyCode | `$${string}`;\n/**\n * Input types which can be used to search for which token represents\n * a given currency or cryptocurrency.\n */\ntype CurrencySearchInput = ServiceMetadataCurrencyCodeCanonical | CurrencyInfo.ISOCurrencyNumber | CurrencyInfo.Currency;\ntype CurrencySearchCanonical = ServiceMetadataCurrencyCodeCanonical;\ntype CountrySearchInput = CurrencyInfo.ISOCountryCode | CurrencyInfo.ISOCountryNumber | CurrencyInfo.Country;\ntype CountrySearchCanonical = CurrencyInfo.ISOCountryCode; /* XXX:TODO */\n\nconst isCurrencySearchCanonical = createIs<CurrencySearchCanonical>();\n\n// #region Global Service Metadata\n/**\n * Service Metadata General Structure\n */\ntype ServiceMetadata = {\n\tversion: number;\n\t/**\n\t * Map of the currency code to the token public key which\n\t * represents that currency.\n\t */\n\tcurrencyMap: {\n\t\t[currencyCode in ServiceMetadataCurrencyCodeCanonical]?: KeetaNetAccountTokenPublicKeyString;\n\t};\n\tservices: {\n\t\tbanking?: {\n\t\t\t[id: string]: {\n\t\t\t\toperations: {\n\t\t\t\t\tcreateAccount?: string;\n\t\t\t\t};\n\t\t\t\tcurrencyCodes: string[];\n\t\t\t\tcountryCodes: string[];\n\t\t\t\tkycProviders?: string[];\n\t\t\t};\n\t\t};\n\t\tkyc?: {\n\t\t\t[id: string]: {\n\t\t\t\toperations: {\n\t\t\t\t\t/**\n\t\t\t\t\t * Check if the KYC provider can\n\t\t\t\t\t * service a more specific locality\n\t\t\t\t\t * (optional)\n\t\t\t\t\t */\n\t\t\t\t\tcheckLocality?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Request an estimate for a KYC\n\t\t\t\t\t * verification (optional)\n\t\t\t\t\t */\n\t\t\t\t\tgetEstimate?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Begin the KYC verification process\n\t\t\t\t\t * with this KYC provider\n\t\t\t\t\t */\n\t\t\t\t\tcreateVerification?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Get the certificate for the\n\t\t\t\t\t * KYC verification\n\t\t\t\t\t */\n\t\t\t\t\tgetCertificates?: string;\n\t\t\t\t};\n\t\t\t\t/**\n\t\t\t\t * Country codes which this KYC provider can\n\t\t\t\t * validate accounts in. If this is not\n\t\t\t\t * specified, then the KYC provider can\n\t\t\t\t * validate accounts in any country.\n\t\t\t\t */\n\t\t\t\tcountryCodes?: string[];\n\t\t\t\t/**\n\t\t\t\t * The Certificate Authority (CA) Certificate\n\t\t\t\t * that this KYC provider uses to sign KYC\n\t\t\t\t * certificates. This is used to identify the\n\t\t\t\t * KYC provider.\n\t\t\t\t */\n\t\t\t\tca: string;\n\t\t\t};\n\t\t};\n\t\t/**\n\t\t * Foreign Exchange (FX) services\n\t\t *\n\t\t * This is used to identify service providers which\n\t\t * can convert currency from one currency to another.\n\t\t */\n\t\tfx?: {\n\t\t\t/**\n\t\t\t * Provider ID which identifies the FX provider\n\t\t\t */\n\t\t\t[id: string]: {\n\t\t\t\toperations: {\n\t\t\t\t\t/**\n\t\t\t\t\t * Get an estimate for a currency\n\t\t\t\t\t * conversion (optional)\n\t\t\t\t\t */\n\t\t\t\t\tgetEstimate?: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Get a quote for a currency\n\t\t\t\t\t * conversion\n\t\t\t\t\t */\n\t\t\t\t\tgetQuote: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Create an exchange to convert\n\t\t\t\t\t * currency\n\t\t\t\t\t */\n\t\t\t\t\tcreateExchange: string;\n\t\t\t\t\t/**\n\t\t\t\t\t * Get the status of an exchange\n\t\t\t\t\t * which was previously created\n\t\t\t\t\t */\n\t\t\t\t\tgetExchangeStatus: string;\n\t\t\t\t};\n\t\t\t\t/**\n\t\t\t\t * Path for which can be used to identify which\n\t\t\t\t * currencies this FX provider can convert\n\t\t\t\t * between.\n\t\t\t\t */\n\t\t\t\tfrom: {\n\t\t\t\t\t/**\n\t\t\t\t\t * Currency code which this FX provider can\n\t\t\t\t\t * convert from\n\t\t\t\t\t */\n\t\t\t\t\tcurrencyCodes: KeetaNetAccountTokenPublicKeyString[];\n\t\t\t\t\t/**\n\t\t\t\t\t * Currency codes which this FX provider can\n\t\t\t\t\t * convert to from the `from.currencyCode`\n\t\t\t\t\t */\n\t\t\t\t\tto: KeetaNetAccountTokenPublicKeyString[];\n\t\t\t\t\t/**\n\t\t\t\t\t * KYC providers which this FX provider\n\t\t\t\t\t * supports (DN) -- if not specified,\n\t\t\t\t\t * then it does not require KYC.\n\t\t\t\t\t */\n\t\t\t\t\tkycProviders?: string[];\n\t\t\t\t}[];\n\t\t\t}\n\t\t};\n\t\tinbound?: {\n\t\t\t[id: string]: {\n\t\t\t\t/* XXX:TODO */\n\t\t\t\tworkInProgress?: true;\n\t\t\t};\n\t\t};\n\t\toutbound?: {\n\t\t\t[id: string]: {\n\t\t\t\t/* XXX:TODO */\n\t\t\t\tworkInProgress?: true;\n\t\t\t};\n\t\t};\n\t\tcards?: {\n\t\t\t[id: string]: {\n\t\t\t\t/* XXX:TODO */\n\t\t\t\tworkInProgress?: true;\n\t\t\t};\n\t\t};\n\t};\n};\n\ntype ServiceMetadataExternalizable = ToJSONValuizable<ServiceMetadata>;\n\n/**\n * Types of services which can be resolved\n */\ntype Services = keyof ServiceMetadata['services'];\n\n/**\n * Search criteria for each service type\n */\ntype ServiceSearchCriteria<T extends Services> = {\n\t'banking': {\n\t\t/**\n\t\t * Search for a banking provider which supports creating\n\t\t * accounts in ALL of the following currencies.\n\t\t */\n\t\tcurrencyCodes?: CurrencySearchInput[];\n\t\t/**\n\t\t * Search for a banking provider which supports creating\n\t\t * accounts in ANY of the following countries.\n\t\t */\n\t\tcountryCodes?: CountrySearchInput[];\n\t\t/**\n\t\t * Search for a banking provider which supports creating\n\t\t * accounts verified by ANY of the following KYC providers\n\t\t * (DN).\n\t\t */\n\t\tkycProviders?: string[]; /* XXX:TODO */\n\t};\n\t'fx': {\n\t\t/**\n\t\t * Search for a provider which can convert from the following\n\t\t * input currency\n\t\t */\n\t\tinputCurrencyCode?: CurrencySearchInput | KeetaNetAccountTokenPublicKeyString;\n\t\t/**\n\t\t * Search for a provider which can convert to the following\n\t\t * output currency\n\t\t */\n\t\toutputCurrencyCode?: CurrencySearchInput | KeetaNetAccountTokenPublicKeyString;\n\t\t/**\n\t\t * Search for a provider which supports ANY of the following\n\t\t * KYC providers\n\t\t */\n\t\tkycProviders?: string[];\n\t};\n\t'kyc': {\n\t\t/**\n\t\t * Search for a KYC provider which can verify accounts in ALL\n\t\t * of the following countries.\n\t\t */\n\t\tcountryCodes: CountrySearchInput[];\n\t};\n\t'inbound': {\n\t\t/* XXX:TODO */\n\t\tworkInProgress: true;\n\t};\n\t'outbound': {\n\t\t/* XXX:TODO */\n\t\tworkInProgress: true;\n\t};\n\t'cards': {\n\t\t/* XXX:TODO */\n\t\tworkInProgress: true;\n\t};\n}[T];\n\ntype ResolverLookupServiceResults<Service extends Services> = { [id: string]: ToValuizableObject<NonNullable<ServiceMetadata['services'][Service]>[string]> };\n\ntype ServicesMetadataLookupMap = {\n\t[Service in Services]: {\n\t\tcriteria: ServiceSearchCriteria<Service>;\n\t\tresults: ResolverLookupServiceResults<Service>;\n\t};\n};\n\nfunction assertValidCountryCodes(input: unknown): asserts input is { countryCodes: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['countryCodes'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('countryCodes' in input)) {\n\t\tthrow(new Error('Expected \"countryCodes\" to be present, but it was not found'));\n\t}\n\n\tif (typeof input.countryCodes !== 'function' && !Array.isArray(input.countryCodes)) {\n\t\tthrow(new Error(`Expected \"countryCodes\" to be an array | function, got ${typeof input.countryCodes}`));\n\t}\n\n\tif (Array.isArray(input.countryCodes)) {\n\t\tfor (const countryCode of input.countryCodes) {\n\t\t\tif (typeof countryCode !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"countryCodes\" to be an array of strings, got ${typeof countryCode}`));\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidOptionalCountryCodes(input: unknown): asserts input is { countryCodes?: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['countryCodes'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('countryCodes' in input)) {\n\t\treturn;\n\t}\n\n\tassertValidCountryCodes(input);\n}\n\nfunction assertValidCurrencyCodes(input: unknown): asserts input is { currencyCodes: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['currencyCodes'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('currencyCodes' in input)) {\n\t\tthrow(new Error('Expected \"currencyCodes\" to be present, but it was not found'));\n\t}\n\n\tif (typeof input.currencyCodes !== 'function' && !Array.isArray(input.currencyCodes)) {\n\t\tthrow(new Error(`Expected \"currencyCodes\" to be an array | function, got ${typeof input.currencyCodes}`));\n\t}\n\n\tif (Array.isArray(input.currencyCodes)) {\n\t\tfor (const currencyCode of input.currencyCodes) {\n\t\t\tif (typeof currencyCode !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"currencyCodes\" to be an array of strings, got ${typeof currencyCode}`));\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidOperationsBanking(input: unknown): asserts input is { operations: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['operations'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('operations' in input)) {\n\t\tthrow(new Error('Expected \"operations\" key in KYC service, but it was not found'));\n\t}\n\n\tif ((typeof input.operations !== 'object' || input.operations === null) && typeof input.operations !== 'function') {\n\t\tthrow(new Error(`Expected \"operations\" to be an object | function, got ${typeof input.operations}`));\n\t}\n\n\tif (typeof input.operations !== 'function') {\n\t\tfor (const [operation, operationValue] of Object.entries(input.operations)) {\n\t\t\tif (typeof operation !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"operations\" to be an object with string keys, got ${typeof operation}`));\n\t\t\t}\n\n\t\t\tif (typeof operationValue !== 'string') {\n\t\t\t\tthrow(new Error(`Expected \"operations.${operation}\" to be a string, got ${typeof operationValue}`));\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidOperationsKYC(input: unknown): asserts input is { operations: ToValuizableObject<NonNullable<ServiceMetadata['services']['kyc']>[string]>['operations'] } {\n\t/* XXX:TODO: Validate the specific operations */\n\tassertValidOperationsBanking(input);\n}\n\nfunction assertValidOperationsFX(input: unknown): asserts input is { operations: ToValuizableObject<NonNullable<ServiceMetadata['services']['fx']>[string]>['operations'] } {\n\t/* XXX:TODO: Validate the specific operations */\n\tassertValidOperationsBanking(input);\n}\n\nfunction assertValidOptionalKYCProviders(input: unknown): asserts input is { kycProviders?: ToValuizableObject<NonNullable<ServiceMetadata['services']['banking']>[string]>['kycProviders'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif ('kycProviders' in input) {\n\t\tif (typeof input.kycProviders !== 'function' && !Array.isArray(input.kycProviders)) {\n\t\t\tthrow(new Error(`Expected \"kycProviders\" to be an array | function, got ${typeof input.kycProviders}`));\n\t\t}\n\n\t\tif (Array.isArray(input.kycProviders)) {\n\t\t\tfor (const kycProvider of input.kycProviders) {\n\t\t\t\tif (typeof kycProvider !== 'string') {\n\t\t\t\t\tthrow(new Error(`Expected \"kycProviders\" to be an array of strings, got ${typeof kycProvider}`));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction assertValidCA(input: unknown): asserts input is { ca: ToValuizableObject<NonNullable<ServiceMetadata['services']['kyc']>[string]>['ca'] } {\n\tif (typeof input !== 'object' || input === null) {\n\t\tthrow(new Error(`Expected an object, got ${typeof input}`));\n\t}\n\n\tif (!('ca' in input)) {\n\t\tthrow(new Error('Expected \"ca\" key in KYC service, but it was not found'));\n\t}\n\n\tif (typeof input.ca !== 'string' && typeof input.ca !== 'function') {\n\t\tthrow(new Error(`Expected \"ca\" to be a string | function, got ${typeof input.ca}`));\n\t}\n}\n\nconst assertResolverLookupBankingResult = function(input: unknown): ResolverLookupServiceResults<'banking'>[string] {\n\tassertValidOperationsBanking(input);\n\tassertValidCountryCodes(input);\n\tassertValidCurrencyCodes(input);\n\tassertValidOptionalKYCProviders(input);\n\n\treturn(input);\n\n};\nconst assertResolverLookupKYCResult = function(input: unknown): ResolverLookupServiceResults<'kyc'>[string] {\n\tassertValidOperationsKYC(input);\n\tassertValidOptionalCountryCodes(input);\n\tassertValidCA(input);\n\n\treturn(input);\n};\n\nconst assertResolverLookupFXResult = async function(input: unknown): Promise<ResolverLookupServiceResults<'fx'>[string]> {\n\tassertValidOperationsFX(input);\n\n\tif (!('from' in input)) {\n\t\tthrow(new Error('Expected \"from\" key in FX service, but it was not found'));\n\t}\n\n\tconst fromUnrealized = input.from;\n\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\tif (!Metadata.isValuizable(fromUnrealized)) {\n\t\tthrow(new Error(`Expected \"from\" to be an Valuizable, got ${typeof fromUnrealized}`));\n\t}\n\n\t// XXX:TODO: Perform deeper validation of the \"from\" structure\n\tawait fromUnrealized('array');\n\n\t// XXX:TODO: Perform deeper validation of the \"from\" structure\n\t// @ts-ignore\n\treturn(input);\n};\n\n// #endregion\n\n// #region Validation\n\nasync function isValidOperations(input: unknown): Promise<{ operations: ValuizableMethod } | false> {\n\tif (typeof input !== 'object' || input === null) {\n\t\treturn(false);\n\t}\n\n\tif (!('operations' in input)) {\n\t\treturn(false);\n\t}\n\n\tconst operations = input.operations;\n\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\tif (!Metadata.isValuizable(operations)) {\n\t\treturn(false);\n\t}\n\n\treturn({\n\t\t...input,\n\t\toperations\n\t});\n}\n\nfunction convertToCurrencySearchCanonical(input: CurrencySearchInput): CurrencySearchCanonical {\n\tif (CurrencyInfo.Currency.isCurrencyCode(input)) {\n\t\treturn(input);\n\t} else if (CurrencyInfo.Currency.isISOCurrencyNumber(input)) {\n\t\tinput = new CurrencyInfo.Currency(input);\n\t\treturn(input.code);\n\t} else if (typeof input === 'string') {\n\t\treturn(input);\n\t} else if (input === null) {\n\t\tthrow(new Error('Invalid currency input: null'));\n\t} else if ('code' in input) {\n\t\treturn(input.code);\n\t} else {\n\t\tthrow(new Error(`Invalid currency input: ${input}`));\n\t}\n}\n\nasync function hasAllCurrencyCodes(input: unknown, criteria: { currencyCodes: CurrencySearchCanonical[] }): Promise<boolean> {\n\t// XXX:TODO: Avoid using exceptions for flow-control\n\tassertValidCurrencyCodes(input);\n\n\tconst currencyCodes = await input.currencyCodes?.('array') ?? [];\n\tconst inputCurrencyCodes = await Promise.all(currencyCodes.map(async function(item) {\n\t\treturn(await item?.('primitive'));\n\t}));\n\n\tfor (const checkCurrencyCode of criteria.currencyCodes) {\n\t\tconst checkCurrencyCodeCanonical = convertToCurrencySearchCanonical(checkCurrencyCode);\n\t\tif (!inputCurrencyCodes.includes(checkCurrencyCodeCanonical)) {\n\t\t\treturn(false);\n\t\t}\n\t}\n\n\treturn(true);\n}\n\nasync function hasAnyCountryCodes(input: unknown, criteria: { countryCodes: CountrySearchCanonical[] }): Promise<boolean> {\n\t// XXX:TODO: Avoid using exceptions for flow-control\n\tassertValidCountryCodes(input);\n\n\tconst countryCodes = await input.countryCodes?.('array') ?? [];\n\n\tfor (const countryCode of countryCodes) {\n\t\tconst countryCodeValue = await countryCode?.('primitive');\n\t\tif (countryCodeValue === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any\n\t\tif (criteria.countryCodes.includes(countryCodeValue as any)) {\n\t\t\treturn(true);\n\t\t}\n\t}\n\n\treturn(false);\n}\n\n// #endregion\n\nfunction convertToCountrySearchCanonical(input: CountrySearchInput): CountrySearchCanonical {\n\tif (CurrencyInfo.Country.isCountryCode(input)) {\n\t\treturn(input);\n\t} else if (CurrencyInfo.Country.isISOCountryNumber(input)) {\n\t\tinput = new CurrencyInfo.Country(input);\n\t}\n\n\treturn(input.code);\n}\n\n/**\n * Check if a value is an ExternalURL\n */\nconst isExternalURL = createIs<ExternalURL>();\n\ntype JSONSerializablePrimitive = Exclude<JSONSerializable, object>;\ntype ValuizeInput = JSONSerializablePrimitive | ValuizableObject | ValuizableArray;\ntype ValuizableArray = (ValuizableMethod | undefined)[];\ntype ValuizableObject = { [key: string]: ValuizableMethod | undefined };\n\ntype ValuizableKind = 'any' | 'object' | 'array' | 'primitive' | 'string' | 'number' | 'boolean';\ninterface ValuizableMethod {\n\t(expect: 'object'): Promise<ValuizableObject>;\n\t(expect: 'array'): Promise<ValuizableArray>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n\t(expect: 'string'): Promise<string>;\n\t(expect: 'number'): Promise<number>;\n\t(expect: 'boolean'): Promise<boolean>;\n\t(expect: 'any'): Promise<ValuizeInput>;\n\t(expect?: ValuizableKind): Promise<ValuizeInput>;\n};\n\ninterface ToValuizableExpectString {\n\t(expect: 'string'): Promise<string>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n};\ninterface ToValuizableExpectNumber {\n\t(expect: 'number'): Promise<number>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n};\ninterface ToValuizableExpectBoolean {\n\t(expect: 'boolean'): Promise<boolean>;\n\t(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n};\n/* eslint-disable @stylistic/indent */\ntype ToValuizableObject<T extends object> = {\n\t[K in keyof T]:\n\t\tT[K] extends string ? ToValuizableExpectString :\n\t\tT[K] extends number ? ToValuizableExpectNumber :\n\t\tT[K] extends boolean ? ToValuizableExpectBoolean :\n\t\tT[K] extends JSONSerializablePrimitive ?\n\t\t\t(expect: 'primitive') => Promise<JSONSerializablePrimitive> :\n\t\tT[K] extends unknown[] ?\n\t\t\t(expect: 'array') => Promise<ToValuizableObject<T[K]>> :\n\t\tT[K] extends object ?\n\t\t\t(expect: 'object') => Promise<ToValuizableObject<T[K]>> :\n\t\tT[K] extends (infer U | undefined) ?\n\t\t\tToValuizable<U> | undefined :\n\t\tnever;\n};\ntype ToValuizable<T> = ToValuizableObject<{ tmp: T }>['tmp'];\n\ntype ToJSONValuizableObject<T extends object> = {\n\t[K in keyof T]: (\n\t\tT[K] extends object ?\n\t\t\tToJSONValuizableObject<T[K]> :\n\t\tT[K] extends (object | undefined) ?\n\t\t\tToJSONValuizableObject<NonNullable<T[K]>> | undefined :\n\t\tT[K]\n\t) | ExternalURL;\n};\ntype ToJSONValuizable<T> = ToJSONValuizableObject<{ tmp: T }>['tmp'];\n\n/*\n * Access token to share with the Metadata object to allow it to\n * access the mutable stats object.\n */\nconst statsAccessToken = Symbol('statsAccessToken');\n\n/**\n * A cache object\n */\ntype URLCacheObject = Map<string, {\n\tpass: true;\n\tvalue: JSONSerializable;\n\texpires: Date;\n} | {\n\tpass: false;\n\terror: unknown;\n\texpires: Date;\n}>;\n\n\ntype ResolverConfig = {\n\t/**\n\t * The \"root\" account to use as the basis for all lookups. It should\n\t * contain the authoritative information for resolving in its\n\t * Metadata.\n\t */\n\troot: KeetaNetAccount;\n\t/**\n\t * A KeetaNet Client to access the network using.\n\t */\n\tclient: KeetaNetClient.Client | KeetaNetClient.UserClient;\n\t/**\n\t * A list of trusted Certificate Authorities to use when connecting to\n\t * external HTTPS services.\n\t */\n\ttrustedCAs: string[]; /* XXX:TODO */\n\t/**\n\t * Logger to use for debugging\n\t */\n\tlogger?: Logger;\n\t/**\n\t * ID for this instance of the resolver\n\t */\n\tid?: string;\n\t/**\n\t * Caching Parameters\n\t */\n\tcache?: Omit<NonNullable<MetadataConfig['cache']>, 'instance'>;\n}\n\n\ntype MetadataConfig = {\n\ttrustedCAs: ResolverConfig['trustedCAs'];\n\tclient: KeetaNetClient.Client;\n\tlogger?: ResolverConfig['logger'];\n\tresolver: Resolver;\n\tcache?: {\n\t\tinstance: URLCacheObject;\n\t\tpositiveTTL?: number;\n\t\tnegativeTTL?: number;\n\t};\n\tparent?: Metadata;\n};\n\ntype ValuizableInstance = { value: ValuizableMethod };\n\nconst assertServiceMetadata = createAssert<ToJSONValuizable<ServiceMetadata>>();\n\nclass Metadata implements ValuizableInstance {\n\treadonly #cache: Required<NonNullable<MetadataConfig['cache']>>;\n\treadonly #trustedCAs: ResolverConfig['trustedCAs'];\n\treadonly #client: KeetaNetClient.Client;\n\treadonly #logger: Logger | undefined;\n\treadonly #url: URL;\n\treadonly #resolver: Resolver;\n\treadonly #stats: ResolverStats;\n\tprivate readonly seenURLs: Set<string>;\n\n\tprivate static readonly instanceTypeID = 'Metadata:c85b3d67-9548-4042-9862-f6e6677690ac';\n\n\tstatic isInstance(value: unknown): value is Metadata {\n\t\tif (typeof value !== 'object' || value === null) {\n\t\t\treturn(false);\n\t\t}\n\t\tif (!('instanceID' in value)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(value.instanceID === Metadata.instanceTypeID);\n\t}\n\n\t/**\n\t * Format the supplied Metadata as appropriate to be included\n\t * within the Metadata field of a KeetaNet acccount to serve\n\t * as the Metadata for the Resolver.\n\t */\n\tstatic formatMetadata(metadata: ToJSONValuizable<ServiceMetadata>): string;\n\t// eslint-disable-next-line @typescript-eslint/unified-signatures\n\tstatic formatMetadata(metadata: JSONSerializable): string;\n\tstatic formatMetadata(metadata: JSONSerializable | ToJSONValuizable<ServiceMetadata>): string {\n\t\tconst metadataBytes = Buffer.from(JSON.stringify(metadata), 'utf-8');\n\t\tconst metadataCompressed = KeetaNetClient.lib.Utils.Buffer.ZlibDeflate(KeetaNetClient.lib.Utils.Helper.bufferToArrayBuffer(metadataBytes));\n\t\tconst metadataEncoded = Buffer.from(metadataCompressed).toString('base64');\n\n\t\treturn(metadataEncoded);\n\t}\n\n\t/**\n\t * Assert that the supplied value is a valid Metadata Root Object\n\t */\n\tstatic assertMetadata(value: unknown): asserts value is ToJSONValuizable<ServiceMetadata> {\n\t\tassertServiceMetadata(value);\n\t}\n\n\tstatic isValuizable(value: unknown): value is ValuizableMethod {\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\t// @ts-ignore\n\t\tif (!('instanceTypeID' in value)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (value.instanceTypeID === Metadata.instanceTypeID) {\n\t\t\treturn(true);\n\t\t}\n\n\t\tif (value.instanceTypeID === 'Anonymous:6e69d6db-9263-466d-9c96-4b92ced498bd') {\n\t\t\treturn(true);\n\t\t}\n\n\t\treturn(false);\n\t}\n\n\tconstructor(url: string | URL, config: MetadataConfig) {\n\t\t/*\n\t\t * Define an \"instanceTypeID\" as an unenumerable property to\n\t\t * ensure that we can identify this object as an instance of\n\t\t * Metadata, but we do not need to serialize it.\n\t\t */\n\t\tObject.defineProperty(this, 'instanceTypeID', {\n\t\t\tvalue: Metadata.instanceTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t\tthis.#url = new URL(url);\n\t\tthis.#cache = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tinstance: config.cache?.instance ?? new Map() satisfies URLCacheObject as URLCacheObject,\n\t\t\tpositiveTTL: config.cache?.positiveTTL ?? 60 * 1000,\n\t\t\tnegativeTTL: config.cache?.negativeTTL ?? 5 * 1000\n\t\t};\n\t\tthis.#trustedCAs = config.trustedCAs;\n\t\tthis.#client = config.client;\n\t\tthis.#logger = config.logger;\n\t\tthis.#resolver = config.resolver;\n\t\tthis.#stats = this.#resolver._mutableStats(statsAccessToken);\n\t\tif (config.parent !== undefined) {\n\t\t\tthis.seenURLs = config.parent.seenURLs;\n\t\t} else {\n\t\t\tthis.seenURLs = new Set();\n\t\t}\n\t}\n\n\t/**\n\t * @param metadata Metadata to parse -- base64 encoded string or ArrayBuffer\n\t */\n\tprivate async parseMetadata(metadata: string | ArrayBuffer): Promise<JSONSerializable> {\n\t\tif (typeof metadata === 'string') {\n\t\t\tmetadata = KeetaNetClient.lib.Utils.Helper.bufferToArrayBuffer(Buffer.from(metadata, 'base64'));\n\t\t}\n\n\t\t/*\n\t\t * Attempt to decompress the metadata. If it fails, then\n\t\t * assume it is not compressed.\n\t\t */\n\t\tlet metadataUncompressed: ArrayBuffer;\n\t\ttry {\n\t\t\tmetadataUncompressed = KeetaNetClient.lib.Utils.Buffer.ZlibInflate(metadata);\n\t\t} catch {\n\t\t\tmetadataUncompressed = metadata;\n\t\t}\n\n\t\tconst metadataBytes = Buffer.from(metadataUncompressed);\n\t\tconst metadataDecoded = metadataBytes.toString('utf-8');\n\n\t\t/*\n\t\t * JSON.parse() will always return a JSONSerializable,\n\t\t * and not `unknown`, so we can safely cast it.\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst retval = await this.resolveValue(JSON.parse(metadataDecoded) as JSONSerializable);\n\n\t\treturn(retval);\n\t}\n\n\tprivate async readKeetaNetURL(url: URL): Promise<JSONSerializable> {\n\t\tconst accountString = url.hostname;\n\t\tconst path = url.pathname;\n\n\t\tthis.#stats.keetanet.reads++;\n\n\t\tif (path !== '/metadata') {\n\t\t\tthrow(new Error(`Unsupported path: ${path}`));\n\t\t}\n\n\t\tlet account: KeetaNetAccount | string;\n\t\ttry {\n\t\t\taccount = KeetaNetClient.lib.Account.fromPublicKeyString(accountString);\n\t\t} catch {\n\t\t\treturn('');\n\t\t}\n\n\t\tconst accountInfo = await this.#client.getAccountInfo(account);\n\t\tconst metadata = accountInfo.info.metadata;\n\t\tif (metadata === '') {\n\t\t\treturn('');\n\t\t}\n\n\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Account info for', accountString, '=', accountInfo.info);\n\t\tconst retval = await this.parseMetadata(metadata);\n\t\treturn(retval);\n\t}\n\n\tprivate async readHTTPSURL(url: URL): Promise<JSONSerializable> {\n\t\tthis.#stats.https.reads++;\n\n\t\tconst results = await fetch(url.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tif (!results.ok) {\n\t\t\tthrow(new Error(`Error HTTP status ${results.status} ${results.statusText} for ${url.toString()}`));\n\t\t}\n\n\t\tif (results.status === 204) {\n\t\t\t/*\n\t\t\t * 204 No Content is a valid response, so we return an empty\n\t\t\t * object.\n\t\t\t */\n\t\t\treturn({});\n\t\t}\n\n\t\tif (results.status !== 200) {\n\t\t\tthrow(new Error(`Unexpected HTTP status ${results.status} for ${url.toString()}`));\n\t\t}\n\n\t\tconst metadata = await (await results.blob()).arrayBuffer();\n\n\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Read URL', url.toString(), ':', metadata);\n\n\t\tconst retval = await this.parseMetadata(metadata);\n\n\t\treturn(retval);\n\t}\n\n\tprivate async readURL(url: URL) {\n\t\tthis.#stats.reads++;\n\n\t\tconst cacheKey = url.toString();\n\t\t/*\n\t\t * To ensure any circular references are handled correctly, we\n\t\t * keep track of a chain of accessed URLs. If we see the same\n\t\t * URL twice, then we have a circular reference.\n\t\t */\n\t\tif (this.seenURLs.has(cacheKey)) {\n\t\t\treturn('');\n\t\t}\n\t\tthis.seenURLs.add(cacheKey);\n\n\t\t/*\n\t\t * Verify that the cache entry is still valid. If it is not,\n\t\t * then remove it from the cache.\n\t\t */\n\t\tlet cacheVal = this.#cache.instance.get(cacheKey);\n\n\t\tif (this.#cache.instance.has(cacheKey) && cacheVal !== undefined) {\n\t\t\tif (cacheVal.expires < new Date()) {\n\t\t\t\tthis.#cache.instance.delete(cacheKey);\n\t\t\t\tcacheVal = undefined;\n\t\t\t}\n\t\t}\n\n\t\tif (cacheVal !== undefined) {\n\t\t\tthis.#stats.cache.hit++;\n\n\t\t\tif (cacheVal.pass) {\n\t\t\t\treturn(cacheVal.value);\n\t\t\t} else {\n\t\t\t\tthrow(cacheVal.error);\n\t\t\t}\n\t\t}\n\n\t\tthis.#stats.cache.miss++;\n\n\t\tlet retval: JSONSerializable;\n\t\ttry {\n\t\t\tconst protocol = url.protocol;\n\t\t\tif (protocol === 'keetanet:') {\n\t\t\t\tretval = await this.readKeetaNetURL(url);\n\t\t\t} else if (protocol === 'https:') {\n\t\t\t\tretval = await this.readHTTPSURL(url);\n\t\t\t} else {\n\t\t\t\tthis.#stats.unsupported.reads++;\n\t\t\t\tthrow(new Error(`Unsupported protocol: ${protocol}`));\n\t\t\t}\n\t\t} catch (readError) {\n\t\t\tthis.#cache.instance.set(cacheKey, {\n\t\t\t\tpass: false,\n\t\t\t\terror: readError,\n\t\t\t\texpires: new Date(Date.now() + this.#cache.negativeTTL)\n\t\t\t});\n\n\t\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Read URL', url.toString(), 'failed:', readError);\n\t\t\tthrow(readError);\n\t\t}\n\n\t\tthis.#logger?.debug(`Resolver:${this.#resolver.id}`, 'Read URL', url.toString(), ':', retval);\n\n\t\tthis.#cache.instance.set(cacheKey, {\n\t\t\tpass: true,\n\t\t\tvalue: retval,\n\t\t\texpires: new Date(Date.now() + this.#cache.positiveTTL)\n\t\t});\n\n\t\treturn(retval);\n\t}\n\n\tprivate async resolveValue<T extends ExternalURL | undefined>(value: T): Promise<JSONSerializable>;\n\tprivate async resolveValue<T extends JSONSerializable | undefined>(value: T): Promise<T>;\n\tprivate async resolveValue<T extends JSONSerializable | ExternalURL | undefined>(value: T): Promise<T | JSONSerializable> {\n\t\tif (value === undefined) {\n\t\t\treturn(value);\n\t\t}\n\n\t\t/*\n\t\t * If the value passed in is a reference to an external URL, then\n\t\t * we need to read that URL (and continue to resolve it).\n\t\t */\n\t\tif (isExternalURL(value)) {\n\t\t\tconst url = new URL(value.url);\n\t\t\tconst retval = await this.readURL(url);\n\n\t\t\treturn(await this.resolveValue(retval));\n\t\t}\n\n\t\treturn(value);\n\t}\n\n\tprivate assertValuizableKind(input: ValuizeInput, expect: ValuizableKind) {\n\t\tswitch (expect) {\n\t\t\tcase 'any':\n\t\t\t\treturn(input);\n\t\t\tcase 'object':\n\t\t\t\tif (typeof input !== 'object') {\n\t\t\t\t\tthrow(new Error(`expected an object, got ${typeof input}`));\n\t\t\t\t}\n\n\t\t\t\tif (input === null) {\n\t\t\t\t\tthrow(new Error('expected an object, got null'));\n\t\t\t\t}\n\n\t\t\t\tif (Array.isArray(input)) {\n\t\t\t\t\tthrow(new Error('expected an object, got an array'));\n\t\t\t\t}\n\n\t\t\t\treturn(input);\n\t\t\tcase 'array':\n\t\t\t\tif (!Array.isArray(input)) {\n\t\t\t\t\tthrow(new Error(`expected an array, got ${typeof input}`));\n\t\t\t\t}\n\n\t\t\t\treturn(input);\n\t\t\tcase 'primitive':\n\t\t\t\tif ((typeof input === 'object' && input !== null) || input === undefined) {\n\t\t\t\t\tthrow(new Error(`expected a primitive, got ${typeof input}`));\n\t\t\t\t}\n\n\t\t\t\treturn(input);\n\t\t\tcase 'string':\n\t\t\tcase 'number':\n\t\t\tcase 'boolean':\n\t\t\t\tif (typeof input !== expect) {\n\t\t\t\t\tthrow(new Error(`expected a ${expect}, got ${typeof input}`));\n\t\t\t\t}\n\t\t\t\treturn(input);\n\t\t\tdefault:\n\t\t\t\tassertNever(expect);\n\t\t}\n\t}\n\n\tprivate async valuize(value: JSONSerializable): Promise<ValuizeInput> {\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tlet newValue: ValuizableObject | ValuizableArray;\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tnewValue = [];\n\t\t\t} else {\n\t\t\t\tnewValue = {};\n\t\t\t}\n\t\t\tfor (const key in value) {\n\t\t\t\t/*\n\t\t\t\t * Since `key` is the index of the array or\n\t\t\t\t * object, it is safe to use it to index\n\t\t\t\t * into the array or object.\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst keyValue: JSONSerializable = value[key];\n\n\t\t\t\tif (isExternalURL(keyValue)) {\n\t\t\t\t\tconst newMetadataObject = new Metadata(keyValue.url, {\n\t\t\t\t\t\ttrustedCAs: this.#trustedCAs,\n\t\t\t\t\t\tclient: this.#client,\n\t\t\t\t\t\tlogger: this.#logger,\n\t\t\t\t\t\tresolver: this.#resolver,\n\t\t\t\t\t\tcache: this.#cache,\n\t\t\t\t\t\tparent: this\n\t\t\t\t\t});\n\n\t\t\t\t\tconst newValuizableObject: ValuizableMethod = newMetadataObject.value.bind(newMetadataObject);\n\n\t\t\t\t\tif (Array.isArray(newValue)) {\n\t\t\t\t\t\tthrow(new Error('internal error: newValue is an array, but it should be an object since it is an external field, which can only be an object'));\n\t\t\t\t\t}\n\t\t\t\t\tnewValue[key] = newValuizableObject;\n\t\t\t\t} else {\n\t\t\t\t\t/*\n\t\t\t\t\t * This is safe because `assertValuizableKind` will\n\t\t\t\t\t * ensure the correct output type\n\t\t\t\t\t */\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst newValueEntry: ValuizableMethod = async (expect: ValuizableKind = 'any') => {\n\t\t\t\t\t\tconst retval = this.assertValuizableKind(await this.valuize(keyValue), expect);\n\t\t\t\t\t\treturn(retval);\n\t\t\t\t\t};\n\n\t\t\t\t\tObject.defineProperty(newValueEntry, 'instanceTypeID', {\n\t\t\t\t\t\tvalue: 'Anonymous:6e69d6db-9263-466d-9c96-4b92ced498bd',\n\t\t\t\t\t\tenumerable: false\n\t\t\t\t\t});\n\n\t\t\t\t\t/*\n\t\t\t\t\t * TypeScript doesn't track that `key`\n\t\t\t\t\t * is a valid index regardless of the\n\t\t\t\t\t * type of `newValue` is an array or an\n\t\t\t\t\t * object, so we need to use `@ts-ignore`\n\t\t\t\t\t */\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewValue[key] = newValueEntry;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn(newValue);\n\t\t} else {\n\t\t\treturn(value);\n\t\t}\n\t}\n\n\tasync value(expect: 'object'): Promise<ValuizableObject>;\n\tasync value(expect: 'array'): Promise<ValuizableArray>;\n\tasync value(expect: 'primitive'): Promise<JSONSerializablePrimitive>;\n\tasync value(expect: 'string'): Promise<string>;\n\tasync value(expect: 'number'): Promise<number>;\n\tasync value(expect: 'boolean'): Promise<boolean>;\n\tasync value(expect: 'any'): Promise<ValuizeInput>;\n\tasync value(expect?: ValuizableKind): Promise<ValuizeInput>;\n\tasync value(expect: ValuizableKind = 'any'): Promise<ValuizeInput> {\n\t\tconst value = await this.readURL(this.#url);\n\n\t\tconst retval = this.assertValuizableKind(await this.valuize(value), expect);\n\n\t\treturn(retval);\n\t}\n}\n\n\ntype ResolverStats = {\n\tkeetanet: {\n\t\treads: number;\n\t};\n\thttps: {\n\t\treads: number;\n\t};\n\tunsupported: {\n\t\treads: number;\n\t};\n\treads: number;\n\tcache: {\n\t\thit: number;\n\t\tmiss: number;\n\t}\n};\n\nclass Resolver {\n\treadonly #root: ResolverConfig['root'];\n\treadonly #trustedCAs: ResolverConfig['trustedCAs'];\n\treadonly #client: KeetaNetClient.Client;\n\treadonly #logger: Logger | undefined;\n\treadonly #stats: ResolverStats;\n\treadonly #metadataCache: NonNullable<MetadataConfig['cache']>;\n\n\treadonly id: string;\n\n\tstatic readonly Metadata: typeof Metadata = Metadata;\n\n\tprivate readonly lookupMap: {\n\t\t[Service in Services]: {\n\t\t\tsearch: (input: ValuizableObject | undefined, criteria: ServiceSearchCriteria<Service>) => Promise<ResolverLookupServiceResults<Service> | undefined>;\n\t\t};\n\t} = {\n\t\t'banking': {\n\t\t\tsearch: this.lookupBankingServices.bind(this)\n\t\t},\n\t\t'kyc': {\n\t\t\tsearch: this.lookupKYCServices.bind(this)\n\t\t},\n\t\t'fx': {\n\t\t\tsearch: this.lookupFXServices.bind(this)\n\t\t},\n\t\t'inbound': {\n\t\t\tsearch: async (_ignored_input: ValuizableObject | undefined, _ignored_criteria: ServiceSearchCriteria<'inbound'>) => {\n\t\t\t\tthrow(new Error('not implemented'));\n\t\t\t}\n\t\t},\n\t\t'outbound': {\n\t\t\tsearch: async (_ignored_input: ValuizableObject | undefined, _ignored_criteria: ServiceSearchCriteria<'outbound'>) => {\n\t\t\t\tthrow(new Error('not implemented'));\n\t\t\t}\n\t\t},\n\t\t'cards': {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tsearch: async (_input: ValuizableObject | undefined, _criteria: ServiceSearchCriteria<'cards'>) => {\n\t\t\t\tthrow(new Error('not implemented'));\n\t\t\t}\n\t\t}\n\t};\n\n\n\tconstructor(config: ResolverConfig) {\n\t\tthis.#root = config.root;\n\t\tthis.#trustedCAs = config.trustedCAs;\n\t\tthis.#logger = config.logger;\n\t\tthis.#metadataCache = {\n\t\t\t...config.cache,\n\t\t\tinstance: new Map()\n\t\t};\n\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Creating resolver with root account', this.#root.publicKeyString.get());\n\n\t\tif (KeetaNetClient.Client.isInstance(config.client)) {\n\t\t\tthis.#client = config.client;\n\t\t} else {\n\t\t\tthis.#client = config.client.client;\n\t\t}\n\n\t\tthis.#stats = {\n\t\t\tkeetanet: {\n\t\t\t\treads: 0\n\t\t\t},\n\t\t\thttps: {\n\t\t\t\treads: 0\n\t\t\t},\n\t\t\tunsupported: {\n\t\t\t\treads: 0\n\t\t\t},\n\t\t\treads: 0,\n\t\t\tcache: {\n\t\t\t\thit: 0,\n\t\t\t\tmiss: 0\n\t\t\t}\n\t\t};\n\t}\n\n\t/** @internal */\n\t_mutableStats(accessToken: symbol) {\n\t\tif (accessToken !== statsAccessToken) {\n\t\t\tthrow(new Error('Invalid access token'));\n\t\t}\n\n\t\treturn(this.#stats);\n\t}\n\n\tget stats(): ResolverStats {\n\t\treturn(structuredClone(this.#stats));\n\t}\n\n\tprivate async lookupBankingServices(bankingServices: ValuizableObject | undefined, criteria: ServiceSearchCriteria<'banking'>) {\n\t\tif (bankingServices === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tlet canonicalCurrencyCriteria;\n\t\tif ('currencyCodes' in criteria) {\n\t\t\tcanonicalCurrencyCriteria = {\n\t\t\t\tcurrencyCodes: criteria.currencyCodes.map(convertToCurrencySearchCanonical)\n\t\t\t}\n\t\t}\n\n\t\tlet canonicalCountryCriteria;\n\t\tif ('countryCodes' in criteria) {\n\t\t\tcanonicalCountryCriteria = {\n\t\t\t\tcountryCodes: criteria.countryCodes.map(convertToCountrySearchCanonical)\n\t\t\t}\n\t\t}\n\n\t\tconst retval: ResolverLookupServiceResults<'banking'> = {};\n\t\tfor (const checkBankingServiceID in bankingServices) {\n\t\t\ttry {\n\t\t\t\tconst checkBankingService = await isValidOperations(await bankingServices[checkBankingServiceID]?.('object'));\n\t\t\t\tif (!checkBankingService) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (canonicalCurrencyCriteria !== undefined && 'currencyCodes' in checkBankingService) {\n\t\t\t\t\tif (!(await hasAllCurrencyCodes(checkBankingService, canonicalCurrencyCriteria))) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (canonicalCountryCriteria !== undefined && 'countryCodes' in checkBankingService) {\n\t\t\t\t\tif (!(await hasAnyCountryCodes(checkBankingService, canonicalCountryCriteria))) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tretval[checkBankingServiceID] = assertResolverLookupBankingResult(checkBankingService);\n\t\t\t} catch (checkBankingServiceError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Error checking banking service', checkBankingServiceID, ':', checkBankingServiceError, ' -- ignoring');\n\t\t\t}\n\t\t}\n\n\t\tif (Object.keys(retval).length === 0) {\n\t\t\t/*\n\t\t\t * If we didn't find any banking services, then we return\n\t\t\t * undefined to indicate that no services were found.\n\t\t\t */\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tprivate async lookupKYCServices(kycServices: ValuizableObject | undefined, criteria: ServiceSearchCriteria<'kyc'>) {\n\t\tif (kycServices === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst retval: ResolverLookupServiceResults<'kyc'> = {};\n\t\tfor (const checkKYCServiceID in kycServices) {\n\t\t\ttry {\n\t\t\t\tconst checkKYCService = await kycServices[checkKYCServiceID]?.('object');\n\t\t\t\tif (checkKYCService === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!('operations' in checkKYCService)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (criteria.countryCodes !== undefined) {\n\t\t\t\t\tlet acceptable = true;\n\t\t\t\t\t/*\n\t\t\t\t\t * If the KYC service does not have a countryCodes\n\t\t\t\t\t * property, then it can validate accounts in any\n\t\t\t\t\t * country, so we skip this check.\n\t\t\t\t\t */\n\t\t\t\t\tif ('countryCodes' in checkKYCService) {\n\t\t\t\t\t\tconst countryCodes = await checkKYCService.countryCodes?.('array') ?? [];\n\t\t\t\t\t\tconst checkKYCServiceCountryCodes = await Promise.all(countryCodes.map(async function(item) {\n\t\t\t\t\t\t\treturn(await item?.('string'));\n\t\t\t\t\t\t}));\n\t\t\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Checking country codes:', criteria.countryCodes, 'against', checkKYCServiceCountryCodes, 'for', checkKYCServiceID);\n\n\t\t\t\t\t\tfor (const checkCountryCode of criteria.countryCodes) {\n\t\t\t\t\t\t\tconst checkCountryCodeCanonical = convertToCountrySearchCanonical(checkCountryCode);\n\t\t\t\t\t\t\tif (!checkKYCServiceCountryCodes.includes(checkCountryCodeCanonical)) {\n\t\t\t\t\t\t\t\tacceptable = false;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!acceptable) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tretval[checkKYCServiceID] = assertResolverLookupKYCResult(checkKYCService);\n\t\t\t} catch (checkKYCServiceError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Error checking KYC service', checkKYCServiceID, ':', checkKYCServiceError, ' -- ignoring');\n\t\t\t}\n\t\t}\n\n\t\tif (Object.keys(retval).length === 0) {\n\t\t\t/*\n\t\t\t * If we didn't find any banking services, then we return\n\t\t\t * undefined to indicate that no services were found.\n\t\t\t */\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tprivate async lookupFXServices(fxServices: ValuizableObject | undefined, criteria: ServiceSearchCriteria<'fx'>): Promise<ResolverLookupServiceResults<'fx'> | undefined> {\n\t\tif (fxServices === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst isCurrencySearchInput = createIs<CurrencySearchInput>();\n\t\t// if currency code is provided then convert to canonical format otherwise token public key string was provided\n\t\tconst canonicalInputCurrencyCriteria = isCurrencySearchInput(criteria.inputCurrencyCode) ? convertToCurrencySearchCanonical(criteria.inputCurrencyCode) : criteria.inputCurrencyCode;\n\t\tconst canonicalOutputCurrencyCriteria = isCurrencySearchInput(criteria.outputCurrencyCode) ? convertToCurrencySearchCanonical(criteria.outputCurrencyCode) : criteria.outputCurrencyCode;\n\t\t// if search criteria is not provided then set token to undefined\n\t\tconst inputToken = canonicalInputCurrencyCriteria !== undefined ? await this.lookupToken(canonicalInputCurrencyCriteria) : undefined;\n\t\tconst outputToken = canonicalOutputCurrencyCriteria !== undefined ? await this.lookupToken(canonicalOutputCurrencyCriteria) : undefined;\n\t\tif (criteria.inputCurrencyCode !== undefined && inputToken === null) {\n\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Input currency code', canonicalInputCurrencyCriteria, 'could not be resolved to a token');\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tif (criteria.outputCurrencyCode !== undefined && outputToken === null) {\n\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Output currency code', canonicalOutputCurrencyCriteria, 'could not be resolved to a token');\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst retval: ResolverLookupServiceResults<'fx'> = {};\n\t\tfor (const checkFXServiceID in fxServices) {\n\t\t\ttry {\n\t\t\t\tconst checkFXService = await assertResolverLookupFXResult(await fxServices[checkFXServiceID]?.('object'));\n\t\t\t\tif (!checkFXService) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst fromUnrealized: ToValuizable<NonNullable<ServiceMetadata['services']['fx']>[string]['from']> = checkFXService.from;\n\t\t\t\tconst from = await fromUnrealized?.('array');\n\t\t\t\tif (from === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet acceptable = false;\n\t\t\t\tfor (const fromEntryUnrealized of from) {\n\t\t\t\t\tconst fromEntry = await fromEntryUnrealized?.('object');\n\n\t\t\t\t\tif (inputToken) {\n\t\t\t\t\t\tconst fromCurrencyCodes = await fromEntry.currencyCodes?.('array') ?? [];\n\t\t\t\t\t\tconst fromCurrencyCodesValues = await Promise.all(fromCurrencyCodes.map(async function(item) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\treturn(await item?.('string'));\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\treturn(undefined);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}));\n\n\t\t\t\t\t\t// If inputToken was provided, check if it matches providers supported input currencies\n\t\t\t\t\t\tif (!fromCurrencyCodesValues.includes(inputToken.token)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (outputToken) {\n\t\t\t\t\t\tconst toCurrencyCodes = await fromEntry.to?.('array') ?? [];\n\t\t\t\t\t\tconst toCurrencyCodesValues = await Promise.all(toCurrencyCodes.map(async function(item) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\treturn(await item?.('string'));\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\treturn(undefined);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}));\n\n\t\t\t\t\t\t// If outputToken was provided, check if it matches providers supported output currencies\n\t\t\t\t\t\tif (!toCurrencyCodesValues.includes(outputToken.token)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t/* XXX:TODO: Check kycProviders */\n\t\t\t\t\tacceptable = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (!acceptable) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tretval[checkFXServiceID] = await assertResolverLookupFXResult(checkFXService);\n\t\t\t} catch (checkFXServiceError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Error checking FX service', checkFXServiceID, ':', checkFXServiceError, ' -- ignoring');\n\t\t\t}\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync #getRootMetadata() {\n\t\tconst rootURL = new URL(`keetanet://${this.#root.publicKeyString.get()}/metadata`);\n\t\tconst metadata = new Metadata(rootURL, {\n\t\t\ttrustedCAs: this.#trustedCAs,\n\t\t\tclient: this.#client,\n\t\t\tlogger: this.#logger,\n\t\t\tresolver: this,\n\t\t\tcache: this.#metadataCache\n\t\t});\n\t\tconst rootMetadata = await metadata.value('object');\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Root Metadata:', rootMetadata);\n\n\t\tif (!('version' in rootMetadata)) {\n\t\t\tthrow(new Error('Root metadata is missing \"version\" property'));\n\t\t}\n\n\t\tconst rootMetadataVersion = await rootMetadata.version?.('primitive');\n\t\tif (rootMetadataVersion !== 1) {\n\t\t\tthrow(new Error(`Unsupported metadata version: ${rootMetadataVersion}`));\n\t\t}\n\n\t\treturn(rootMetadata);\n\t}\n\n\tasync listTokens(): Promise<{ token: KeetaNetAccountTokenPublicKeyString; currency: CurrencySearchCanonical; }[]> {\n\t\tconst rootMetadata = await this.#getRootMetadata();\n\n\t\t/*\n\t\t * Get the services object\n\t\t */\n\t\tconst definedCurrenciesMapProperty = rootMetadata.currencyMap;\n\t\tif (definedCurrenciesMapProperty === undefined) {\n\t\t\tthrow(new Error('Root metadata is missing \"currencyMap\" property'));\n\t\t}\n\t\tconst definedCurrenciesMap = await definedCurrenciesMapProperty('object');\n\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Defined Currencies Map:', definedCurrenciesMap);\n\n\t\tconst retval: { token: KeetaNetAccountTokenPublicKeyString; currency: CurrencySearchCanonical; }[] = [];\n\t\tfor (const [checkCurrencyCode, checkTokenProperty] of Object.entries(definedCurrenciesMap)) {\n\t\t\tconst checkToken = await checkTokenProperty?.('string');\n\t\t\tif (checkToken === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!isCurrencySearchCanonical(checkCurrencyCode)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst checkTokenObject = KeetaNetAccount.fromPublicKeyString(checkToken);\n\t\t\t\tif (!checkTokenObject.isToken()) {\n\t\t\t\t\tthrow(new Error('Not a token account'));\n\t\t\t\t}\n\n\t\t\t\tretval.push({\n\t\t\t\t\ttoken: checkTokenObject.publicKeyString.get(),\n\t\t\t\t\tcurrency: checkCurrencyCode\n\t\t\t\t});\n\t\t\t} catch (validationError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Token public key for currency code', checkCurrencyCode, 'is invalid:', validationError);\n\t\t\t}\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync lookupToken(currencyCode: CurrencySearchInput | KeetaNetAccountTokenPublicKeyString): Promise<{ token: KeetaNetAccountTokenPublicKeyString; currency: CurrencySearchCanonical; } | null> {\n\t\tlet tokenPublicKey: KeetaNetAccountTokenPublicKeyString | undefined;\n\t\tif (typeof currencyCode === 'string') {\n\t\t\ttry {\n\t\t\t\tconst token = KeetaNetAccount.fromPublicKeyString(currencyCode);\n\t\t\t\tif (token.isToken()) {\n\t\t\t\t\ttokenPublicKey = token.publicKeyString.get();\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t/* Ignored */\n\t\t\t}\n\t\t}\n\n\t\tconst rootMetadata = await this.#getRootMetadata();\n\n\t\t/*\n\t\t * Get the services object\n\t\t */\n\t\tconst definedCurrenciesMapProperty = rootMetadata.currencyMap;\n\t\tif (definedCurrenciesMapProperty === undefined) {\n\t\t\tthrow(new Error('Root metadata is missing \"currencyMap\" property'));\n\t\t}\n\t\tconst definedCurrenciesMap = await definedCurrenciesMapProperty('object');\n\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Defined Currencies Map:', definedCurrenciesMap);\n\n\t\tlet currencyCodeFound: CurrencySearchCanonical | undefined;\n\t\tif (tokenPublicKey === undefined) {\n\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Performing forward lookup for currency code', currencyCode);\n\n\t\t\t/*\n\t\t\t * Perform a forward lookup from the currency code\n\t\t\t * to the token public key\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any\n\t\t\tconst currencyCodeCanonical = convertToCurrencySearchCanonical(currencyCode as unknown as any);\n\t\t\tif (currencyCodeCanonical === undefined) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst checkToken = await definedCurrenciesMap[currencyCodeCanonical]?.('string');\n\t\t\tif (checkToken === undefined) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Validating token public key for currency code', currencyCodeCanonical, ':', checkToken, typeof checkToken);\n\t\t\ttry {\n\t\t\t\tconst checkTokenObject = KeetaNetAccount.fromPublicKeyString(checkToken);\n\t\t\t\tif (!checkTokenObject.isToken()) {\n\t\t\t\t\tthrow(new Error('Not a token account'));\n\t\t\t\t}\n\n\t\t\t\ttokenPublicKey = checkTokenObject.publicKeyString.get();\n\t\t\t\tcurrencyCodeFound = currencyCodeCanonical;\n\t\t\t} catch (validationError) {\n\t\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Token public key for currency code', currencyCodeCanonical, 'is invalid:', validationError);\n\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Performing reverse lookup for token public key', tokenPublicKey);\n\n\t\t\t/*\n\t\t\t * Perform a reverse lookup from the token public key\n\t\t\t * to the currency code\n\t\t\t */\n\t\t\tfor (const [checkCurrencyCode, checkTokenProperty] of Object.entries(definedCurrenciesMap)) {\n\t\t\t\tconst checkToken = await checkTokenProperty?.('string');\n\t\t\t\tif (checkToken === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (checkToken === tokenPublicKey) {\n\t\t\t\t\tif (isCurrencySearchCanonical(checkCurrencyCode)) {\n\t\t\t\t\t\tcurrencyCodeFound = checkCurrencyCode;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currencyCodeFound === undefined) {\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}\n\n\t\treturn({\n\t\t\ttoken: tokenPublicKey,\n\t\t\tcurrency: currencyCodeFound\n\t\t});\n\t}\n\n\tasync lookup<T extends keyof ServicesMetadataLookupMap>(service: T, criteria: ServicesMetadataLookupMap[T]['criteria']): Promise<ServicesMetadataLookupMap[T]['results'] | undefined> {\n\t\tconst rootMetadata = await this.#getRootMetadata();\n\n\t\t/*\n\t\t * Get the services object\n\t\t */\n\t\tconst definedServicesProperty = rootMetadata.services;\n\t\tif (definedServicesProperty === undefined) {\n\t\t\tthrow(new Error('Root metadata is missing \"services\" property'));\n\t\t}\n\t\tconst definedServices = await definedServicesProperty('object');\n\n\t\tthis.#logger?.debug(`Resolver:${this.id}`, 'Looking up', service, 'with criteria:', criteria, 'in', definedServices);\n\n\t\tconst serviceLookup = this.lookupMap[service].search;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any\n\t\treturn(await serviceLookup(await definedServices[service]?.('object'), criteria as any));\n\t}\n\n\tclearCache(): void {\n\t\tthis.#metadataCache.instance.clear();\n\t\tthis.#stats.cache.hit = 0;\n\t\tthis.#stats.cache.miss = 0;\n\t\tthis.#stats.https.reads = 0;\n\t\tthis.#stats.keetanet.reads = 0;\n\t\tthis.#stats.unsupported.reads = 0;\n\t\tthis.#stats.reads = 0;\n\t}\n}\n\nexport default Resolver;\nexport type {\n\tServiceMetadata,\n\tServiceMetadataExternalizable,\n\tServiceSearchCriteria,\n\tServices\n};\n"]}
@@ -0,0 +1,12 @@
1
+ export type Brand<T, BrandName extends string> = T & {
2
+ readonly [B in BrandName as `__${B}_brand`]: never;
3
+ };
4
+ /**
5
+ * A branded string type. This is a string that is branded with a specific
6
+ * type, making it impossible to accidentally mix it with other strings.
7
+ *
8
+ * We pretend that `symbol` is a primitive type for the purposes of branding
9
+ * it, since it is unique and cannot be easily created by accident.
10
+ */
11
+ export type BrandedString<BrandName extends string> = Brand<symbol, BrandName>;
12
+ //# sourceMappingURL=brand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/brand.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,SAAS,SAAS,MAAM,IAAI,CAAC,GAAG;IACpD,QAAQ,EAAE,CAAC,IAAI,SAAS,IAAI,KAAK,CAAC,QAAQ,GAAG,KAAK;CAClD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,SAAS,SAAS,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=brand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand.js","sourceRoot":"","sources":["../../../src/lib/utils/brand.ts"],"names":[],"mappings":"","sourcesContent":["export type Brand<T, BrandName extends string> = T & {\n\treadonly [B in BrandName as `__${B}_brand`]: never;\n};\n\n/**\n * A branded string type. This is a string that is branded with a specific\n * type, making it impossible to accidentally mix it with other strings.\n *\n * We pretend that `symbol` is a primitive type for the purposes of branding\n * it, since it is unique and cannot be easily created by accident.\n */\nexport type BrandedString<BrandName extends string> = Brand<symbol, BrandName>;\n"]}
@@ -5,4 +5,8 @@
5
5
  * are handled.
6
6
  */
7
7
  export declare function assertNever(value: never): never;
8
+ /**
9
+ * Asserts that the provided type is never.
10
+ */
11
+ export type AssertNever<T extends never> = T;
8
12
  //# sourceMappingURL=never.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"never.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/never.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAO/C"}
1
+ {"version":3,"file":"never.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/never.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAO/C;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"never.js","sourceRoot":"","sources":["../../../src/lib/utils/never.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC;;;WAGU;IAEV,MAAK,CAAC,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/**\n * Asserts that the provided value is never.\n *\n * This is useful for static type checking to ensure that all possible values\n * are handled.\n */\nexport function assertNever(value: never): never {\n\t/**\n * If we got to this point, it means that the value is not never and\n * so can be logged\n */\n\n\tthrow(new Error(`Unexpected value: ${value}`));\n}\n"]}
1
+ {"version":3,"file":"never.js","sourceRoot":"","sources":["../../../src/lib/utils/never.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC;;;WAGU;IAEV,MAAK,CAAC,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/**\n * Asserts that the provided value is never.\n *\n * This is useful for static type checking to ensure that all possible values\n * are handled.\n */\nexport function assertNever(value: never): never {\n\t/**\n * If we got to this point, it means that the value is not never and\n * so can be logged\n */\n\n\tthrow(new Error(`Unexpected value: ${value}`));\n}\n\n/**\n * Asserts that the provided type is never.\n */\nexport type AssertNever<T extends never> = T;\n"]}
@@ -0,0 +1,17 @@
1
+ import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
+ import { Buffer } from '../../lib/utils/buffer.js';
3
+ export type SignableAccount = ReturnType<InstanceType<typeof KeetaNetLib.Account>['assertAccount']>;
4
+ export type VerifableAccount = InstanceType<typeof KeetaNetLib.Account>;
5
+ export type Signable = (string | number | bigint | InstanceType<typeof KeetaNetLib.Account>)[];
6
+ export declare function FormatData(account: VerifableAccount, data: Signable, nonce?: string, timestamp?: string | Date): {
7
+ nonce: string;
8
+ timestamp: string;
9
+ verificationData: Buffer;
10
+ };
11
+ export declare function SignData(account: SignableAccount, data: Signable): Promise<{
12
+ nonce: string;
13
+ timestamp: string;
14
+ signature: string;
15
+ }>;
16
+ export declare function VerifySignedData(account: VerifableAccount, data: Signable, signed: Awaited<ReturnType<typeof SignData>>): Promise<boolean>;
17
+ //# sourceMappingURL=signing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAMnE,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAInD,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;AACpG,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AACxE,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;AAE/F,wBAAgB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;CAAE,CAoDhL;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;CAAE,CAAC,CAS1I;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAShJ"}
@@ -0,0 +1,73 @@
1
+ import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
+ import { Buffer } from '../../lib/utils/buffer.js';
3
+ import crypto from '../../lib/utils/crypto.js';
4
+ import { assertNever } from '../../lib/utils/never.js';
5
+ export function FormatData(account, data, nonce, timestamp) {
6
+ nonce ??= crypto.randomUUID();
7
+ timestamp ??= new Date();
8
+ let timestampString;
9
+ if (typeof timestamp === 'string') {
10
+ timestampString = timestamp;
11
+ }
12
+ else {
13
+ timestampString = timestamp.toISOString();
14
+ }
15
+ const input = [
16
+ nonce,
17
+ timestampString,
18
+ account.publicKeyAndType
19
+ ];
20
+ const schema = [
21
+ { type: 'string', kind: 'utf8' },
22
+ { type: 'string', kind: 'utf8' },
23
+ KeetaNetLib.Utils.ASN1.ValidateASN1.IsOctetString
24
+ ];
25
+ for (const item of data) {
26
+ if (typeof item === 'string') {
27
+ input.push(item);
28
+ schema.push({ type: 'string', kind: 'utf8' });
29
+ }
30
+ else if (typeof item === 'number' || typeof item === 'bigint') {
31
+ input.push(item);
32
+ schema.push(KeetaNetLib.Utils.ASN1.ValidateASN1.IsInteger);
33
+ }
34
+ else if (KeetaNetLib.Account.isInstance(item)) {
35
+ input.push(item.publicKeyAndType);
36
+ schema.push(KeetaNetLib.Utils.ASN1.ValidateASN1.IsOctetString);
37
+ }
38
+ else {
39
+ assertNever(item);
40
+ }
41
+ }
42
+ /*
43
+ * Verify that the generated ASN.1 data matches the expected schema before returning it.
44
+ */
45
+ // @ts-ignore
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
47
+ const inputCanonical = KeetaNetLib.Utils.ASN1.ValidateASN1.againstSchema(input, schema);
48
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
49
+ const verificationData = KeetaNetLib.Utils.ASN1.JStoASN1(inputCanonical);
50
+ return ({
51
+ nonce: nonce,
52
+ timestamp: timestampString,
53
+ verificationData: Buffer.from(verificationData.toBER())
54
+ });
55
+ }
56
+ export async function SignData(account, data) {
57
+ const { nonce, timestamp, verificationData } = FormatData(account, data);
58
+ const signature = await account.sign(verificationData);
59
+ return ({
60
+ nonce: nonce,
61
+ timestamp: timestamp,
62
+ signature: signature.getBuffer().toString('base64')
63
+ });
64
+ }
65
+ export async function VerifySignedData(account, data, signed) {
66
+ const nonce = signed.nonce;
67
+ const timestamp = signed.timestamp;
68
+ const signatureBuffer = Buffer.from(signed.signature, 'base64');
69
+ /* XXX:TODO: Verify that the timestamp is a valid ISO 8601 date string within a reasonable range */
70
+ const { verificationData } = FormatData(account, data, nonce, timestamp);
71
+ return (account.verify(KeetaNetLib.Utils.Helper.bufferToArrayBuffer(verificationData), KeetaNetLib.Utils.Helper.bufferToArrayBuffer(signatureBuffer)));
72
+ }
73
+ //# sourceMappingURL=signing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing.js","sourceRoot":"","sources":["../../../src/lib/utils/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAMnE,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,MAAM,UAAU,UAAU,CAAC,OAAyB,EAAE,IAAc,EAAE,KAAc,EAAE,SAAyB;IAC9G,KAAK,KAAK,MAAM,CAAC,UAAU,EAAE,CAAC;IAC9B,SAAS,KAAK,IAAI,IAAI,EAAE,CAAC;IAEzB,IAAI,eAAuB,CAAC;IAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QACnC,eAAe,GAAG,SAAS,CAAC;IAC7B,CAAC;SAAM,CAAC;QACP,eAAe,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAC3C,CAAC;IAED,MAAM,KAAK,GAAwB;QAClC,KAAK;QACL,eAAe;QACf,OAAO,CAAC,gBAAgB;KACxB,CAAC;IAEF,MAAM,MAAM,GAAoC;QAC/C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,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N1Validation,\n\tASN1AnyJS as KeetaNetASN1AnyJS\n} from '@keetanetwork/keetanet-client/lib/utils/asn1.js';\n\nimport { Buffer } from '../../lib/utils/buffer.js';\nimport crypto from '../../lib/utils/crypto.js';\nimport { assertNever } from '../../lib/utils/never.js';\n\nexport type SignableAccount = ReturnType<InstanceType<typeof KeetaNetLib.Account>['assertAccount']>;\nexport type VerifableAccount = InstanceType<typeof KeetaNetLib.Account>;\nexport type Signable = (string | number | bigint | InstanceType<typeof KeetaNetLib.Account>)[];\n\nexport function FormatData(account: VerifableAccount, data: Signable, nonce?: string, timestamp?: string | Date): { nonce: string; timestamp: string; verificationData: Buffer; } {\n\tnonce ??= crypto.randomUUID();\n\ttimestamp ??= new Date();\n\n\tlet timestampString: string;\n\tif (typeof timestamp === 'string') {\n\t\ttimestampString = timestamp;\n\t} else {\n\t\ttimestampString = timestamp.toISOString();\n\t}\n\n\tconst input: KeetaNetASN1AnyJS[] = [\n\t\tnonce,\n\t\ttimestampString,\n\t\taccount.publicKeyAndType\n\t];\n\n\tconst schema: KeetaNetASN1Validation.Schema[] = [\n\t\t{ type: 'string', kind: 'utf8' },\n\t\t{ type: 'string', kind: 'utf8' },\n\t\tKeetaNetLib.Utils.ASN1.ValidateASN1.IsOctetString\n\t];\n\n\tfor (const item of data) {\n\t\tif (typeof item === 'string') {\n\t\t\tinput.push(item);\n\t\t\tschema.push({ type: 'string', kind: 'utf8' });\n\t\t} else if (typeof item === 'number' || typeof item === 'bigint') {\n\t\t\tinput.push(item);\n\t\t\tschema.push(KeetaNetLib.Utils.ASN1.ValidateASN1.IsInteger);\n\t\t} else if (KeetaNetLib.Account.isInstance(item)) {\n\t\t\tinput.push(item.publicKeyAndType);\n\t\t\tschema.push(KeetaNetLib.Utils.ASN1.ValidateASN1.IsOctetString);\n\t\t} else {\n\t\t\tassertNever(item);\n\t\t}\n\t}\n\n\t/*\n\t * Verify that the generated ASN.1 data matches the expected schema before returning it.\n\t */\n\t// @ts-ignore\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\tconst inputCanonical = KeetaNetLib.Utils.ASN1.ValidateASN1.againstSchema(input, schema);\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\tconst verificationData = KeetaNetLib.Utils.ASN1.JStoASN1(inputCanonical);\n\n\treturn({\n\t\tnonce: nonce,\n\t\ttimestamp: timestampString,\n\t\tverificationData: Buffer.from(verificationData.toBER())\n\t});\n}\n\nexport async function SignData(account: SignableAccount, data: Signable): Promise<{ nonce: string; timestamp: string; signature: string; }> {\n\tconst { nonce, timestamp, verificationData } = FormatData(account, data);\n\tconst signature = await account.sign(verificationData);\n\n\treturn({\n\t\tnonce: nonce,\n\t\ttimestamp: timestamp,\n\t\tsignature: signature.getBuffer().toString('base64')\n\t});\n}\n\nexport async function VerifySignedData(account: VerifableAccount, data: Signable, signed: Awaited<ReturnType<typeof SignData>>): Promise<boolean> {\n\tconst nonce = signed.nonce;\n\tconst timestamp = signed.timestamp;\n\tconst signatureBuffer = Buffer.from(signed.signature, 'base64');\n\n\t/* XXX:TODO: Verify that the timestamp is a valid ISO 8601 date string within a reasonable range */\n\tconst { verificationData } = FormatData(account, data, nonce, timestamp);\n\n\treturn(account.verify(KeetaNetLib.Utils.Helper.bufferToArrayBuffer(verificationData), KeetaNetLib.Utils.Helper.bufferToArrayBuffer(signatureBuffer)));\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function validateURL(url: string | undefined | null): URL;
2
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/url.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,GAAG,CAQ/D"}
@@ -0,0 +1,8 @@
1
+ export function validateURL(url) {
2
+ if (url === undefined || url === null) {
3
+ throw (new Error('Invalid URL: null or undefined'));
4
+ }
5
+ const parsedURL = new URL(url);
6
+ return (parsedURL);
7
+ }
8
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/lib/utils/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,GAA8B;IACzD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACvC,MAAK,CAAC,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAE/B,OAAM,CAAC,SAAS,CAAC,CAAC;AACnB,CAAC","sourcesContent":["export function validateURL(url: string | undefined | null): URL {\n\tif (url === undefined || url === null) {\n\t\tthrow(new Error('Invalid URL: null or undefined'));\n\t}\n\n\tconst parsedURL = new URL(url);\n\n\treturn(parsedURL);\n}\n"]}