@keetanetwork/anchor 0.0.79 → 0.0.80

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 (88) hide show
  1. package/lib/anchor-external.d.ts +94 -1
  2. package/lib/anchor-external.d.ts.map +1 -1
  3. package/lib/anchor-external.generated.js +52 -3
  4. package/lib/anchor-external.generated.js.map +1 -1
  5. package/lib/anchor-external.js +126 -3
  6. package/lib/anchor-external.js.map +1 -1
  7. package/lib/anchor-metadata-server.d.ts +15 -2
  8. package/lib/anchor-metadata-server.d.ts.map +1 -1
  9. package/lib/anchor-metadata-server.js +54 -0
  10. package/lib/anchor-metadata-server.js.map +1 -1
  11. package/lib/anchor-status.d.ts +149 -0
  12. package/lib/anchor-status.d.ts.map +1 -0
  13. package/lib/anchor-status.js +93 -0
  14. package/lib/anchor-status.js.map +1 -0
  15. package/lib/chaining.d.ts +2 -1
  16. package/lib/chaining.d.ts.map +1 -1
  17. package/lib/chaining.js +67 -8
  18. package/lib/chaining.js.map +1 -1
  19. package/lib/history.d.ts +405 -0
  20. package/lib/history.d.ts.map +1 -0
  21. package/lib/history.js +723 -0
  22. package/lib/history.js.map +1 -0
  23. package/lib/http-server/index.d.ts +1 -0
  24. package/lib/http-server/index.d.ts.map +1 -1
  25. package/lib/http-server/index.js +1 -0
  26. package/lib/http-server/index.js.map +1 -1
  27. package/lib/index.d.ts +6 -1
  28. package/lib/index.d.ts.map +1 -1
  29. package/lib/index.js +3 -1
  30. package/lib/index.js.map +1 -1
  31. package/lib/metadata.types.d.ts +3 -0
  32. package/lib/metadata.types.d.ts.map +1 -1
  33. package/lib/metadata.types.js.map +1 -1
  34. package/lib/resolver.d.ts +28 -7
  35. package/lib/resolver.d.ts.map +1 -1
  36. package/lib/resolver.generated.js +528 -453
  37. package/lib/resolver.generated.js.map +1 -1
  38. package/lib/resolver.js +67 -8
  39. package/lib/resolver.js.map +1 -1
  40. package/lib/utils/brand.d.ts +5 -0
  41. package/lib/utils/brand.d.ts.map +1 -1
  42. package/lib/utils/brand.js +4 -1
  43. package/lib/utils/brand.js.map +1 -1
  44. package/npm-shrinkwrap.json +10 -17
  45. package/package.json +2 -2
  46. package/services/asset-movement/client.d.ts +7 -1
  47. package/services/asset-movement/client.d.ts.map +1 -1
  48. package/services/asset-movement/client.js +70 -15
  49. package/services/asset-movement/client.js.map +1 -1
  50. package/services/asset-movement/lib/location.d.ts.map +1 -1
  51. package/services/asset-movement/lib/location.js +1 -0
  52. package/services/asset-movement/lib/location.js.map +1 -1
  53. package/services/asset-movement/server.d.ts +1 -1
  54. package/services/asset-movement/server.d.ts.map +1 -1
  55. package/services/asset-movement/server.js +1 -1
  56. package/services/asset-movement/server.js.map +1 -1
  57. package/services/asset-movement/status-source.d.ts +32 -0
  58. package/services/asset-movement/status-source.d.ts.map +1 -0
  59. package/services/asset-movement/status-source.js +77 -0
  60. package/services/asset-movement/status-source.js.map +1 -0
  61. package/services/fx/server.d.ts +2 -2
  62. package/services/fx/server.d.ts.map +1 -1
  63. package/services/fx/server.js +2 -1
  64. package/services/fx/server.js.map +1 -1
  65. package/services/kyc/server.d.ts +1 -1
  66. package/services/kyc/server.d.ts.map +1 -1
  67. package/services/kyc/server.js +1 -1
  68. package/services/kyc/server.js.map +1 -1
  69. package/services/notification/client.js +50 -6
  70. package/services/notification/client.js.map +1 -1
  71. package/services/notification/server.d.ts.map +1 -1
  72. package/services/notification/server.js +4 -1
  73. package/services/notification/server.js.map +1 -1
  74. package/services/storage/client.js +50 -6
  75. package/services/storage/client.js.map +1 -1
  76. package/services/storage/clients/contacts.d.ts +5 -0
  77. package/services/storage/clients/contacts.d.ts.map +1 -1
  78. package/services/storage/clients/contacts.js +20 -9
  79. package/services/storage/clients/contacts.js.map +1 -1
  80. package/services/storage/server.d.ts +1 -1
  81. package/services/storage/server.d.ts.map +1 -1
  82. package/services/storage/server.js +2 -2
  83. package/services/storage/server.js.map +1 -1
  84. package/services/username/client.js +50 -6
  85. package/services/username/client.js.map +1 -1
  86. package/services/username/server.d.ts.map +1 -1
  87. package/services/username/server.js +4 -1
  88. package/services/username/server.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/lib/history.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAYnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,kCAAkC,EAAE,eAAe,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAInJ,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC;AAwXtD;;;GAGG;AACH,SAAS,OAAO,CAAC,KAAa;IAC7B,IAAI,CAAC;QACJ,OAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACR,OAAM,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,QAAgB,EAAE,SAAmB;IAC7D,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACJ,MAAM,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACR,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED,OAAM,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAuC;IAC9E,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/D,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC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C,GAAG,CAAC,YAAY,CAAC,CAAC;QAC7C,IAAI,MAAM,KAAK,SAAS,IAAI,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3D,OAAM,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;QACxB,CAAC;QAED,IAAI,MAAkE,CAAC;QACvE,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;YACrE,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,wBAAwB,EAAE,0BAA0B,YAAY,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1G,MAAM,GAAG,IAAI,CAAC;QACf,CAAC;QAED,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QACtC,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACD;AAED,eAAe,WAAW,CAAC","sourcesContent":["import type { GenericAccount } from '@keetanetwork/keetanet-client/lib/account.js';\nimport type { Block } from '@keetanetwork/keetanet-client/lib/block/index.js';\nimport type { BlockOperations } from '@keetanetwork/keetanet-client/lib/block/operations.js';\nimport { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nimport type { KeetaNetAccount } from './asset.js';\nimport type { Logger } from './log/index.js';\nimport type { KeetaAssetMovementTransaction } from '../services/asset-movement/common.js';\nimport type {\n\tAnchorExternalTransactionStatusOptions,\n\tAnchorGetTransactionStatusOptions,\n\tAnchorTransactionStatus,\n\tAnchorTransactionStatusResult,\n\tAnchorTransferReader\n} from './anchor-status.js';\nimport { isCompletedTransferStatus } from './anchor-status.js';\nimport { convertAssetSearchInputToCanonical, isChainLocation, toAssetLocationFromString, toAssetPair } from '../services/asset-movement/common.js';\n\ntype Account = InstanceType<typeof KeetaNetLib.Account>;\n\nconst OperationType = KeetaNetLib.Block.OperationType;\n\n/**\n * Wallet-facing logical category of a transaction.\n */\nexport type LogicalTransactionType = 'send' | 'receive' | 'swap' | 'deposit' | 'withdraw' | 'bridge' | 'other';\n\n/**\n * Standardized lifecycle state. Only `complete` is asserted from a settled\n * block or a `COMPLETE` anchor status.\n */\nexport type LogicalTransactionStatus = 'pending' | 'complete' | 'failed';\n\n/**\n * Flow of value relative to the queried account.\n */\nexport type LogicalDirection = 'in' | 'out' | 'self';\n\n/**\n * A token (or anchor asset) and its quantity in smallest units.\n */\nexport type LogicalAmount = {\n\t/**\n\t * Token public key for on-chain legs, or the anchor asset rendered as a\n\t * string for anchor legs.\n\t */\n\ttoken: string;\n\t/**\n\t * Quantity in the asset's smallest unit.\n\t */\n\tamount: bigint;\n};\n\n/**\n * The other party to a logical transaction.\n */\nexport type LogicalCounterparty = {\n\t/**\n\t * What the counterparty represents.\n\t */\n\tkind: 'account' | 'anchor' | 'liquidity';\n\t/**\n\t * Account public key (or anchor id) of the counterparty.\n\t */\n\tid: string;\n\t/**\n\t * Optional display name resolved for the counterparty.\n\t */\n\tname?: string;\n};\n\n/**\n * One constituent part of a logical transaction: either a single on-chain\n * operation or a transfer tracked at an anchor.\n */\nexport type LogicalLeg =\n\t| {\n\t\t/**\n\t\t * On-chain operation leg.\n\t\t */\n\t\tkind: 'onchain';\n\t\t/**\n\t\t * Hash of the block carrying the operation.\n\t\t */\n\t\tblockHash: string;\n\t\t/**\n\t\t * Index of the operation within its block.\n\t\t */\n\t\toperationIndex: number;\n\t\t/**\n\t\t * Whether the operation sent or received value.\n\t\t */\n\t\topType: 'send' | 'receive';\n\t\t/**\n\t\t * Account on the other side of the operation.\n\t\t */\n\t\tcounterparty: string;\n\t\t/**\n\t\t * Value moved by the operation.\n\t\t */\n\t\tamount: LogicalAmount;\n\t}\n\t| {\n\t\t/**\n\t\t * Anchor-tracked transfer leg.\n\t\t */\n\t\tkind: 'anchor';\n\t\t/**\n\t\t * Anchor account the transfer was filed under.\n\t\t */\n\t\tanchorID: string;\n\t\t/**\n\t\t * Anchor-scoped transaction id.\n\t\t */\n\t\ttransactionID: string;\n\t\t/**\n\t\t * Related chain transaction ids reported by the anchor.\n\t\t */\n\t\tsubTransactions: string[];\n\t};\n\n/**\n * A single condensed, wallet-displayable transaction folded from one or more\n * on-chain operations and any anchor transfer that backs them.\n */\nexport type LogicalTransaction = {\n\t/**\n\t * Stable id: the block hash, or `blockHash:operationIndex` when a block\n\t * yields more than one logical transaction.\n\t */\n\tid: string;\n\t/**\n\t * Logical category.\n\t */\n\ttype: LogicalTransactionType;\n\t/**\n\t * Standardized status.\n\t */\n\tstatus: LogicalTransactionStatus;\n\t/**\n\t * Raw provider status string, present when an anchor transfer backs the\n\t * transaction. The wallet interprets non-standardized states.\n\t */\n\tproviderStatus?: string;\n\t/**\n\t * Flow of value relative to the queried account.\n\t */\n\tdirection: LogicalDirection;\n\t/**\n\t * ISO-8601 timestamp from the vote staple the block settled in.\n\t */\n\ttimestamp: string;\n\t/**\n\t * Value the account sent, when applicable.\n\t */\n\tsend?: LogicalAmount;\n\t/**\n\t * Value the account received, when applicable.\n\t */\n\treceive?: LogicalAmount;\n\t/**\n\t * Fee paid, when applicable.\n\t */\n\tfee?: LogicalAmount;\n\t/**\n\t * The other party, when one applies.\n\t */\n\tcounterparty?: LogicalCounterparty;\n\t/**\n\t * Constituent legs.\n\t */\n\tlegs: LogicalLeg[];\n\t/**\n\t * Source references for drill-down.\n\t */\n\trefs: {\n\t\t/**\n\t\t * Block hashes contributing to this logical transaction.\n\t\t */\n\t\tblockHashes: string[];\n\t\t/**\n\t\t * Anchor-scoped transaction ids contributing to this logical transaction.\n\t\t */\n\t\tanchorTxIDs: string[];\n\t\t/**\n\t\t * Raw `external` strings observed, when present.\n\t\t */\n\t\texternal?: string[];\n\t};\n\t/**\n\t * Raw source the transaction was folded from. Present only when\n\t * {@link UserHistoryListOptions.includeSource} is set.\n\t */\n\tsource?: LogicalTransactionSource;\n};\n\n/**\n * Raw source backing a {@link LogicalTransaction}, for callers that need to\n * drill down into the underlying on-chain data without re-fetching.\n */\nexport type LogicalTransactionSource = {\n\t/**\n\t * Vote staple that settled the source block.\n\t */\n\tstaple: HistoryStaple;\n\t/**\n\t * The enriched source block the transaction was classified from.\n\t */\n\tenriched: EnrichedBlock;\n};\n\n/**\n * One on-chain operation enriched with the anchor transfer it resolved to,\n * if any. The classify input unit.\n */\nexport type EnrichedOperation = {\n\t/**\n\t * The decoded on-chain operation.\n\t */\n\toperation: BlockOperations;\n\t/**\n\t * Index of the operation within its block.\n\t */\n\tindex: number;\n\t/**\n\t * Anchor transfer the operation resolved to, if enrichment found one.\n\t */\n\ttransfer?: KeetaAssetMovementTransaction;\n\t/**\n\t * Anchor account the transfer resolved under, when enrichment found one.\n\t * Authoritative over operation counterparties: for anchor-issued payout\n\t * blocks the operation counterparty is the user, not the anchor.\n\t */\n\tanchorID?: string;\n};\n\n/**\n * A block with each of its operations enriched. The classifier operates on\n * this and has no I/O of its own.\n */\nexport type EnrichedBlock = {\n\t/**\n\t * Hash of the block.\n\t */\n\tblockHash: string;\n\t/**\n\t * Issuing account of the block.\n\t * Note: Do NOT narrow to `AccountPublicKeyString`.\n\t */\n\taccount: string;\n\t/**\n\t * Account whose history is being folded.\n\t * Note: Do NOT narrow to `AccountPublicKeyString`.\n\t */\n\tperspective?: string;\n\t/**\n\t * ISO-8601 timestamp from the block's vote staple.\n\t */\n\ttimestamp: string;\n\t/**\n\t * The block's enriched operations.\n\t */\n\toperations: EnrichedOperation[];\n};\n\n/**\n * A classifier that maps an enriched block to zero or more logical\n * transactions. Returns `null` when it does not apply.\n */\nexport interface LogicalClassifier {\n\tclassify(block: EnrichedBlock): LogicalTransaction[] | null;\n}\n\n/**\n * A history page entry as produced by a node client's history call.\n */\nexport interface HistoryEntry {\n\t/**\n\t * The vote staple settling one or more blocks.\n\t */\n\tvoteStaple: HistoryStaple;\n}\n\n/**\n * The minimal vote-staple surface consumed when folding history.\n */\nexport interface HistoryStaple {\n\t/**\n\t * Settlement time of the staple.\n\t */\n\ttimestamp(): Date;\n\t/**\n\t * Blocks settled by the staple.\n\t */\n\tblocks: readonly Block[];\n\t/**\n\t * Cursor for the next page.\n\t */\n\tblocksHash: { toString(): string };\n}\n\n/**\n * Per-page query passed to a {@link HistorySource}.\n */\nexport type HistoryQuery = {\n\t/**\n\t * Number of vote staples to walk back per page.\n\t */\n\tdepth?: number;\n\t/**\n\t * Cursor returned by a previous page.\n\t */\n\tstartBlocksHash?: string;\n\t/**\n\t * Page size hint.\n\t */\n\tpageSize?: number;\n};\n\n/**\n * Account a history is read for: an account instance, its public-key\n * string, or `null` for the network-wide perspective.\n */\nexport type HistoryAccount = GenericAccount | string | null;\n\n/**\n * Inverted source of on-chain history pages, newest-first.\n */\nexport interface HistorySource {\n\tgetHistory(account: HistoryAccount, query?: HistoryQuery): Promise<HistoryEntry[]>;\n}\n\n/**\n * Construction inputs for {@link UserHistory}.\n */\nexport type UserHistoryConfig = {\n\t/**\n\t * Source of on-chain history pages. Any object exposing\n\t * {@link HistorySource.getHistory} is accepted, including a node client.\n\t */\n\thistory: HistorySource;\n\t/**\n\t * Anchor status reader used to enrich operations.\n\t */\n\tstatus?: AnchorTransactionStatus<KeetaAssetMovementTransaction>;\n\t/**\n\t * Ordered classifiers, specific-first.\n\t * Defaults to {@link defaultClassifiers}.\n\t */\n\tclassifiers?: readonly LogicalClassifier[];\n\t/**\n\t * Logger for diagnostics.\n\t */\n\tlogger?: Logger;\n};\n\n/**\n * Per-call options for {@link UserHistory.list}.\n */\nexport type UserHistoryListOptions = {\n\t/**\n\t * Vote staples to walk back per page.\n\t */\n\tdepth?: number;\n\t/**\n\t * Page size hint.\n\t */\n\tpageSize?: number;\n\t/**\n\t * Maximum number of logical transactions to return.\n\t */\n\tlimit?: number;\n\t/**\n\t * Cursor to resume paging from.\n\t */\n\tcursor?: string;\n\t/**\n\t * Enable anchor enrichment.\n\t * Defaults to `true` when a status source is set.\n\t */\n\tenrich?: boolean;\n\t/**\n\t * Keys tried against encrypted external slices.\n\t */\n\tdecryptionKeys?: Account[];\n\t/**\n\t * Account used to authenticate anchor status reads.\n\t */\n\trequesterAccount?: KeetaNetAccount;\n\t/**\n\t * Attach {@link LogicalTransaction.source} to each returned transaction.\n\t * Defaults to `false` to keep results lean.\n\t */\n\tincludeSource?: boolean;\n};\n\n/**\n * Parse a value string into smallest-unit units, defaulting to zero on a\n * value that is not a whole-number string.\n */\nfunction toUnits(value: string): bigint {\n\ttry {\n\t\treturn(BigInt(value));\n\t} catch {\n\t\treturn(0n);\n\t}\n}\n\n/**\n * Whether a location string denotes a chain (optionally a specific one).\n */\nfunction locationIsChain(location: string, chainType?: 'keeta'): boolean {\n\tlet parsed;\n\ttry {\n\t\tparsed = toAssetLocationFromString(location);\n\t} catch {\n\t\treturn(false);\n\t}\n\n\treturn(isChainLocation(parsed, chainType));\n}\n\n/**\n * Derive the logical type of an anchor transfer from its endpoints.\n */\nexport function logicalTypeFromTransfer(transfer: KeetaAssetMovementTransaction): LogicalTransactionType {\n\tconst fromKeeta = locationIsChain(transfer.from.location, 'keeta');\n\tconst toKeeta = locationIsChain(transfer.to.location, 'keeta');\n\tif (fromKeeta && toKeeta) {\n\t\treturn('swap');\n\t}\n\n\tconst fromChain = locationIsChain(transfer.from.location);\n\tconst toChain = locationIsChain(transfer.to.location);\n\tif ((fromKeeta && toChain) || (toKeeta && fromChain)) {\n\t\treturn('bridge');\n\t}\n\n\tif (fromKeeta) {\n\t\treturn('withdraw');\n\t}\n\n\tif (toKeeta) {\n\t\treturn('deposit');\n\t}\n\n\treturn('other');\n}\n\n/**\n * Map an anchor transfer's raw status onto the standardized status, carrying\n * the raw provider string for the wallet to interpret.\n */\nexport function statusFromTransfer(transfer: KeetaAssetMovementTransaction): { status: LogicalTransactionStatus; providerStatus: string } {\n\tif (isCompletedTransferStatus(transfer.status)) {\n\t\treturn({ status: 'complete', providerStatus: transfer.status });\n\t}\n\n\treturn({ status: 'pending', providerStatus: transfer.status });\n}\n\n/**\n * Derive value flow for an anchor transfer type.\n */\nfunction directionFromTransfer(type: LogicalTransactionType, fromKeeta: boolean): LogicalDirection {\n\tif (type === 'deposit') {\n\t\treturn('in');\n\t}\n\n\tif (type === 'withdraw') {\n\t\treturn('out');\n\t}\n\n\tif (type === 'bridge') {\n\t\tif (fromKeeta) {\n\t\t\treturn('out');\n\t\t}\n\n\t\treturn('in');\n\t}\n\n\treturn('self');\n}\n\n/**\n * Collect the chain transaction ids an anchor transfer references.\n */\nfunction collectAnchorSubTransactions(transfer: KeetaAssetMovementTransaction): string[] {\n\tconst ids: string[] = [];\n\tconst groups = [ transfer.from.transactions, transfer.to.transactions ];\n\tfor (const group of groups) {\n\t\tfor (const value of Object.values(group)) {\n\t\t\tif (value !== null && value !== undefined) {\n\t\t\t\tids.push(value.id);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn(ids);\n}\n\n/**\n * A SEND/RECEIVE operation reduced to its logical shape.\n */\ntype OperationView = {\n\topType: 'send' | 'receive';\n\tcounterparty: string;\n\tamount: LogicalAmount;\n};\n\n/**\n * Reduce a block operation to its logical view, or `null` for non-transfer\n * operations.\n */\nfunction operationView(operation: BlockOperations): OperationView | null {\n\tif (operation.type === OperationType.SEND) {\n\t\treturn({\n\t\t\topType: 'send',\n\t\t\tcounterparty: operation.to.publicKeyString.get(),\n\t\t\tamount: { token: operation.token.publicKeyString.get(), amount: operation.amount }\n\t\t});\n\t}\n\tif (operation.type === OperationType.RECEIVE) {\n\t\treturn({\n\t\t\topType: 'receive',\n\t\t\tcounterparty: operation.from.publicKeyString.get(),\n\t\t\tamount: { token: operation.token.publicKeyString.get(), amount: operation.amount }\n\t\t});\n\t}\n\n\treturn(null);\n}\n\n/**\n * Reduce an operation to its logical view relative to the block's\n * perspective account.\n */\nfunction viewOf(block: EnrichedBlock, operation: BlockOperations): OperationView | null {\n\tconst native = operationView(operation);\n\tif (native === null) {\n\t\treturn(null);\n\t}\n\n\tif (block.perspective === undefined || block.perspective === block.account) {\n\t\treturn(native);\n\t}\n\n\tif (native.opType === 'send' && native.counterparty === block.perspective) {\n\t\treturn({ opType: 'receive', counterparty: block.account, amount: native.amount });\n\t}\n\n\treturn(null);\n}\n\n/**\n * The account on the other side of a transfer operation, if any.\n */\nfunction counterpartyID(operation: BlockOperations): string | undefined {\n\tif (operation.type === OperationType.SEND) {\n\t\treturn(operation.to.publicKeyString.get());\n\t}\n\tif (operation.type === OperationType.RECEIVE) {\n\t\treturn(operation.from.publicKeyString.get());\n\t}\n\n\treturn(undefined);\n}\n\n/**\n * An operation view paired with its block-relative index.\n */\ntype IndexedView = OperationView & { index: number };\n\n/**\n * Partition a block's operations into send/receive views.\n */\nfunction viewsOf(block: EnrichedBlock): { sends: IndexedView[]; receives: IndexedView[]; otherCount: number } {\n\tconst sends: IndexedView[] = [];\n\tconst receives: IndexedView[] = [];\n\tlet otherCount = 0;\n\tfor (const enriched of block.operations) {\n\t\tconst view = viewOf(block, enriched.operation);\n\t\tif (view === null) {\n\t\t\totherCount++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst indexed: IndexedView = { ...view, index: enriched.index };\n\t\tif (indexed.opType === 'send') {\n\t\t\tsends.push(indexed);\n\t\t} else {\n\t\t\treceives.push(indexed);\n\t\t}\n\t}\n\n\treturn({ sends, receives, otherCount });\n}\n\n/**\n * The shared counterparty across views, or `undefined` when they differ.\n */\nfunction uniformCounterparty(views: readonly IndexedView[]): string | undefined {\n\tconst first = views[0];\n\tif (first === undefined) {\n\t\treturn(undefined);\n\t}\n\n\tfor (const view of views) {\n\t\tif (view.counterparty !== first.counterparty) {\n\t\t\treturn(undefined);\n\t\t}\n\t}\n\n\treturn(first.counterparty);\n}\n\n/**\n * Build on-chain legs for every transfer operation in a block.\n */\nfunction onchainLegs(block: EnrichedBlock): LogicalLeg[] {\n\tconst legs: LogicalLeg[] = [];\n\tfor (const enriched of block.operations) {\n\t\tconst view = viewOf(block, enriched.operation);\n\t\tif (view === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlegs.push({\n\t\t\tkind: 'onchain',\n\t\t\tblockHash: block.blockHash,\n\t\t\toperationIndex: enriched.index,\n\t\t\topType: view.opType,\n\t\t\tcounterparty: view.counterparty,\n\t\t\tamount: view.amount\n\t\t});\n\t}\n\n\treturn(legs);\n}\n\n/**\n * Collect raw `external` strings carried by a block's SEND operations.\n */\nfunction blockExternals(block: EnrichedBlock): string[] {\n\tconst externals: string[] = [];\n\tfor (const enriched of block.operations) {\n\t\tconst operation = enriched.operation;\n\t\tif (operation.type === OperationType.SEND && operation.external !== undefined) {\n\t\t\texternals.push(operation.external);\n\t\t}\n\t}\n\n\treturn(externals);\n}\n\n/**\n * Build the refs block for a logical transaction.\n */\nfunction buildRefs(block: EnrichedBlock, anchorTxIDs: string[]): LogicalTransaction['refs'] {\n\tconst refs: LogicalTransaction['refs'] = { blockHashes: [ block.blockHash ], anchorTxIDs };\n\tconst externals = blockExternals(block);\n\tif (externals.length > 0) {\n\t\trefs.external = externals;\n\t}\n\n\treturn(refs);\n}\n\n// #endregion Operation views\n\n// #region Classifiers\n\n/**\n * Build the logical transaction backing one enriched anchor operation.\n */\nfunction buildAnchorTransaction(block: EnrichedBlock, enriched: EnrichedOperation, transfer: KeetaAssetMovementTransaction): LogicalTransaction {\n\tconst type = logicalTypeFromTransfer(transfer);\n\tconst fromKeeta = locationIsChain(transfer.from.location, 'keeta');\n\tconst direction = directionFromTransfer(type, fromKeeta);\n\tconst settled = statusFromTransfer(transfer);\n\tconst assets = toAssetPair(transfer.asset);\n\tconst view = viewOf(block, enriched.operation);\n\n\tconst legs: LogicalLeg[] = [];\n\tif (view !== null) {\n\t\tlegs.push({\n\t\t\tkind: 'onchain',\n\t\t\tblockHash: block.blockHash,\n\t\t\toperationIndex: enriched.index,\n\t\t\topType: view.opType,\n\t\t\tcounterparty: view.counterparty,\n\t\t\tamount: view.amount\n\t\t});\n\t}\n\n\tconst anchorID = enriched.anchorID ?? view?.counterparty ?? transfer.id;\n\tlegs.push({\n\t\tkind: 'anchor',\n\t\tanchorID,\n\t\ttransactionID: transfer.id,\n\t\tsubTransactions: collectAnchorSubTransactions(transfer)\n\t});\n\n\tconst refs: LogicalTransaction['refs'] = { blockHashes: [ block.blockHash ], anchorTxIDs: [ transfer.id ] };\n\tconst externals = blockExternals(block);\n\tif (externals.length > 0) {\n\t\trefs.external = externals;\n\t}\n\n\tconst transaction: LogicalTransaction = {\n\t\tid: `${block.blockHash}:${enriched.index}`,\n\t\ttype,\n\t\tstatus: settled.status,\n\t\tproviderStatus: settled.providerStatus,\n\t\tdirection,\n\t\ttimestamp: block.timestamp,\n\t\tsend: { token: convertAssetSearchInputToCanonical(assets.from), amount: toUnits(transfer.from.value) },\n\t\treceive: { token: convertAssetSearchInputToCanonical(assets.to), amount: toUnits(transfer.to.value) },\n\t\tlegs,\n\t\trefs\n\t};\n\n\ttransaction.counterparty = { kind: 'anchor', id: anchorID };\n\n\tif (transfer.fee !== null) {\n\t\ttransaction.fee = { token: convertAssetSearchInputToCanonical(transfer.fee.asset), amount: toUnits(transfer.fee.value) };\n\t}\n\n\treturn(transaction);\n}\n\n/**\n * Emits one logical transaction per operation that resolved to an anchor\n * transfer; the logical type comes from the transfer, not block shape.\n */\nconst anchorTransferClassifier: LogicalClassifier = {\n\tclassify(block) {\n\t\tconst transactions: LogicalTransaction[] = [];\n\t\tfor (const enriched of block.operations) {\n\t\t\tconst transfer = enriched.transfer;\n\t\t\tif (transfer === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttransactions.push(buildAnchorTransaction(block, enriched, transfer));\n\t\t}\n\n\t\tif (transactions.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(transactions);\n\t}\n};\n\n/**\n * Classifies an on-chain atomic swap: SEND(s) and RECEIVE(s) against a single\n * counterparty with differing send/receive tokens.\n */\nconst atomicSwapClassifier: LogicalClassifier = {\n\tclassify(block) {\n\t\tconst { sends, receives, otherCount } = viewsOf(block);\n\t\tif (otherCount !== 0 || sends.length === 0 || receives.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst counterparty = uniformCounterparty([ ...sends, ...receives ]);\n\t\tif (counterparty === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst received = receives[0];\n\t\tif (received === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst principal = sends.find(send => send.amount.token !== received.amount.token);\n\t\tif (principal === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst fee = sends.find(send => send.index !== principal.index);\n\n\t\tconst transaction: LogicalTransaction = {\n\t\t\tid: block.blockHash,\n\t\t\ttype: 'swap',\n\t\t\tstatus: 'complete',\n\t\t\tdirection: 'self',\n\t\t\ttimestamp: block.timestamp,\n\t\t\tsend: principal.amount,\n\t\t\treceive: received.amount,\n\t\t\tcounterparty: { kind: 'liquidity', id: counterparty },\n\t\t\tlegs: onchainLegs(block),\n\t\t\trefs: buildRefs(block, [])\n\t\t};\n\n\t\tif (fee !== undefined) {\n\t\t\ttransaction.fee = fee.amount;\n\t\t}\n\n\t\treturn([ transaction ]);\n\t}\n};\n\n/**\n * Classifies a SEND-only block as a plain send.\n */\nconst sendClassifier: LogicalClassifier = {\n\tclassify(block) {\n\t\tconst { sends, receives, otherCount } = viewsOf(block);\n\t\tif (otherCount !== 0 || receives.length !== 0 || sends.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst primary = sends[0];\n\t\tif (primary === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst transaction: LogicalTransaction = {\n\t\t\tid: block.blockHash,\n\t\t\ttype: 'send',\n\t\t\tstatus: 'complete',\n\t\t\tdirection: 'out',\n\t\t\ttimestamp: block.timestamp,\n\t\t\tsend: primary.amount,\n\t\t\tlegs: onchainLegs(block),\n\t\t\trefs: buildRefs(block, [])\n\t\t};\n\n\t\tconst counterparty = uniformCounterparty(sends);\n\t\tif (counterparty !== undefined) {\n\t\t\ttransaction.counterparty = { kind: 'account', id: counterparty };\n\t\t}\n\n\t\treturn([ transaction ]);\n\t}\n};\n\n/**\n * Classifies a RECEIVE-only block as a plain receive.\n */\nconst receiveClassifier: LogicalClassifier = {\n\tclassify(block) {\n\t\tconst { sends, receives, otherCount } = viewsOf(block);\n\t\tif (otherCount !== 0 || sends.length !== 0 || receives.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst primary = receives[0];\n\t\tif (primary === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst transaction: LogicalTransaction = {\n\t\t\tid: block.blockHash,\n\t\t\ttype: 'receive',\n\t\t\tstatus: 'complete',\n\t\t\tdirection: 'in',\n\t\t\ttimestamp: block.timestamp,\n\t\t\treceive: primary.amount,\n\t\t\tlegs: onchainLegs(block),\n\t\t\trefs: buildRefs(block, [])\n\t\t};\n\n\t\tconst counterparty = uniformCounterparty(receives);\n\t\tif (counterparty !== undefined) {\n\t\t\ttransaction.counterparty = { kind: 'account', id: counterparty };\n\t\t}\n\n\t\treturn([ transaction ]);\n\t}\n};\n\n/**\n * Fallback that emits a single `other` transaction for any unmatched block.\n */\nconst otherClassifier: LogicalClassifier = {\n\tclassify(block) {\n\t\tconst transaction: LogicalTransaction = {\n\t\t\tid: block.blockHash,\n\t\t\ttype: 'other',\n\t\t\tstatus: 'complete',\n\t\t\tdirection: 'self',\n\t\t\ttimestamp: block.timestamp,\n\t\t\tlegs: onchainLegs(block),\n\t\t\trefs: buildRefs(block, [])\n\t\t};\n\n\t\treturn([ transaction ]);\n\t}\n};\n\n/**\n * Default ordered classifier list, specific-first.\n */\nexport const defaultClassifiers: readonly LogicalClassifier[] = [\n\tanchorTransferClassifier,\n\tatomicSwapClassifier,\n\tsendClassifier,\n\treceiveClassifier,\n\totherClassifier\n];\n\n/**\n * Fold enriched blocks into logical transactions by running the ordered\n * classifiers; the first classifier that applies to a block wins.\n */\nexport function foldHistory(blocks: readonly EnrichedBlock[], classifiers: readonly LogicalClassifier[]): LogicalTransaction[] {\n\tconst results: LogicalTransaction[] = [];\n\tfor (const block of blocks) {\n\t\tfor (const classifier of classifiers) {\n\t\t\tconst classified = classifier.classify(block);\n\t\t\tif (classified !== null) {\n\t\t\t\tresults.push(...classified);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn(results);\n}\n\n/**\n * A transfer paired with the anchor account it resolved under.\n */\ntype ResolvedTransfer = {\n\tanchorID: string;\n\ttransfer: KeetaAssetMovementTransaction;\n};\n\n/**\n * The first transfer reported as a status across an external's anchors.\n */\nfunction firstResolvedTransfer(results: { [anchorID: string]: AnchorTransactionStatusResult<KeetaAssetMovementTransaction> }): ResolvedTransfer | undefined {\n\tfor (const [ anchorID, result ] of Object.entries(results)) {\n\t\tif (result.kind === 'status') {\n\t\t\treturn({ anchorID, transfer: result.status.transaction });\n\t\t}\n\t}\n\n\treturn(undefined);\n}\n\n/**\n * Build decode + status options for an external resolution.\n */\nfunction buildExternalOptions(options?: UserHistoryListOptions): AnchorExternalTransactionStatusOptions {\n\tconst built: AnchorExternalTransactionStatusOptions = {};\n\tif (options?.decryptionKeys !== undefined) {\n\t\tbuilt.decryptionKeys = options.decryptionKeys;\n\t}\n\n\tif (options?.requesterAccount !== undefined) {\n\t\tbuilt.requesterAccount = options.requesterAccount;\n\t}\n\n\treturn(built);\n}\n\n/**\n * Attach raw sources to folded transactions by their source block hash.\n *\n * A transaction id is its block hash, or `blockHash:operationIndex` when a\n * block yields more than one logical transaction.\n */\nfunction attachSources(transactions: readonly LogicalTransaction[], sources: ReadonlyMap<string, LogicalTransactionSource>): void {\n\tfor (const transaction of transactions) {\n\t\tconst [ blockHash ] = transaction.id.split(':');\n\t\tif (blockHash === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst source = sources.get(blockHash);\n\t\tif (source !== undefined) {\n\t\t\ttransaction.source = source;\n\t\t}\n\t}\n}\n\n/**\n * Normalize the queried account to its public key string.\n */\nfunction perspectiveOf(account: HistoryAccount): string | undefined {\n\tif (account === null) {\n\t\treturn(undefined);\n\t}\n\n\tif (typeof account === 'string') {\n\t\treturn(account);\n\t}\n\n\treturn(account.publicKeyString.get());\n}\n\n/**\n * Build status options for a reverse-lookup.\n */\nfunction buildStatusOptions(options?: UserHistoryListOptions): AnchorGetTransactionStatusOptions {\n\tconst built: AnchorGetTransactionStatusOptions = {};\n\tif (options?.requesterAccount !== undefined) {\n\t\tbuilt.requesterAccount = options.requesterAccount;\n\t}\n\n\treturn(built);\n}\n\n/**\n * Folds a user's on-chain history and anchor transfer data into a condensed\n * list of {@link LogicalTransaction}.\n */\nexport class UserHistory {\n\treadonly #history: HistorySource;\n\treadonly #status?: AnchorTransactionStatus<KeetaAssetMovementTransaction>;\n\treadonly #classifiers: readonly LogicalClassifier[];\n\treadonly #logger?: Logger;\n\n\tconstructor(config: UserHistoryConfig) {\n\t\tthis.#history = config.history;\n\t\tif (config.status !== undefined) {\n\t\t\tthis.#status = config.status;\n\t\t}\n\n\t\tif (config.logger !== undefined) {\n\t\t\tthis.#logger = config.logger;\n\t\t}\n\n\t\tthis.#classifiers = config.classifiers ?? defaultClassifiers;\n\t}\n\n\t/**\n\t * Fetch, enrich and fold a user's history into logical transactions.\n\t */\n\tasync list(account: HistoryAccount, options?: UserHistoryListOptions): Promise<LogicalTransaction[]> {\n\t\tconst transactions: LogicalTransaction[] = [];\n\t\tfor await (const transaction of this.iterate(account, options)) {\n\t\t\ttransactions.push(transaction);\n\t\t}\n\n\t\treturn(transactions);\n\t}\n\n\t/**\n\t * Stream logical transactions page by page instead of buffering the full\n\t * result set in memory.\n\t */\n\tasync *iterate(account: HistoryAccount, options?: UserHistoryListOptions): AsyncGenerator<LogicalTransaction> {\n\t\tconst externalCache = new Map<string, ResolvedTransfer | undefined>();\n\t\tconst readerCache = new Map<string, AnchorTransferReader<KeetaAssetMovementTransaction> | null>();\n\t\tconst perspective = perspectiveOf(account);\n\n\t\tlet cursor = options?.cursor;\n\t\tlet yielded = 0;\n\t\twhile (true) {\n\t\t\tconst page = await this.#fetchPage(account, cursor, options);\n\t\t\tif (page.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfor (const entry of page) {\n\t\t\t\tconst timestamp = entry.voteStaple.timestamp().toISOString();\n\t\t\t\tconst blocks: EnrichedBlock[] = [];\n\t\t\t\tconst sources = new Map<string, LogicalTransactionSource>();\n\t\t\t\tfor (const block of entry.voteStaple.blocks) {\n\t\t\t\t\tconst enriched = await this.#enrichBlock(block, timestamp, perspective, options, externalCache, readerCache);\n\t\t\t\t\tblocks.push(enriched);\n\n\t\t\t\t\tif (options?.includeSource === true) {\n\t\t\t\t\t\tsources.set(enriched.blockHash, { staple: entry.voteStaple, enriched });\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst logical = foldHistory(blocks, this.#classifiers);\n\t\t\t\tattachSources(logical, sources);\n\n\t\t\t\tfor (const transaction of logical) {\n\t\t\t\t\tyield transaction;\n\t\t\t\t\tyielded += 1;\n\n\t\t\t\t\tif (options?.limit !== undefined && yielded >= options.limit) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst last = page.at(-1);\n\t\t\tif (last === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcursor = last.voteStaple.blocksHash.toString();\n\t\t\tif (options?.limit === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Fetch one page of on-chain history.\n\t */\n\tasync #fetchPage(account: HistoryAccount, cursor: string | undefined, options?: UserHistoryListOptions): Promise<HistoryEntry[]> {\n\t\tconst query: HistoryQuery = {};\n\t\tif (options?.depth !== undefined) {\n\t\t\tquery.depth = options.depth;\n\t\t}\n\t\tif (options?.pageSize !== undefined) {\n\t\t\tquery.pageSize = options.pageSize;\n\t\t}\n\t\tif (cursor !== undefined) {\n\t\t\tquery.startBlocksHash = cursor;\n\t\t}\n\n\t\tconst result = await this.#history.getHistory(account, query);\n\t\treturn(result);\n\t}\n\n\t/**\n\t * Enrich each operation of a block with its anchor transfer, if resolvable.\n\t */\n\tasync #enrichBlock(block: Block, timestamp: string, perspective: string | undefined, options: UserHistoryListOptions | undefined, externalCache: Map<string, ResolvedTransfer | undefined>, readerCache: Map<string, AnchorTransferReader<KeetaAssetMovementTransaction> | null>): Promise<EnrichedBlock> {\n\t\tconst blockHash = block.hash.toString();\n\t\tconst account = block.account.publicKeyString.get();\n\t\tconst enrichEnabled = options?.enrich !== false && this.#status !== undefined;\n\n\t\tconst operations: EnrichedOperation[] = [];\n\t\tfor (let index = 0; index < block.operations.length; index++) {\n\t\t\tconst operation = block.operations[index];\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst enriched: EnrichedOperation = { operation, index };\n\t\t\tif (enrichEnabled) {\n\t\t\t\tconst resolved = await this.#resolveTransfer(block, operation, index, perspective, options, externalCache, readerCache);\n\t\t\t\tif (resolved !== undefined) {\n\t\t\t\t\tenriched.transfer = resolved.transfer;\n\t\t\t\t\tenriched.anchorID = resolved.anchorID;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\toperations.push(enriched);\n\t\t}\n\n\t\tconst result: EnrichedBlock = { blockHash, account, timestamp, operations };\n\t\tif (perspective !== undefined) {\n\t\t\tresult.perspective = perspective;\n\t\t}\n\n\t\treturn(result);\n\t}\n\n\t/**\n\t * Resolve one operation to its anchor transfer, preferring the SEND's own\n\t * `external` and falling back to a reverse-lookup by on-chain coordinates.\n\t */\n\tasync #resolveTransfer(block: Block, operation: BlockOperations, index: number, perspective: string | undefined, options: UserHistoryListOptions | undefined, externalCache: Map<string, ResolvedTransfer | undefined>, readerCache: Map<string, AnchorTransferReader<KeetaAssetMovementTransaction> | null>): Promise<ResolvedTransfer | undefined> {\n\t\tconst status = this.#status;\n\t\tif (status === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tif (operation.type === OperationType.SEND && operation.external !== undefined) {\n\t\t\tconst fromExternal = await this.#resolveFromExternal(status, operation.external, options, externalCache);\n\t\t\tif (fromExternal !== undefined) {\n\t\t\t\treturn(fromExternal);\n\t\t\t}\n\t\t}\n\n\t\tconst issuer = block.account.publicKeyString.get();\n\t\tlet candidateAnchor: string | undefined;\n\t\tif (perspective !== undefined && issuer !== perspective) {\n\t\t\tcandidateAnchor = issuer;\n\t\t} else {\n\t\t\tcandidateAnchor = counterpartyID(operation);\n\t\t}\n\n\t\tif (candidateAnchor === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst fromOnChain = await this.#resolveByOnChain(status, candidateAnchor, block.network, block.hash.toString(), index, options, readerCache);\n\t\treturn(fromOnChain);\n\t}\n\n\t/**\n\t * Resolve a transfer from a SEND's `external` envelope, deduped per blob.\n\t */\n\tasync #resolveFromExternal(status: AnchorTransactionStatus<KeetaAssetMovementTransaction>, external: string, options: UserHistoryListOptions | undefined, externalCache: Map<string, ResolvedTransfer | undefined>): Promise<ResolvedTransfer | undefined> {\n\t\tconst cached = externalCache.get(external);\n\t\tif (cached !== undefined || externalCache.has(external)) {\n\t\t\treturn(cached);\n\t\t}\n\n\t\tlet resolved: ResolvedTransfer | undefined;\n\t\ttry {\n\t\t\tconst results = await status.getStatusesFromExternal(external, buildExternalOptions(options));\n\t\t\tresolved = firstResolvedTransfer(results);\n\t\t} catch (error) {\n\t\t\tthis.#logger?.debug('UserHistory::resolveFromExternal', `External did not resolve to a transfer, degrading to block-shape classification: ${String(error)}`);\n\t\t\tresolved = undefined;\n\t\t}\n\n\t\texternalCache.set(external, resolved);\n\t\treturn(resolved);\n\t}\n\n\t/**\n\t * Reverse-lookup a transfer by on-chain coordinates through the anchor the\n\t * counterparty resolves to.\n\t */\n\tasync #resolveByOnChain(status: AnchorTransactionStatus<KeetaAssetMovementTransaction>, counterparty: string, networkID: bigint, blockHash: string, operationIndex: number, options: UserHistoryListOptions | undefined, readerCache: Map<string, AnchorTransferReader<KeetaAssetMovementTransaction> | null>): Promise<ResolvedTransfer | undefined> {\n\t\tconst reader = await this.#getReader(status, counterparty, readerCache);\n\t\tif (reader?.findByOnChain === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await reader.findByOnChain({ keetaNetworkID: networkID, blockHash, operationIndex }, buildStatusOptions(options));\n\t\t\tif (result === null) {\n\t\t\t\treturn(undefined);\n\t\t\t}\n\n\t\t\treturn({ anchorID: counterparty, transfer: result.transaction });\n\t\t} catch (error) {\n\t\t\tthis.#logger?.debug('UserHistory::resolveByOnChain', `Reverse-lookup at ${counterparty} for ${blockHash}:${operationIndex} failed: ${String(error)}`);\n\t\t\treturn(undefined);\n\t\t}\n\t}\n\n\t/**\n\t * Resolve and cache the reader for an anchor counterparty.\n\t */\n\tasync #getReader(status: AnchorTransactionStatus<KeetaAssetMovementTransaction>, counterparty: string, readerCache: Map<string, AnchorTransferReader<KeetaAssetMovementTransaction> | null>): Promise<AnchorTransferReader<KeetaAssetMovementTransaction> | null> {\n\t\tconst cached = readerCache.get(counterparty);\n\t\tif (cached !== undefined || readerCache.has(counterparty)) {\n\t\t\treturn(cached ?? null);\n\t\t}\n\n\t\tlet reader: AnchorTransferReader<KeetaAssetMovementTransaction> | null;\n\t\ttry {\n\t\t\tconst anchor = KeetaNetLib.Account.fromPublicKeyString(counterparty);\n\t\t\treader = await status.getReader(anchor);\n\t\t} catch (error) {\n\t\t\tthis.#logger?.debug('UserHistory::getReader', `No reader resolved for ${counterparty}: ${String(error)}`);\n\t\t\treader = null;\n\t\t}\n\n\t\treaderCache.set(counterparty, reader);\n\t\treturn(reader);\n\t}\n}\n\nexport default UserHistory;\n"]}
@@ -2,6 +2,7 @@ import * as http from 'http';
2
2
  import type { JSONSerializable } from '../utils/json.js';
3
3
  import type { Logger } from '../log/index.js';
4
4
  import type { CertificateChainConfig, ResolvedCertificateChainRequirement } from '../utils/certificate-network.js';
5
+ import { Buffer } from '../utils/buffer.js';
5
6
  export declare const AssertHTTPErrorData: (input: unknown) => {
6
7
  error: string;
7
8
  statusCode?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/http-server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAM7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EACX,sBAAsB,EACtB,mCAAmC,EACnC,MAAM,iCAAiC,CAAC;AAMzC,eAAO,MAAM,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAAkF,CAAC;AAOpM,KAAK,kBAAkB,CAAC,YAAY,GAAG,gBAAgB,GAAG,SAAS,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,CAAC,mBAAmB,EAAE,UAAU,EAAE,GAAG,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;KAAE,CAAC;CAAE,CAAC,CAAC;AAC5T,KAAK,sBAAsB,GAAG;IAC7B,QAAQ,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;CACpC,GAAG;IACH,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,C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AAG,SAAS,CAEhE;IAED;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,EAAE,GAAG,SAAS;IAS9E,OAAO,CAAC,MAAM,CAAC,UAAU;IAyEzB,OAAO,CAAC,MAAM,CAAC,SAAS;IA2CxB,OAAO,CAAC,MAAM,CAAC,OAAO;YAyHR,IAAI;IA0QlB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B;;;;;OAKG;IACH,IAAI,GAAG,IAAI,MAAM,CAoChB;IAED,IAAI,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,KAAK,MAAM,CAAC,EAGnE;IAED,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAGtC"}
@@ -5,6 +5,7 @@ import { Log } from '../log/index.js';
5
5
  import { createAssert } from 'typia';
6
6
  import { assertNever } from '../utils/never.js';
7
7
  import { resolveCertificateChainConfig } from '../utils/certificate-network.js';
8
+ import { Buffer } from '../utils/buffer.js';
8
9
  export const AssertHTTPErrorData = (() => { const _io0 = input => "string" === typeof input.error && (undefined === input.statusCode || "number" === typeof input.statusCode) && (undefined === input.contentType || "string" === typeof input.contentType); const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.error || __typia_transform__assertGuard._assertGuard(_exceptionable, {
9
10
  method: "createAssert",
10
11
  path: _path + ".error",
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/http-server/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EACN,gB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YAClC,SAAS,CAAC,QAAQ,GAAG,GAAG,CAAC;YACzB,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC;YAEtB,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YAEpC,OAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,IAAI,WAAW,CAAC;QAC1D,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,IAAI,OAAO,CAAC;QACtD,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC;QACtB,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;QAEnB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAEjC,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,IAAI,GAAG,CAAC,KAA4D;QACnE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,CAAC,MAAM,CAAC,YAAY,CAAC;QACpB,OAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACrB,CAAC;CACD","sourcesContent":["import * as http from 'http';\n\nimport {\n\tKeetaAnchorError,\n\tKeetaAnchorUserError\n} from '../error.js';\nimport type { JSONSerializable } from '../utils/json.js';\nimport type { Logger, LogLevel } from '../log/index.js';\nimport type {\n\tCertificateChainConfig,\n\tResolvedCertificateChainRequirement\n} from '../utils/certificate-network.js';\nimport { Log } from '../log/index.js';\nimport { createAssert } from 'typia';\nimport { assertNever } from '../utils/never.js';\nimport { resolveCertificateChainConfig } from '../utils/certificate-network.js';\n\nexport const AssertHTTPErrorData: (input: unknown) => { error: string; statusCode?: number; contentType?: string; } = createAssert<{ error: string; statusCode?: number; contentType?: string; }>();\n\n/**\n * The maximum size of a request (128MiB)\n */\nconst MAX_REQUEST_SIZE = 128 * (1024 ** 2);\n\ntype RouteHandlerMethod<BodyDataType = JSONSerializable | undefined> = (urlParams: Map<string, string>, postData: BodyDataType, requestHeaders: http.IncomingHttpHeaders, requestUrl: URL) => Promise<{ output: string | Buffer; statusCode?: number; contentType?: string; headers?: { [headerName: string]: string; }; }>;\ntype RouteHandlerWithConfig = {\n\tbodyType: 'raw';\n\tmaxBodySize?: number;\n\thandler: RouteHandlerMethod<Buffer>;\n} | {\n\tbodyType: 'parsed';\n\tmaxBodySize?: number;\n\thandler: RouteHandlerMethod;\n} | {\n\tbodyType: 'none';\n\thandler: RouteHandlerMethod<undefined>;\n};\ntype RouteHandler = RouteHandlerMethod | RouteHandlerWithConfig;\nexport type Routes = { [route: string]: RouteHandler };\nexport type RoutesWithConfigs = { [route: string]: RouteHandlerWithConfig };\n\nexport interface KeetaAnchorHTTPServerConfig {\n\t/**\n\t * Identifier for the server instance -- if one is not given\n\t * a random one will be generated.\n\t */\n\tid?: string;\n\n\t/**\n\t * The port for the HTTP server to listen on (default is an ephemeral port).\n\t */\n\tport?: number;\n\n\t/**\n\t * Enable debug logging\n\t */\n\tlogger?: Logger | undefined;\n\t/**\n\t * The URL for the server. By default, this will be generated based on\n\t * the port and will use \"localhost\" as the hostname, but it can be\n\t * overridden by setting this to a string, URL, or function that\n\t * generates the URL\n\t */\n\turl?: undefined | string | URL | ((object: KeetaNetAnchorHTTPServer) => string) | {\n\t\thostname?: string;\n\t\tport?: number;\n\t\tprotocol?: string;\n\t};\n\n\t/**\n\t * Optional on-chain cert-chain gate. When set, authenticated callers\n\t * MUST have a published cert chaining to one of `trustedIssuers`.\n\t */\n\trequireCertificateChain?: CertificateChainConfig | undefined;\n};\n\nexport abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaAnchorHTTPServerConfig = KeetaAnchorHTTPServerConfig> implements Required<KeetaAnchorHTTPServerConfig> {\n\treadonly port: NonNullable<KeetaAnchorHTTPServerConfig['port']>;\n\treadonly logger: NonNullable<KeetaAnchorHTTPServerConfig['logger']>;\n\treadonly id: NonNullable<KeetaAnchorHTTPServerConfig['id']>;\n\t/**\n\t * Resolved cert-chain requirement, or `undefined` when disabled.\n\t * @see {@link requireCertificateChain}.\n\t */\n\tprotected readonly resolvedCertificateChainRequirement: ResolvedCertificateChainRequirement | undefined;\n\t#serverPromise?: Promise<void>;\n\t#server?: http.Server;\n\t#urlParts: undefined | { hostname?: string; port?: number; protocol?: string; };\n\t#url: undefined | string | URL | ((object: this) => string);\n\treadonly #config: ConfigType;\n\n\tconstructor(config: ConfigType) {\n\t\tthis.#config = { ...config };\n\t\tthis.port = config.port ?? 0;\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\t\tthis.logger = config.logger ?? Log.Legacy('ANCHOR');\n\t\tthis.resolvedCertificateChainRequirement = resolveCertificateChainConfig(config.requireCertificateChain);\n\n\t\tif (config.url !== undefined) {\n\t\t\tif (config.url instanceof URL || typeof config.url === 'string') {\n\t\t\t\tthis.#url = config.url;\n\t\t\t\tthis.#urlParts = undefined;\n\t\t\t} else if (typeof config.url === 'function') {\n\t\t\t\t/**\n\t\t\t\t * The parameter for the call back is typed as\n\t\t\t\t * `this`, which means any subclass is typed\n\t\t\t\t * but the interface can't identify that --\n\t\t\t\t * instead it types it as the base class\n\t\t\t\t * (KeetaNetAnchorHTTPServer), which means it\n\t\t\t\t * can't be assigned to the type of `#url`\n\t\t\t\t * without overriding the type check. However,\n\t\t\t\t * we know that `this` will be at least\n\t\t\t\t * compatible with the base class.\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.#url = config.url;\n\t\t\t\tthis.#urlParts = undefined;\n\t\t\t} else {\n\t\t\t\tthis.#url = undefined;\n\t\t\t\tthis.#urlParts = config.url;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected abstract initRoutes(config: ConfigType): Promise<Routes>;\n\n\t/**\n\t * Public view of the cert-chain config, or `undefined` when disabled.\n\t */\n\tget requireCertificateChain(): CertificateChainConfig | undefined {\n\t\treturn(this.resolvedCertificateChainRequirement);\n\t}\n\n\t/**\n\t * Trusted-issuer DNs metadata. Is `undefined` when the gate is not configured.\n\t */\n\tprotected acceptedIssuerDNs(): { name: string; value: string }[][] | undefined {\n\t\tconst requirement = this.resolvedCertificateChainRequirement;\n\t\tif (requirement === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(requirement.acceptedIssuerDNs);\n\t}\n\n\tprivate static routeMatch(requestURL: URL, routeURL: URL): ({ match: true; params: Map<string, string>; wildcard?: { prefixLength: number }} | { match: false }) {\n\t\tconst requestURLPaths = requestURL.pathname.split('/');\n\t\tconst routeURLPaths = routeURL.pathname.split('/');\n\n\t\t// Check if route ends with wildcard /**\n\t\tconst isWildcard = routeURLPaths.length > 0 && routeURLPaths[routeURLPaths.length - 1] === '**';\n\t\tif (isWildcard) {\n\t\t\t// For wildcard routes, request must have more segments than route prefix (minus the **)\n\t\t\t// This ensures at least one segment is captured by the wildcard\n\t\t\tconst prefixLength = routeURLPaths.length - 1;\n\t\t\tif (requestURLPaths.length <= prefixLength) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\t// Check that prefix segments match\n\t\t\tconst params = new Map<string, string>();\n\t\t\tfor (let partIndex = 0; partIndex < prefixLength; partIndex++) {\n\t\t\t\tconst requestPath = requestURLPaths[partIndex];\n\n\t\t\t\tconst routePath = routeURLPaths[partIndex];\n\t\t\t\tif (routePath === undefined || requestPath === undefined) {\n\t\t\t\t\treturn({ match: false });\n\t\t\t\t}\n\n\t\t\t\tif (routePath.startsWith(':')) {\n\t\t\t\t\tparams.set(routePath.slice(1), requestPath);\n\t\t\t\t} else if (requestPath !== routePath) {\n\t\t\t\t\treturn({ match: false });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Capture the remainder as the wildcard param\n\t\t\t// Filter empty segments to handle trailing slashes correctly\n\t\t\tconst remainder = requestURLPaths.slice(prefixLength)\n\t\t\t\t.filter(function(s) {\n\t\t\t\t\treturn(s !== '');\n\t\t\t\t})\n\t\t\t\t.join('/');\n\n\t\t\tif (remainder === '') {\n\t\t\t\t// Reject if wildcard would capture nothing\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\tparams.set('**', remainder);\n\n\t\t\treturn({ match: true, params: params, wildcard: { prefixLength }});\n\t\t}\n\n\t\t// Non-wildcard: require exact segment count\n\t\tif (requestURLPaths.length !== routeURLPaths.length) {\n\t\t\treturn({ match: false });\n\t\t}\n\n\t\tconst params = new Map<string, string>();\n\t\tfor (let partIndex = 0; partIndex < requestURLPaths.length; partIndex++) {\n\t\t\tconst requestPath = requestURLPaths[partIndex];\n\t\t\tconst routePath = routeURLPaths[partIndex];\n\n\t\t\tif (routePath === undefined || requestPath === undefined) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\tif (routePath.startsWith(':')) {\n\t\t\t\tparams.set(routePath.slice(1), requestPath);\n\t\t\t} else if (requestPath !== routePath) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\t\t}\n\n\t\treturn({ match: true, params: params });\n\t}\n\n\tprivate static routeFind(method: string, requestURL: URL, routes: Routes): { route: Routes[keyof Routes]; params: Map<string, string> } | null {\n\t\tlet wildcardMatch: { route: Routes[keyof Routes]; params: Map<string, string> } | null = null;\n\t\tlet wildcardPrefixLength = -1;\n\n\t\tfor (const routeKey in routes) {\n\t\t\tconst route = routes[routeKey];\n\t\t\tif (route === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst [routeMethod, ...routePathParts] = routeKey.split(' ');\n\t\t\tconst routePath = `/${routePathParts.join(' ')}`.replace(/^\\/+/, '/');\n\n\t\t\tif (method !== routeMethod) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst routeURL = new URL(routePath, 'http://localhost');\n\t\t\tconst matchResult = this.routeMatch(requestURL, routeURL);\n\t\t\tif (matchResult.match) {\n\t\t\t\t// Exact matches take priority over wildcard matches\n\t\t\t\tif (matchResult.wildcard === undefined) {\n\t\t\t\t\treturn({\n\t\t\t\t\t\troute: route,\n\t\t\t\t\t\tparams: matchResult.params\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Keep the most specific wildcard (longest prefix wins)\n\t\t\t\tif (matchResult.wildcard.prefixLength > wildcardPrefixLength) {\n\t\t\t\t\twildcardPrefixLength = matchResult.wildcard.prefixLength;\n\t\t\t\t\twildcardMatch = {\n\t\t\t\t\t\troute: route,\n\t\t\t\t\t\tparams: matchResult.params\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Return most specific wildcard match if no exact match found\n\t\treturn(wildcardMatch);\n\t}\n\n\tprivate static addCORS(routes: Routes): RoutesWithConfigs {\n\t\tconst newRoutes: RoutesWithConfigs = {};\n\n\t\tconst validMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']);\n\n\t\tconst methodsByPath: { [key: string]: Set<string>; } = {};\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!validMethods.has(method)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!(path in methodsByPath)) {\n\t\t\t\tmethodsByPath[path] = new Set<string>();\n\t\t\t}\n\n\t\t\tif (methodsByPath[path] === undefined) {\n\t\t\t\tthrow(new Error(`internal error: methodsByPath missing path for ${path}`));\n\t\t\t}\n\n\t\t\tmethodsByPath[path].add(method);\n\t\t}\n\n\t\tconst seenPaths = new Set<string>();\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tconst routeHandler = routes[routeKey];\n\t\t\tif (routeHandler === undefined) {\n\t\t\t\tthrow(new Error(`internal error: routeHandler missing for routeKey ${routeKey}`));\n\t\t\t}\n\n\t\t\tlet newRoute: RouteHandlerWithConfig;\n\n\t\t\tif (typeof routeHandler === 'function') {\n\t\t\t\tnewRoute = {\n\t\t\t\t\tbodyType: 'parsed',\n\t\t\t\t\thandler: routeHandler\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tnewRoute = routeHandler;\n\t\t\t}\n\n\t\t\tif (method !== 'ERROR') {\n\t\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\t\tnewRoutes[routeKey] = newRoute;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!validMethods.has(method)) {\n\t\t\t\t\tnewRoutes[routeKey] = newRoute;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst validMethodsForPath = methodsByPath[path];\n\n\t\t\tlet validMethodsForPathParts: string[] = [];\n\t\t\tif (validMethodsForPath !== undefined) {\n\t\t\t\tvalidMethodsForPath.add('OPTIONS');\n\t\t\t\tvalidMethodsForPathParts = Array.from(validMethodsForPath);\n\t\t\t} else {\n\t\t\t\tvalidMethodsForPathParts = [...Array.from(validMethods), 'OPTIONS'];\n\t\t\t}\n\n\t\t\tnewRoutes[routeKey] = {\n\t\t\t\t...newRoute,\n\t\t\t\tasync handler(...args: Parameters<RouteHandlerMethod<unknown>>) {\n\t\t\t\t\t// This is typed properly, but TS can't infer it here\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst retval = await newRoute.handler(...args);\n\n\t\t\t\t\t/* Add CORS headers to the response for the original route handler */\n\t\t\t\t\tif (retval.contentType === 'application/json' || retval.contentType === undefined) {\n\t\t\t\t\t\tif (!('headers' in retval) || retval.headers === undefined) {\n\t\t\t\t\t\t\tretval.headers = {};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tretval.headers['Access-Control-Allow-Origin'] = '*';\n\t\t\t\t\t}\n\n\t\t\t\t\treturn(retval);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (!seenPaths.has(path) && path !== '' && path !== undefined) {\n\t\t\t\tconst corsRouteKey = `OPTIONS ${path}`;\n\n\t\t\t\tnewRoutes[corsRouteKey] = {\n\t\t\t\t\tbodyType: 'none',\n\t\t\t\t\tasync handler() {\n\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\toutput: '',\n\t\t\t\t\t\t\tstatusCode: 204,\n\t\t\t\t\t\t\tcontentType: 'text/plain',\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t'Access-Control-Allow-Origin': '*',\n\t\t\t\t\t\t\t\t'Access-Control-Allow-Methods': validMethodsForPathParts.join(', '),\n\t\t\t\t\t\t\t\t'Access-Control-Allow-Headers': 'Content-Type',\n\t\t\t\t\t\t\t\t'Access-Control-Max-Age': '86400'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tseenPaths.add(path);\n\t\t\t}\n\t\t}\n\n\t\treturn(newRoutes);\n\t}\n\n\tprivate async main(onSetPort?: (port: number) => void): Promise<void> {\n\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Starting HTTP server...');\n\n\t\tconst port = this.port;\n\n\t\tconst routes = KeetaNetAnchorHTTPServer.addCORS({\n\t\t\tERROR: async function(_ignore_params, postData) {\n\t\t\t\tconst errorInfo = AssertHTTPErrorData(postData);\n\n\t\t\t\tconst retval = {\n\t\t\t\t\toutput: errorInfo.error,\n\t\t\t\t\tstatusCode: errorInfo.statusCode ?? 400,\n\t\t\t\t\tcontentType: errorInfo.contentType ?? 'text/plain'\n\t\t\t\t};\n\n\t\t\t\treturn(retval);\n\t\t\t},\n\t\t\t...(await this.initRoutes(this.#config))\n\t\t});\n\n\t\tconst server = new http.Server(async (request, response) => {\n\t\t\t/*\n\t\t\t * Get the Base URL from the request Host header (if\n\t\t\t * available) or default to localhost. This is used\n\t\t\t * to construct the full URL for routing.\n\t\t\t */\n\t\t\tconst inputURLBaseRaw = new URL(`http://${request.headers.host ?? 'localhost'}`);\n\t\t\tconst inputURLBase = inputURLBaseRaw.protocol + '//' + inputURLBaseRaw.host;\n\n\t\t\t/*\n\t\t\t * Normalize the input URL by stripping leading slashes and\n\t\t\t * combining it with the base URL to get the full URL for routing.\n\t\t\t */\n\t\t\tconst inputURLRaw = (request.url ?? '/').replace(/^\\/+/, '/');\n\t\t\tconst inputURLObject = new URL(inputURLRaw, 'http://localhost');\n\t\t\tconst inputURL = inputURLObject.pathname + (function() {\n\t\t\t\tif (inputURLObject.search === '') {\n\t\t\t\t\treturn('');\n\t\t\t\t}\n\n\t\t\t\treturn('?' + inputURLObject.searchParams.toString());\n\t\t\t})();\n\t\t\tconst url = new URL(inputURL, inputURLBase);\n\t\t\tconst method = request.method ?? 'GET';\n\n\t\t\t/*\n\t\t\t * Finalize the response by syncing the logger and ending\n\t\t\t * the response.\n\t\t\t */\n\t\t\tconst responseFinalize = async () => {\n\t\t\t\tif ('sync' in this.logger && typeof this.logger.sync === 'function') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.logger.sync();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t/* ignore errors */\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tresponse.end();\n\t\t\t};\n\n\t\t\t/*\n\t\t\t * If the request is malformed, reject it immediately\n\t\t\t */\n\t\t\tif (inputURLRaw.at(0) !== '/') {\n\t\t\t\tresponse.statusCode = 400;\n\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\tresponse.write('Bad Request');\n\t\t\t\tawait responseFinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Lookup the route based on the request\n\t\t\t */\n\t\t\tconst requestedRouteAndParams = KeetaNetAnchorHTTPServer.routeFind(method, url, routes);\n\t\t\tif (requestedRouteAndParams === null) {\n\t\t\t\tresponse.statusCode = 404;\n\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\tresponse.write('Not Found');\n\t\t\t\tawait responseFinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Extract the route handler and the parameters from\n\t\t\t * the request\n\t\t\t */\n\t\t\tconst { route, params } = requestedRouteAndParams;\n\n\t\t\t/**\n\t\t\t * Attempt to run the route, catch any errors\n\t\t\t */\n\t\t\tlet result: Awaited<ReturnType<RouteHandlerMethod>> | undefined = undefined;\n\t\t\tlet generatedResult = false;\n\t\t\ttry {\n\t\t\t\tif (!request.method) {\n\t\t\t\t\tthrow(new Error('internal error: No request method'));\n\t\t\t\t}\n\n\t\t\t\tlet bodyData: JSONSerializable | Buffer | undefined;\n\n\t\t\t\tconst shouldCheckBody = ['POST', 'PUT', 'PATCH', 'DELETE'].includes(request.method);\n\n\t\t\t\tif (typeof route === 'function') {\n\t\t\t\t\tthrow(new Error('internal error: Route handler missing body type configuration, should have been added in addCORS'));\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * If POST'ing, PUT'ing, or PATCH'ing, read and parse the request body\n\t\t\t\t */\n\t\t\t\tif (shouldCheckBody && route.bodyType !== 'none') {\n\t\t\t\t\tconst bodySizeLimit = route.maxBodySize ?? MAX_REQUEST_SIZE;\n\n\t\t\t\t\t// Early rejection based on Content-Length header\n\t\t\t\t\tconst contentLength = request.headers['content-length'];\n\t\t\t\t\tif (contentLength !== undefined) {\n\t\t\t\t\t\tconst declaredSize = parseInt(contentLength, 10);\n\t\t\t\t\t\tif (!isNaN(declaredSize) && declaredSize > bodySizeLimit) {\n\t\t\t\t\t\t\trequest.resume();\n\n\t\t\t\t\t\t\tresponse.statusCode = 413;\n\t\t\t\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\t\t\t\tresponse.write('Payload Too Large');\n\n\t\t\t\t\t\t\tawait responseFinalize();\n\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst data = await request.map(function(chunk) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\t\t\treturn(Buffer.from(chunk));\n\t\t\t\t\t}).reduce(function(prev, curr) {\n\t\t\t\t\t\tif (prev.length > bodySizeLimit) {\n\t\t\t\t\t\t\tthrow(new Error('Request too large'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!Buffer.isBuffer(curr)) {\n\t\t\t\t\t\t\tthrow(new Error(`internal error: Current item is not a buffer -- ${typeof curr}`));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn(Buffer.concat([prev, curr]));\n\t\t\t\t\t}, Buffer.from(''));\n\n\t\t\t\t\tif (route.bodyType === 'raw') {\n\t\t\t\t\t\tbodyData = data;\n\t\t\t\t\t} else if (route.bodyType === 'parsed' && request.headers['content-type'] === 'application/json') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\t\t\tbodyData = JSON.parse(data.toString('utf-8'));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow(new Error('Invalid JSON data'));\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (data.length > 0) {\n\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Unsupported content type'));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * Call the route handler\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\tresult = await route.handler(params, bodyData, request.headers, url);\n\n\t\t\t\tgeneratedResult = true;\n\t\t\t} catch (err) {\n\t\t\t\tlet logLevel: Lowercase<LogLevel> = 'error';\n\t\t\t\tif (KeetaAnchorError.isInstance(err)) {\n\t\t\t\t\t/*\n\t\t\t\t\t * We're able to safely cast this here because the cast\n\t\t\t\t\t * duplicates the logic.\n\t\t\t\t\t */\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tlogLevel = err.logLevel.toLowerCase() as Lowercase<typeof err.logLevel>;\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * If an error occurs, log it and return an error page\n\t\t\t\t */\n\t\t\t\tthis.logger?.[logLevel]('KeetaAnchorHTTP.Server', err);\n\n\t\t\t\t/**\n\t\t\t\t * If it is a user error, provide a user-friendly error page\n\t\t\t\t */\n\t\t\t\tconst errorHandlerRoute = routes['ERROR'];\n\t\t\t\tif (errorHandlerRoute !== undefined) {\n\t\t\t\t\tlet errBody;\n\t\t\t\t\tif (KeetaAnchorError.isInstance(err) && err['userError']) {\n\t\t\t\t\t\terrBody = err.asErrorResponse('application/json');\n\t\t\t\t\t} else {\n\t\t\t\t\t\terrBody = {\n\t\t\t\t\t\t\terror: JSON.stringify({ ok: false, error: 'Internal Server Error' }),\n\t\t\t\t\t\t\tstatusCode: 500,\n\t\t\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tresult = await errorHandlerRoute.handler(new Map(), errBody, request.headers, url);\n\t\t\t\t\tgeneratedResult = true;\n\t\t\t\t}\n\n\t\t\t\tif (!generatedResult) {\n\t\t\t\t\t/**\n\t\t\t\t\t * Otherwise provide a generic error page\n\t\t\t\t\t */\n\t\t\t\t\tresponse.statusCode = 500;\n\t\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\t\tresponse.write('Internal Server Error');\n\t\t\t\t\tawait responseFinalize();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (result === undefined) {\n\t\t\t\tthrow(new Error('internal error: No result'));\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Write the response to the client\n\t\t\t */\n\t\t\tresponse.statusCode = result.statusCode ?? 200;\n\n\t\t\tfor (const headerKey in result.headers ?? {}) {\n\t\t\t\tconst headerValue = result.headers?.[headerKey];\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tresponse.setHeader(headerKey, headerValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresponse.setHeader('Content-Type', result.contentType ?? 'application/json');\n\t\t\tresponse.write(result.output);\n\t\t\tawait responseFinalize();\n\t\t});\n\t\tthis.#server = server;\n\n\t\t/**\n\t\t * Create a promise to wait for the server to close\n\t\t */\n\t\tconst waiter = new Promise<void>((resolve) => {\n\t\t\tserver.on('close', () => {\n\t\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Server closed');\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\t/**\n\t\t * Start listening on the port\n\t\t */\n\t\tserver.listen(port, () => {\n\t\t\tconst address = server.address();\n\t\t\tif (address !== null && typeof address === 'object') {\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.port = address.port;\n\t\t\t\tonSetPort?.(this.port);\n\t\t\t}\n\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Listening on port:', this.port);\n\t\t});\n\n\t\t/**\n\t\t * Wait for the server to close\n\t\t */\n\t\tawait waiter;\n\t}\n\n\t/**\n\t * Start the HTTP server and wait for it to be fully initialized.\n\t */\n\tasync start(): Promise<void> {\n\t\t/*\n\t\t * Start the server and wait for it to be initialized before returning\n\t\t */\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.#serverPromise = this.main(function() {\n\t\t\t\tresolve();\n\t\t\t}).catch(function(error: unknown) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n\t\t\t\treject(error);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Wait for the server to terminate. This will only resolve once the\n\t * server has been stopped.\n\t */\n\tasync wait(): Promise<void> {\n\t\tawait this.#serverPromise;\n\t}\n\n\t/**\n\t * Stop the HTTP server and wait for it to be fully terminated.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.#server?.close();\n\t\t// @ts-ignore\n\t\tthis.#server = undefined;\n\t\tawait this.wait();\n\t}\n\n\t/**\n\t * Get the URL of the server, which can be used to make requests to\n\t * it. This will use \"localhost\" as the hostname and the port that\n\t * the server is listening on by default but can be overridden by\n\t * setting a custom URL.\n\t */\n\tget url(): string {\n\t\tif (this.port === 0 || this.#server === undefined) {\n\t\t\tthrow(new Error('Server not started'));\n\t\t}\n\n\t\tif (this.#url !== undefined) {\n\t\t\tlet newURL: string;\n\t\t\tif (typeof this.#url === 'string') {\n\t\t\t\tnewURL = this.#url;\n\t\t\t} else if (this.#url instanceof URL || ('port' in this.#url && 'hostname' in this.#url && 'toString' in this.#url)) {\n\t\t\t\tnewURL = this.#url.toString();\n\t\t\t} else if (typeof this.#url === 'function') {\n\t\t\t\tnewURL = this.#url(this);\n\t\t\t} else {\n\t\t\t\tassertNever(this.#url);\n\t\t\t}\n\n\t\t\tconst newURLObj = new URL(newURL);\n\t\t\tnewURLObj.pathname = '/';\n\t\t\tnewURLObj.search = '';\n\n\t\t\tconst retval = newURLObj.toString();\n\n\t\t\treturn(retval);\n\t\t}\n\n\t\tconst urlObj = new URL('http://localhost');\n\t\turlObj.port = String(this.#urlParts?.port ?? this.port);\n\t\turlObj.hostname = this.#urlParts?.hostname ?? 'localhost';\n\t\turlObj.protocol = this.#urlParts?.protocol ?? 'http:';\n\t\turlObj.pathname = '/';\n\t\turlObj.search = '';\n\n\t\tconst retval = urlObj.toString();\n\n\t\treturn(retval);\n\t}\n\n\tset url(value: undefined | string | URL | ((object: this) => string)) {\n\t\tthis.#urlParts = undefined;\n\t\tthis.#url = value;\n\t}\n\n\t[Symbol.asyncDispose](): Promise<void> {\n\t\treturn(this.stop());\n\t}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/http-server/index.ts"],"names":[],"mappings":";AAAA,OAA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C,IAAI,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;YAClC,SAAS,CAAC,QAAQ,GAAG,GAAG,CAAC;YACzB,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC;YAEtB,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YAEpC,OAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,IAAI,WAAW,CAAC;QAC1D,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,IAAI,OAAO,CAAC;QACtD,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC;QACtB,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;QAEnB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAEjC,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,IAAI,GAAG,CAAC,KAA4D;QACnE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,CAAC,MAAM,CAAC,YAAY,CAAC;QACpB,OAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACrB,CAAC;CACD","sourcesContent":["import * as http from 'http';\n\nimport {\n\tKeetaAnchorError,\n\tKeetaAnchorUserError\n} from '../error.js';\nimport type { JSONSerializable } from '../utils/json.js';\nimport type { Logger, LogLevel } from '../log/index.js';\nimport type {\n\tCertificateChainConfig,\n\tResolvedCertificateChainRequirement\n} from '../utils/certificate-network.js';\nimport { Log } from '../log/index.js';\nimport { createAssert } from 'typia';\nimport { assertNever } from '../utils/never.js';\nimport { resolveCertificateChainConfig } from '../utils/certificate-network.js';\nimport { Buffer } from '../utils/buffer.js';\n\nexport const AssertHTTPErrorData: (input: unknown) => { error: string; statusCode?: number; contentType?: string; } = createAssert<{ error: string; statusCode?: number; contentType?: string; }>();\n\n/**\n * The maximum size of a request (128MiB)\n */\nconst MAX_REQUEST_SIZE = 128 * (1024 ** 2);\n\ntype RouteHandlerMethod<BodyDataType = JSONSerializable | undefined> = (urlParams: Map<string, string>, postData: BodyDataType, requestHeaders: http.IncomingHttpHeaders, requestUrl: URL) => Promise<{ output: string | Buffer; statusCode?: number; contentType?: string; headers?: { [headerName: string]: string; }; }>;\ntype RouteHandlerWithConfig = {\n\tbodyType: 'raw';\n\tmaxBodySize?: number;\n\thandler: RouteHandlerMethod<Buffer>;\n} | {\n\tbodyType: 'parsed';\n\tmaxBodySize?: number;\n\thandler: RouteHandlerMethod;\n} | {\n\tbodyType: 'none';\n\thandler: RouteHandlerMethod<undefined>;\n};\ntype RouteHandler = RouteHandlerMethod | RouteHandlerWithConfig;\nexport type Routes = { [route: string]: RouteHandler };\nexport type RoutesWithConfigs = { [route: string]: RouteHandlerWithConfig };\n\nexport interface KeetaAnchorHTTPServerConfig {\n\t/**\n\t * Identifier for the server instance -- if one is not given\n\t * a random one will be generated.\n\t */\n\tid?: string;\n\n\t/**\n\t * The port for the HTTP server to listen on (default is an ephemeral port).\n\t */\n\tport?: number;\n\n\t/**\n\t * Enable debug logging\n\t */\n\tlogger?: Logger | undefined;\n\t/**\n\t * The URL for the server. By default, this will be generated based on\n\t * the port and will use \"localhost\" as the hostname, but it can be\n\t * overridden by setting this to a string, URL, or function that\n\t * generates the URL\n\t */\n\turl?: undefined | string | URL | ((object: KeetaNetAnchorHTTPServer) => string) | {\n\t\thostname?: string;\n\t\tport?: number;\n\t\tprotocol?: string;\n\t};\n\n\t/**\n\t * Optional on-chain cert-chain gate. When set, authenticated callers\n\t * MUST have a published cert chaining to one of `trustedIssuers`.\n\t */\n\trequireCertificateChain?: CertificateChainConfig | undefined;\n};\n\nexport abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaAnchorHTTPServerConfig = KeetaAnchorHTTPServerConfig> implements Required<KeetaAnchorHTTPServerConfig> {\n\treadonly port: NonNullable<KeetaAnchorHTTPServerConfig['port']>;\n\treadonly logger: NonNullable<KeetaAnchorHTTPServerConfig['logger']>;\n\treadonly id: NonNullable<KeetaAnchorHTTPServerConfig['id']>;\n\t/**\n\t * Resolved cert-chain requirement, or `undefined` when disabled.\n\t * @see {@link requireCertificateChain}.\n\t */\n\tprotected readonly resolvedCertificateChainRequirement: ResolvedCertificateChainRequirement | undefined;\n\t#serverPromise?: Promise<void>;\n\t#server?: http.Server;\n\t#urlParts: undefined | { hostname?: string; port?: number; protocol?: string; };\n\t#url: undefined | string | URL | ((object: this) => string);\n\treadonly #config: ConfigType;\n\n\tconstructor(config: ConfigType) {\n\t\tthis.#config = { ...config };\n\t\tthis.port = config.port ?? 0;\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\t\tthis.logger = config.logger ?? Log.Legacy('ANCHOR');\n\t\tthis.resolvedCertificateChainRequirement = resolveCertificateChainConfig(config.requireCertificateChain);\n\n\t\tif (config.url !== undefined) {\n\t\t\tif (config.url instanceof URL || typeof config.url === 'string') {\n\t\t\t\tthis.#url = config.url;\n\t\t\t\tthis.#urlParts = undefined;\n\t\t\t} else if (typeof config.url === 'function') {\n\t\t\t\t/**\n\t\t\t\t * The parameter for the call back is typed as\n\t\t\t\t * `this`, which means any subclass is typed\n\t\t\t\t * but the interface can't identify that --\n\t\t\t\t * instead it types it as the base class\n\t\t\t\t * (KeetaNetAnchorHTTPServer), which means it\n\t\t\t\t * can't be assigned to the type of `#url`\n\t\t\t\t * without overriding the type check. However,\n\t\t\t\t * we know that `this` will be at least\n\t\t\t\t * compatible with the base class.\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.#url = config.url;\n\t\t\t\tthis.#urlParts = undefined;\n\t\t\t} else {\n\t\t\t\tthis.#url = undefined;\n\t\t\t\tthis.#urlParts = config.url;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected abstract initRoutes(config: ConfigType): Promise<Routes>;\n\n\t/**\n\t * Public view of the cert-chain config, or `undefined` when disabled.\n\t */\n\tget requireCertificateChain(): CertificateChainConfig | undefined {\n\t\treturn(this.resolvedCertificateChainRequirement);\n\t}\n\n\t/**\n\t * Trusted-issuer DNs metadata. Is `undefined` when the gate is not configured.\n\t */\n\tprotected acceptedIssuerDNs(): { name: string; value: string }[][] | undefined {\n\t\tconst requirement = this.resolvedCertificateChainRequirement;\n\t\tif (requirement === undefined) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(requirement.acceptedIssuerDNs);\n\t}\n\n\tprivate static routeMatch(requestURL: URL, routeURL: URL): ({ match: true; params: Map<string, string>; wildcard?: { prefixLength: number }} | { match: false }) {\n\t\tconst requestURLPaths = requestURL.pathname.split('/');\n\t\tconst routeURLPaths = routeURL.pathname.split('/');\n\n\t\t// Check if route ends with wildcard /**\n\t\tconst isWildcard = routeURLPaths.length > 0 && routeURLPaths[routeURLPaths.length - 1] === '**';\n\t\tif (isWildcard) {\n\t\t\t// For wildcard routes, request must have more segments than route prefix (minus the **)\n\t\t\t// This ensures at least one segment is captured by the wildcard\n\t\t\tconst prefixLength = routeURLPaths.length - 1;\n\t\t\tif (requestURLPaths.length <= prefixLength) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\t// Check that prefix segments match\n\t\t\tconst params = new Map<string, string>();\n\t\t\tfor (let partIndex = 0; partIndex < prefixLength; partIndex++) {\n\t\t\t\tconst requestPath = requestURLPaths[partIndex];\n\n\t\t\t\tconst routePath = routeURLPaths[partIndex];\n\t\t\t\tif (routePath === undefined || requestPath === undefined) {\n\t\t\t\t\treturn({ match: false });\n\t\t\t\t}\n\n\t\t\t\tif (routePath.startsWith(':')) {\n\t\t\t\t\tparams.set(routePath.slice(1), requestPath);\n\t\t\t\t} else if (requestPath !== routePath) {\n\t\t\t\t\treturn({ match: false });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Capture the remainder as the wildcard param\n\t\t\t// Filter empty segments to handle trailing slashes correctly\n\t\t\tconst remainder = requestURLPaths.slice(prefixLength)\n\t\t\t\t.filter(function(s) {\n\t\t\t\t\treturn(s !== '');\n\t\t\t\t})\n\t\t\t\t.join('/');\n\n\t\t\tif (remainder === '') {\n\t\t\t\t// Reject if wildcard would capture nothing\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\tparams.set('**', remainder);\n\n\t\t\treturn({ match: true, params: params, wildcard: { prefixLength }});\n\t\t}\n\n\t\t// Non-wildcard: require exact segment count\n\t\tif (requestURLPaths.length !== routeURLPaths.length) {\n\t\t\treturn({ match: false });\n\t\t}\n\n\t\tconst params = new Map<string, string>();\n\t\tfor (let partIndex = 0; partIndex < requestURLPaths.length; partIndex++) {\n\t\t\tconst requestPath = requestURLPaths[partIndex];\n\t\t\tconst routePath = routeURLPaths[partIndex];\n\n\t\t\tif (routePath === undefined || requestPath === undefined) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\tif (routePath.startsWith(':')) {\n\t\t\t\tparams.set(routePath.slice(1), requestPath);\n\t\t\t} else if (requestPath !== routePath) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\t\t}\n\n\t\treturn({ match: true, params: params });\n\t}\n\n\tprivate static routeFind(method: string, requestURL: URL, routes: Routes): { route: Routes[keyof Routes]; params: Map<string, string> } | null {\n\t\tlet wildcardMatch: { route: Routes[keyof Routes]; params: Map<string, string> } | null = null;\n\t\tlet wildcardPrefixLength = -1;\n\n\t\tfor (const routeKey in routes) {\n\t\t\tconst route = routes[routeKey];\n\t\t\tif (route === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst [routeMethod, ...routePathParts] = routeKey.split(' ');\n\t\t\tconst routePath = `/${routePathParts.join(' ')}`.replace(/^\\/+/, '/');\n\n\t\t\tif (method !== routeMethod) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst routeURL = new URL(routePath, 'http://localhost');\n\t\t\tconst matchResult = this.routeMatch(requestURL, routeURL);\n\t\t\tif (matchResult.match) {\n\t\t\t\t// Exact matches take priority over wildcard matches\n\t\t\t\tif (matchResult.wildcard === undefined) {\n\t\t\t\t\treturn({\n\t\t\t\t\t\troute: route,\n\t\t\t\t\t\tparams: matchResult.params\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Keep the most specific wildcard (longest prefix wins)\n\t\t\t\tif (matchResult.wildcard.prefixLength > wildcardPrefixLength) {\n\t\t\t\t\twildcardPrefixLength = matchResult.wildcard.prefixLength;\n\t\t\t\t\twildcardMatch = {\n\t\t\t\t\t\troute: route,\n\t\t\t\t\t\tparams: matchResult.params\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Return most specific wildcard match if no exact match found\n\t\treturn(wildcardMatch);\n\t}\n\n\tprivate static addCORS(routes: Routes): RoutesWithConfigs {\n\t\tconst newRoutes: RoutesWithConfigs = {};\n\n\t\tconst validMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']);\n\n\t\tconst methodsByPath: { [key: string]: Set<string>; } = {};\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!validMethods.has(method)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!(path in methodsByPath)) {\n\t\t\t\tmethodsByPath[path] = new Set<string>();\n\t\t\t}\n\n\t\t\tif (methodsByPath[path] === undefined) {\n\t\t\t\tthrow(new Error(`internal error: methodsByPath missing path for ${path}`));\n\t\t\t}\n\n\t\t\tmethodsByPath[path].add(method);\n\t\t}\n\n\t\tconst seenPaths = new Set<string>();\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tconst routeHandler = routes[routeKey];\n\t\t\tif (routeHandler === undefined) {\n\t\t\t\tthrow(new Error(`internal error: routeHandler missing for routeKey ${routeKey}`));\n\t\t\t}\n\n\t\t\tlet newRoute: RouteHandlerWithConfig;\n\n\t\t\tif (typeof routeHandler === 'function') {\n\t\t\t\tnewRoute = {\n\t\t\t\t\tbodyType: 'parsed',\n\t\t\t\t\thandler: routeHandler\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tnewRoute = routeHandler;\n\t\t\t}\n\n\t\t\tif (method !== 'ERROR') {\n\t\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\t\tnewRoutes[routeKey] = newRoute;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!validMethods.has(method)) {\n\t\t\t\t\tnewRoutes[routeKey] = newRoute;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst validMethodsForPath = methodsByPath[path];\n\n\t\t\tlet validMethodsForPathParts: string[] = [];\n\t\t\tif (validMethodsForPath !== undefined) {\n\t\t\t\tvalidMethodsForPath.add('OPTIONS');\n\t\t\t\tvalidMethodsForPathParts = Array.from(validMethodsForPath);\n\t\t\t} else {\n\t\t\t\tvalidMethodsForPathParts = [...Array.from(validMethods), 'OPTIONS'];\n\t\t\t}\n\n\t\t\tnewRoutes[routeKey] = {\n\t\t\t\t...newRoute,\n\t\t\t\tasync handler(...args: Parameters<RouteHandlerMethod<unknown>>) {\n\t\t\t\t\t// This is typed properly, but TS can't infer it here\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst retval = await newRoute.handler(...args);\n\n\t\t\t\t\t/* Add CORS headers to the response for the original route handler */\n\t\t\t\t\tif (retval.contentType === 'application/json' || retval.contentType === undefined) {\n\t\t\t\t\t\tif (!('headers' in retval) || retval.headers === undefined) {\n\t\t\t\t\t\t\tretval.headers = {};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tretval.headers['Access-Control-Allow-Origin'] = '*';\n\t\t\t\t\t}\n\n\t\t\t\t\treturn(retval);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (!seenPaths.has(path) && path !== '' && path !== undefined) {\n\t\t\t\tconst corsRouteKey = `OPTIONS ${path}`;\n\n\t\t\t\tnewRoutes[corsRouteKey] = {\n\t\t\t\t\tbodyType: 'none',\n\t\t\t\t\tasync handler() {\n\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\toutput: '',\n\t\t\t\t\t\t\tstatusCode: 204,\n\t\t\t\t\t\t\tcontentType: 'text/plain',\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t'Access-Control-Allow-Origin': '*',\n\t\t\t\t\t\t\t\t'Access-Control-Allow-Methods': validMethodsForPathParts.join(', '),\n\t\t\t\t\t\t\t\t'Access-Control-Allow-Headers': 'Content-Type',\n\t\t\t\t\t\t\t\t'Access-Control-Max-Age': '86400'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tseenPaths.add(path);\n\t\t\t}\n\t\t}\n\n\t\treturn(newRoutes);\n\t}\n\n\tprivate async main(onSetPort?: (port: number) => void): Promise<void> {\n\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Starting HTTP server...');\n\n\t\tconst port = this.port;\n\n\t\tconst routes = KeetaNetAnchorHTTPServer.addCORS({\n\t\t\tERROR: async function(_ignore_params, postData) {\n\t\t\t\tconst errorInfo = AssertHTTPErrorData(postData);\n\n\t\t\t\tconst retval = {\n\t\t\t\t\toutput: errorInfo.error,\n\t\t\t\t\tstatusCode: errorInfo.statusCode ?? 400,\n\t\t\t\t\tcontentType: errorInfo.contentType ?? 'text/plain'\n\t\t\t\t};\n\n\t\t\t\treturn(retval);\n\t\t\t},\n\t\t\t...(await this.initRoutes(this.#config))\n\t\t});\n\n\t\tconst server = new http.Server(async (request, response) => {\n\t\t\t/*\n\t\t\t * Get the Base URL from the request Host header (if\n\t\t\t * available) or default to localhost. This is used\n\t\t\t * to construct the full URL for routing.\n\t\t\t */\n\t\t\tconst inputURLBaseRaw = new URL(`http://${request.headers.host ?? 'localhost'}`);\n\t\t\tconst inputURLBase = inputURLBaseRaw.protocol + '//' + inputURLBaseRaw.host;\n\n\t\t\t/*\n\t\t\t * Normalize the input URL by stripping leading slashes and\n\t\t\t * combining it with the base URL to get the full URL for routing.\n\t\t\t */\n\t\t\tconst inputURLRaw = (request.url ?? '/').replace(/^\\/+/, '/');\n\t\t\tconst inputURLObject = new URL(inputURLRaw, 'http://localhost');\n\t\t\tconst inputURL = inputURLObject.pathname + (function() {\n\t\t\t\tif (inputURLObject.search === '') {\n\t\t\t\t\treturn('');\n\t\t\t\t}\n\n\t\t\t\treturn('?' + inputURLObject.searchParams.toString());\n\t\t\t})();\n\t\t\tconst url = new URL(inputURL, inputURLBase);\n\t\t\tconst method = request.method ?? 'GET';\n\n\t\t\t/*\n\t\t\t * Finalize the response by syncing the logger and ending\n\t\t\t * the response.\n\t\t\t */\n\t\t\tconst responseFinalize = async () => {\n\t\t\t\tif ('sync' in this.logger && typeof this.logger.sync === 'function') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.logger.sync();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t/* ignore errors */\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tresponse.end();\n\t\t\t};\n\n\t\t\t/*\n\t\t\t * If the request is malformed, reject it immediately\n\t\t\t */\n\t\t\tif (inputURLRaw.at(0) !== '/') {\n\t\t\t\tresponse.statusCode = 400;\n\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\tresponse.write('Bad Request');\n\t\t\t\tawait responseFinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Lookup the route based on the request\n\t\t\t */\n\t\t\tconst requestedRouteAndParams = KeetaNetAnchorHTTPServer.routeFind(method, url, routes);\n\t\t\tif (requestedRouteAndParams === null) {\n\t\t\t\tresponse.statusCode = 404;\n\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\tresponse.write('Not Found');\n\t\t\t\tawait responseFinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Extract the route handler and the parameters from\n\t\t\t * the request\n\t\t\t */\n\t\t\tconst { route, params } = requestedRouteAndParams;\n\n\t\t\t/**\n\t\t\t * Attempt to run the route, catch any errors\n\t\t\t */\n\t\t\tlet result: Awaited<ReturnType<RouteHandlerMethod>> | undefined = undefined;\n\t\t\tlet generatedResult = false;\n\t\t\ttry {\n\t\t\t\tif (!request.method) {\n\t\t\t\t\tthrow(new Error('internal error: No request method'));\n\t\t\t\t}\n\n\t\t\t\tlet bodyData: JSONSerializable | Buffer | undefined;\n\n\t\t\t\tconst shouldCheckBody = ['POST', 'PUT', 'PATCH', 'DELETE'].includes(request.method);\n\n\t\t\t\tif (typeof route === 'function') {\n\t\t\t\t\tthrow(new Error('internal error: Route handler missing body type configuration, should have been added in addCORS'));\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * If POST'ing, PUT'ing, or PATCH'ing, read and parse the request body\n\t\t\t\t */\n\t\t\t\tif (shouldCheckBody && route.bodyType !== 'none') {\n\t\t\t\t\tconst bodySizeLimit = route.maxBodySize ?? MAX_REQUEST_SIZE;\n\n\t\t\t\t\t// Early rejection based on Content-Length header\n\t\t\t\t\tconst contentLength = request.headers['content-length'];\n\t\t\t\t\tif (contentLength !== undefined) {\n\t\t\t\t\t\tconst declaredSize = parseInt(contentLength, 10);\n\t\t\t\t\t\tif (!isNaN(declaredSize) && declaredSize > bodySizeLimit) {\n\t\t\t\t\t\t\trequest.resume();\n\n\t\t\t\t\t\t\tresponse.statusCode = 413;\n\t\t\t\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\t\t\t\tresponse.write('Payload Too Large');\n\n\t\t\t\t\t\t\tawait responseFinalize();\n\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst data = await request.map(function(chunk) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\t\t\treturn(Buffer.from(chunk));\n\t\t\t\t\t}).reduce(function(prev, curr) {\n\t\t\t\t\t\tif (prev.length > bodySizeLimit) {\n\t\t\t\t\t\t\tthrow(new Error('Request too large'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!Buffer.isBuffer(curr)) {\n\t\t\t\t\t\t\tthrow(new Error(`internal error: Current item is not a buffer -- ${typeof curr}`));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn(Buffer.concat([prev, curr]));\n\t\t\t\t\t}, Buffer.from(''));\n\n\t\t\t\t\tif (route.bodyType === 'raw') {\n\t\t\t\t\t\tbodyData = data;\n\t\t\t\t\t} else if (route.bodyType === 'parsed' && request.headers['content-type'] === 'application/json') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\t\t\tbodyData = JSON.parse(data.toString('utf-8'));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow(new Error('Invalid JSON data'));\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (data.length > 0) {\n\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Unsupported content type'));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * Call the route handler\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\tresult = await route.handler(params, bodyData, request.headers, url);\n\n\t\t\t\tgeneratedResult = true;\n\t\t\t} catch (err) {\n\t\t\t\tlet logLevel: Lowercase<LogLevel> = 'error';\n\t\t\t\tif (KeetaAnchorError.isInstance(err)) {\n\t\t\t\t\t/*\n\t\t\t\t\t * We're able to safely cast this here because the cast\n\t\t\t\t\t * duplicates the logic.\n\t\t\t\t\t */\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tlogLevel = err.logLevel.toLowerCase() as Lowercase<typeof err.logLevel>;\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * If an error occurs, log it and return an error page\n\t\t\t\t */\n\t\t\t\tthis.logger?.[logLevel]('KeetaAnchorHTTP.Server', err);\n\n\t\t\t\t/**\n\t\t\t\t * If it is a user error, provide a user-friendly error page\n\t\t\t\t */\n\t\t\t\tconst errorHandlerRoute = routes['ERROR'];\n\t\t\t\tif (errorHandlerRoute !== undefined) {\n\t\t\t\t\tlet errBody;\n\t\t\t\t\tif (KeetaAnchorError.isInstance(err) && err['userError']) {\n\t\t\t\t\t\terrBody = err.asErrorResponse('application/json');\n\t\t\t\t\t} else {\n\t\t\t\t\t\terrBody = {\n\t\t\t\t\t\t\terror: JSON.stringify({ ok: false, error: 'Internal Server Error' }),\n\t\t\t\t\t\t\tstatusCode: 500,\n\t\t\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tresult = await errorHandlerRoute.handler(new Map(), errBody, request.headers, url);\n\t\t\t\t\tgeneratedResult = true;\n\t\t\t\t}\n\n\t\t\t\tif (!generatedResult) {\n\t\t\t\t\t/**\n\t\t\t\t\t * Otherwise provide a generic error page\n\t\t\t\t\t */\n\t\t\t\t\tresponse.statusCode = 500;\n\t\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\t\tresponse.write('Internal Server Error');\n\t\t\t\t\tawait responseFinalize();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (result === undefined) {\n\t\t\t\tthrow(new Error('internal error: No result'));\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Write the response to the client\n\t\t\t */\n\t\t\tresponse.statusCode = result.statusCode ?? 200;\n\n\t\t\tfor (const headerKey in result.headers ?? {}) {\n\t\t\t\tconst headerValue = result.headers?.[headerKey];\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tresponse.setHeader(headerKey, headerValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresponse.setHeader('Content-Type', result.contentType ?? 'application/json');\n\t\t\tresponse.write(result.output);\n\t\t\tawait responseFinalize();\n\t\t});\n\t\tthis.#server = server;\n\n\t\t/**\n\t\t * Create a promise to wait for the server to close\n\t\t */\n\t\tconst waiter = new Promise<void>((resolve) => {\n\t\t\tserver.on('close', () => {\n\t\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Server closed');\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\t/**\n\t\t * Start listening on the port\n\t\t */\n\t\tserver.listen(port, () => {\n\t\t\tconst address = server.address();\n\t\t\tif (address !== null && typeof address === 'object') {\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.port = address.port;\n\t\t\t\tonSetPort?.(this.port);\n\t\t\t}\n\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Listening on port:', this.port);\n\t\t});\n\n\t\t/**\n\t\t * Wait for the server to close\n\t\t */\n\t\tawait waiter;\n\t}\n\n\t/**\n\t * Start the HTTP server and wait for it to be fully initialized.\n\t */\n\tasync start(): Promise<void> {\n\t\t/*\n\t\t * Start the server and wait for it to be initialized before returning\n\t\t */\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.#serverPromise = this.main(function() {\n\t\t\t\tresolve();\n\t\t\t}).catch(function(error: unknown) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n\t\t\t\treject(error);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Wait for the server to terminate. This will only resolve once the\n\t * server has been stopped.\n\t */\n\tasync wait(): Promise<void> {\n\t\tawait this.#serverPromise;\n\t}\n\n\t/**\n\t * Stop the HTTP server and wait for it to be fully terminated.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.#server?.close();\n\t\t// @ts-ignore\n\t\tthis.#server = undefined;\n\t\tawait this.wait();\n\t}\n\n\t/**\n\t * Get the URL of the server, which can be used to make requests to\n\t * it. This will use \"localhost\" as the hostname and the port that\n\t * the server is listening on by default but can be overridden by\n\t * setting a custom URL.\n\t */\n\tget url(): string {\n\t\tif (this.port === 0 || this.#server === undefined) {\n\t\t\tthrow(new Error('Server not started'));\n\t\t}\n\n\t\tif (this.#url !== undefined) {\n\t\t\tlet newURL: string;\n\t\t\tif (typeof this.#url === 'string') {\n\t\t\t\tnewURL = this.#url;\n\t\t\t} else if (this.#url instanceof URL || ('port' in this.#url && 'hostname' in this.#url && 'toString' in this.#url)) {\n\t\t\t\tnewURL = this.#url.toString();\n\t\t\t} else if (typeof this.#url === 'function') {\n\t\t\t\tnewURL = this.#url(this);\n\t\t\t} else {\n\t\t\t\tassertNever(this.#url);\n\t\t\t}\n\n\t\t\tconst newURLObj = new URL(newURL);\n\t\t\tnewURLObj.pathname = '/';\n\t\t\tnewURLObj.search = '';\n\n\t\t\tconst retval = newURLObj.toString();\n\n\t\t\treturn(retval);\n\t\t}\n\n\t\tconst urlObj = new URL('http://localhost');\n\t\turlObj.port = String(this.#urlParts?.port ?? this.port);\n\t\turlObj.hostname = this.#urlParts?.hostname ?? 'localhost';\n\t\turlObj.protocol = this.#urlParts?.protocol ?? 'http:';\n\t\turlObj.pathname = '/';\n\t\turlObj.search = '';\n\n\t\tconst retval = urlObj.toString();\n\n\t\treturn(retval);\n\t}\n\n\tset url(value: undefined | string | URL | ((object: this) => string)) {\n\t\tthis.#urlParts = undefined;\n\t\tthis.#url = value;\n\t}\n\n\t[Symbol.asyncDispose](): Promise<void> {\n\t\treturn(this.stop());\n\t}\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -2,6 +2,11 @@ import * as Certificates from './certificates.js';
2
2
  import { EncryptedContainer } from './encrypted-container.js';
3
3
  import * as URI from './uri.js';
4
4
  import Resolver from './resolver.js';
5
- export { AnchorExternal } from './anchor-external.js';
5
+ export type { AnchorPayoutExternalOptions } from './anchor-external.js';
6
+ export { AnchorExternal, buildSignedAnchorExternal } from './anchor-external.js';
7
+ export { AnchorTransactionStatus, isCompletedTransferStatus } from './anchor-status.js';
8
+ export type { AnchorOnChainReference, AnchorReference, AnchorStatusSource, AnchorTransferReader, AnchorGetTransactionStatusOptions, AnchorExternalTransactionStatusOptions, AnchorTransactionStatusResult, StandardizedTransferStatus } from './anchor-status.js';
9
+ export { UserHistory, defaultClassifiers, foldHistory, logicalTypeFromTransfer, statusFromTransfer } from './history.js';
10
+ export type { EnrichedBlock, EnrichedOperation, HistoryEntry, HistoryQuery, HistorySource, HistoryStaple, LogicalAmount, LogicalClassifier, LogicalCounterparty, LogicalDirection, LogicalLeg, LogicalTransaction, LogicalTransactionSource, LogicalTransactionStatus, LogicalTransactionType, UserHistoryConfig, UserHistoryListOptions } from './history.js';
6
11
  export { Certificates, EncryptedContainer, Resolver, URI };
7
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,YAAY,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACxF,YAAY,EACX,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iCAAiC,EACjC,sCAAsC,EACtC,6BAA6B,EAC7B,0BAA0B,EAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACX,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,CAAA"}
package/lib/index.js CHANGED
@@ -2,6 +2,8 @@ import * as Certificates from './certificates.js';
2
2
  import { EncryptedContainer } from './encrypted-container.js';
3
3
  import * as URI from './uri.js';
4
4
  import Resolver from './resolver.js';
5
- export { AnchorExternal } from './anchor-external.js';
5
+ export { AnchorExternal, buildSignedAnchorExternal } from './anchor-external.js';
6
+ export { AnchorTransactionStatus, isCompletedTransferStatus } from './anchor-status.js';
7
+ export { UserHistory, defaultClassifiers, foldHistory, logicalTypeFromTransfer, statusFromTransfer } from './history.js';
6
8
  export { Certificates, EncryptedContainer, Resolver, URI };
7
9
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,CAAA","sourcesContent":["import * as Certificates from './certificates.js';\nimport { EncryptedContainer } from './encrypted-container.js';\nimport * as URI from './uri.js';\n\nimport Resolver from './resolver.js';\nexport { AnchorExternal } from './anchor-external.js';\nexport {\n\tCertificates,\n\tEncryptedContainer,\n\tResolver,\n\tURI\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,eAAe,CAAC;AAGrC,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAWxF,OAAO,EACN,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EAClB,MAAM,cAAc,CAAC;AAoBtB,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,CAAA","sourcesContent":["import * as Certificates from './certificates.js';\nimport { EncryptedContainer } from './encrypted-container.js';\nimport * as URI from './uri.js';\n\nimport Resolver from './resolver.js';\n\nexport type { AnchorPayoutExternalOptions } from './anchor-external.js';\nexport { AnchorExternal, buildSignedAnchorExternal } from './anchor-external.js';\nexport { AnchorTransactionStatus, isCompletedTransferStatus } from './anchor-status.js';\nexport type {\n\tAnchorOnChainReference,\n\tAnchorReference,\n\tAnchorStatusSource,\n\tAnchorTransferReader,\n\tAnchorGetTransactionStatusOptions,\n\tAnchorExternalTransactionStatusOptions,\n\tAnchorTransactionStatusResult,\n\tStandardizedTransferStatus\n} from './anchor-status.js';\nexport {\n\tUserHistory,\n\tdefaultClassifiers,\n\tfoldHistory,\n\tlogicalTypeFromTransfer,\n\tstatusFromTransfer\n} from './history.js';\nexport type {\n\tEnrichedBlock,\n\tEnrichedOperation,\n\tHistoryEntry,\n\tHistoryQuery,\n\tHistorySource,\n\tHistoryStaple,\n\tLogicalAmount,\n\tLogicalClassifier,\n\tLogicalCounterparty,\n\tLogicalDirection,\n\tLogicalLeg,\n\tLogicalTransaction,\n\tLogicalTransactionSource,\n\tLogicalTransactionStatus,\n\tLogicalTransactionType,\n\tUserHistoryConfig,\n\tUserHistoryListOptions\n} from './history.js';\nexport {\n\tCertificates,\n\tEncryptedContainer,\n\tResolver,\n\tURI\n}\n"]}
@@ -16,6 +16,9 @@ export type ClientRenderableContent = {
16
16
  export type ServiceMetadataAuthenticationType = {
17
17
  method: 'keeta-account';
18
18
  type: 'required' | 'optional' | 'none';
19
+ } | {
20
+ method?: never;
21
+ type: 'none';
19
22
  };
20
23
  /**
21
24
  * Operation endpoint exposed by a service.
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.types.d.ts","sourceRoot":"","sources":["../../src/lib/metadata.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MA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I,CAAC,mBAAmB,EAAE,CAAC;YAC1B,OAAM,CAAC,SAAS,CAAC,CAAC;QACnB,CAAC;QAED,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,WAAU,UAAU;YACnG,MAAM,kBAAkB,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC;YAEtD,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAE3D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAK,CAAC,IAAI,KAAK,CAAC,mCAAmC,OAAO,EAAE,CAAC,CAAC,CAAC;YAChE,CAAC;YAED,OAAM,CAAC;gBACN,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,MAAM,8BAA8B,CAAC,kBAAkB,CAAC,OAAO,CAAC;aACzE,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC,CAAC;QAEJ,MAAM,QAAQ,GAAG,EAAE,CAAC;QAEpB,KAAK,MAAM,MAAM,IAAI,iBAAiB,EAAE,CAAC;YACxC,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACP,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,2CAA2C,EAAE,sCAAsC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1H,CAAC;QACF,CAAC;QAED,OAAM,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC,CAAC,EAAE,CAAC;IAEL,OAAM,CAAC;QACN,KAAK,EAAE;YACN,WAAW;SACX;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { assertClientRenderableContentType } from \"./metadata.types.generated.js\";\nimport type { HTTPSignedField } from \"./http-server/common.js\";\nimport type { Logger } from \"./log/index.js\";\nimport type { ToValuizable } from \"./resolver.js\";\n\n\n/**\n * This is the type of content that can be rendered directly in a client application.\n *\n * There is no guarantee on if/how this content will be displayed, so it should not be used for critical information, rather as a way to provide the user additional context about a transfer.\n */\nexport type ClientRenderableContent = { type: 'markdown' | 'plaintext'; content: string; };\n\n\n/**\n * Authentication requirement attached to a service operation endpoint.\n */\nexport type ServiceMetadataAuthenticationType = {\n\tmethod: 'keeta-account';\n\ttype: 'required' | 'optional' | 'none';\n};\n\n/**\n * Operation endpoint exposed by a service.\n */\nexport type ServiceMetadataEndpoint = string | { url: string; options?: { authentication?: ServiceMetadataAuthenticationType; }};\n\nexport interface AnchorMetadataLegalField {\n\tdisclaimers?: {\n\t\tpurpose: 'general';\n\t\tcontent: ClientRenderableContent;\n\t}[] | undefined;\n}\n\nexport interface SharedAnchorMetadataLegalExtension {\n\t/**\n\t * Legal details that the anchor wants to share with the user.\n\t * This can include things like disclaimers, terms of service, etc.\n\t */\n\tlegal?: AnchorMetadataLegalField;\n}\n\n/**\n * Signature over `{ operations, legal }` for a service entry. `account` and\n * `signed` are coupled at runtime: either both are absent (unsigned entry)\n * or both are present (signed entry that MUST verify). The coupling cannot\n * be expressed at the type level without breaking `JSONSerializable`\n * compatibility, so consumers MUST treat one-sided forms as malformed.\n */\nexport type SharedAnchorMetadataSignedExtension = {\n\taccount?: string;\n\tsigned?: HTTPSignedField;\n};\n\nexport type SharedAnchorCallerCertificateRequirementMetadata = {\n\t/**\n\t * Issuer DNs this anchor accepts for caller authentication. Outer array\n\t * is any-of (OR), inner array is all-of (AND) within a single DN.\n\t * When present, callers MUST present an on-chain certificate that chains\n\t * to an issuer whose subject DN matches one of these.\n\t */\n\tacceptedIssuerDNs?: { name: string; value: string }[][];\n};\n\nasync function resolveClientRenderableContent(content: ToValuizable<ClientRenderableContent>): Promise<ClientRenderableContent> {\n\tconst resolved = await content('object');\n\n\treturn({\n\t\ttype: assertClientRenderableContentType(await resolved.type('string')),\n\t\tcontent: await resolved.content('string')\n\t})\n}\n\nexport async function resolveSharedAnchorMetadataLegalExtension(metadata: ToValuizable<AnchorMetadataLegalField> | undefined, options: {\n\tlogger?: Logger | undefined;\n}): Promise<SharedAnchorMetadataLegalExtension> {\n\tif (!metadata) {\n\t\treturn({});\n\t}\n\n\tconst resolvedField = await metadata('object');\n\n\tif (!resolvedField) {\n\t\treturn({});\n\t}\n\n\tconst disclaimers = await (async (): Promise<AnchorMetadataLegalField['disclaimers']> => {\n\t\tconst resolvedDisclaimers = await resolvedField.disclaimers?.('array');\n\t\tif (!resolvedDisclaimers) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst parsedDisclaimers = await Promise.allSettled(resolvedDisclaimers.map(async function(disclaimer): Promise<NonNullable<AnchorMetadataLegalField['disclaimers']>[number]> {\n\t\t\tconst resolvedDisclaimer = await disclaimer('object');\n\n\t\t\tconst purpose = await resolvedDisclaimer.purpose('string');\n\n\t\t\tif (purpose !== 'general') {\n\t\t\t\tthrow(new Error(`Unsupported disclaimer purpose: ${purpose}`));\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\tpurpose: purpose,\n\t\t\t\tcontent: await resolveClientRenderableContent(resolvedDisclaimer.content)\n\t\t\t});\n\t\t}));\n\n\t\tconst filtered = [];\n\n\t\tfor (const result of parsedDisclaimers) {\n\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\tfiltered.push(result.value);\n\t\t\t} else {\n\t\t\t\toptions.logger?.warn('resolveSharedAnchorMetadataLegalExtension', 'Failed to resolve disclaimer content', result.reason);\n\t\t\t}\n\t\t}\n\n\t\treturn(filtered);\n\t})();\n\n\treturn({\n\t\tlegal: {\n\t\t\tdisclaimers\n\t\t}\n\t});\n}\n"]}
1
+ {"version":3,"file":"metadata.types.js","sourceRoot":"","sources":["../../src/lib/metadata.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,+BAA+B,CAAC;AAmElF,KAAK,UAAU,8BAA8B,CAAC,OAA8C;IAC3F,MAAM,QAAQ,GA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zE,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC,CAAC;QAEJ,MAAM,QAAQ,GAAG,EAAE,CAAC;QAEpB,KAAK,MAAM,MAAM,IAAI,iBAAiB,EAAE,CAAC;YACxC,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACP,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,2CAA2C,EAAE,sCAAsC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1H,CAAC;QACF,CAAC;QAED,OAAM,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC,CAAC,EAAE,CAAC;IAEL,OAAM,CAAC;QACN,KAAK,EAAE;YACN,WAAW;SACX;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { assertClientRenderableContentType } from \"./metadata.types.generated.js\";\nimport type { HTTPSignedField } from \"./http-server/common.js\";\nimport type { Logger } from \"./log/index.js\";\nimport type { ToValuizable } from \"./resolver.js\";\n\n\n/**\n * This is the type of content that can be rendered directly in a client application.\n *\n * There is no guarantee on if/how this content will be displayed, so it should not be used for critical information, rather as a way to provide the user additional context about a transfer.\n */\nexport type ClientRenderableContent = { type: 'markdown' | 'plaintext'; content: string; };\n\n\n/**\n * Authentication requirement attached to a service operation endpoint.\n */\nexport type ServiceMetadataAuthenticationType = {\n\tmethod: 'keeta-account';\n\ttype: 'required' | 'optional' | 'none';\n} | {\n\tmethod?: never;\n\ttype: 'none';\n};\n\n/**\n * Operation endpoint exposed by a service.\n */\nexport type ServiceMetadataEndpoint = string | { url: string; options?: { authentication?: ServiceMetadataAuthenticationType; }};\n\nexport interface AnchorMetadataLegalField {\n\tdisclaimers?: {\n\t\tpurpose: 'general';\n\t\tcontent: ClientRenderableContent;\n\t}[] | undefined;\n}\n\nexport interface SharedAnchorMetadataLegalExtension {\n\t/**\n\t * Legal details that the anchor wants to share with the user.\n\t * This can include things like disclaimers, terms of service, etc.\n\t */\n\tlegal?: AnchorMetadataLegalField;\n}\n\n/**\n * Signature over `{ operations, legal }` for a service entry. `account` and\n * `signed` are coupled at runtime: either both are absent (unsigned entry)\n * or both are present (signed entry that MUST verify). The coupling cannot\n * be expressed at the type level without breaking `JSONSerializable`\n * compatibility, so consumers MUST treat one-sided forms as malformed.\n */\nexport type SharedAnchorMetadataSignedExtension = {\n\taccount?: string;\n\tsigned?: HTTPSignedField;\n};\n\nexport type SharedAnchorCallerCertificateRequirementMetadata = {\n\t/**\n\t * Issuer DNs this anchor accepts for caller authentication. Outer array\n\t * is any-of (OR), inner array is all-of (AND) within a single DN.\n\t * When present, callers MUST present an on-chain certificate that chains\n\t * to an issuer whose subject DN matches one of these.\n\t */\n\tacceptedIssuerDNs?: { name: string; value: string }[][];\n};\n\nasync function resolveClientRenderableContent(content: ToValuizable<ClientRenderableContent>): Promise<ClientRenderableContent> {\n\tconst resolved = await content('object');\n\n\treturn({\n\t\ttype: assertClientRenderableContentType(await resolved.type('string')),\n\t\tcontent: await resolved.content('string')\n\t})\n}\n\nexport async function resolveSharedAnchorMetadataLegalExtension(metadata: ToValuizable<AnchorMetadataLegalField> | undefined, options: {\n\tlogger?: Logger | undefined;\n}): Promise<SharedAnchorMetadataLegalExtension> {\n\tif (!metadata) {\n\t\treturn({});\n\t}\n\n\tconst resolvedField = await metadata('object');\n\n\tif (!resolvedField) {\n\t\treturn({});\n\t}\n\n\tconst disclaimers = await (async (): Promise<AnchorMetadataLegalField['disclaimers']> => {\n\t\tconst resolvedDisclaimers = await resolvedField.disclaimers?.('array');\n\t\tif (!resolvedDisclaimers) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tconst parsedDisclaimers = await Promise.allSettled(resolvedDisclaimers.map(async function(disclaimer): Promise<NonNullable<AnchorMetadataLegalField['disclaimers']>[number]> {\n\t\t\tconst resolvedDisclaimer = await disclaimer('object');\n\n\t\t\tconst purpose = await resolvedDisclaimer.purpose('string');\n\n\t\t\tif (purpose !== 'general') {\n\t\t\t\tthrow(new Error(`Unsupported disclaimer purpose: ${purpose}`));\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\tpurpose: purpose,\n\t\t\t\tcontent: await resolveClientRenderableContent(resolvedDisclaimer.content)\n\t\t\t});\n\t\t}));\n\n\t\tconst filtered = [];\n\n\t\tfor (const result of parsedDisclaimers) {\n\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\tfiltered.push(result.value);\n\t\t\t} else {\n\t\t\t\toptions.logger?.warn('resolveSharedAnchorMetadataLegalExtension', 'Failed to resolve disclaimer content', result.reason);\n\t\t\t}\n\t\t}\n\n\t\treturn(filtered);\n\t})();\n\n\treturn({\n\t\tlegal: {\n\t\t\tdisclaimers\n\t\t}\n\t});\n}\n"]}
package/lib/resolver.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as KeetaNetClient from '@keetanetwork/keetanet-client';
2
- import type { AccountPublicKeyString, GenericAccount as KeetaNetGenericAccount } from '@keetanetwork/keetanet-client/lib/account.js';
2
+ import type { Account, AccountPublicKeyString, GenericAccount as KeetaNetGenericAccount } from '@keetanetwork/keetanet-client/lib/account.js';
3
3
  import * as CurrencyInfo from '@keetanetwork/currency-info';
4
4
  import type { Logger } from './log/index.ts';
5
5
  import type { JSONSerializable } from './utils/json.ts';
@@ -8,11 +8,14 @@ import type { AssetLocationString, SupportedAssetsMetadata, AssetMovementRailSea
8
8
  import type { MovableAssetSearchInput, KeetaNetTokenPublicKeyString } from './asset.js';
9
9
  import type { NotificationChannelType, NotificationSubscriptionType, SupportedChannelConfigurationMetadata } from '../services/notification/common.js';
10
10
  import type { ServiceMetadataEndpoint, SharedAnchorCallerCertificateRequirementMetadata, SharedAnchorMetadataLegalExtension, SharedAnchorMetadataSignedExtension } from './metadata.types.js';
11
- import type { VerifiableAccount } from './utils/signing.js';
12
- type ExternalURL = {
13
- external: '2b828e33-2692-46e9-817e-9b93d63f28fd';
11
+ import { type Signable, type VerifiableAccount } from './utils/signing.js';
12
+ declare const ExternalURLKey: "2b828e33-2692-46e9-817e-9b93d63f28fd";
13
+ type ExternalURLOptions = Pick<NonNullable<Exclude<NonNullable<ServiceMetadataEndpoint>, string>['options']>, 'authentication'>;
14
+ interface ExternalURL {
15
+ external: typeof ExternalURLKey;
14
16
  url: string;
15
- };
17
+ options?: ExternalURLOptions;
18
+ }
16
19
  type KeetaNetAccount = InstanceType<typeof KeetaNetClient.lib.Account>;
17
20
  declare const KeetaNetAccount: typeof KeetaNetClient.lib.Account;
18
21
  type KeetaNetAccountTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNetClient.lib.Account<typeof KeetaNetAccount.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;
@@ -456,7 +459,7 @@ type ResolverConfig = {
456
459
  /**
457
460
  * Additional configuration for reading metadata
458
461
  */
459
- metadataConfig?: Pick<MetadataConfig, 'allowInsecureProtocols'>;
462
+ metadataConfig?: Pick<MetadataConfig, 'allowInsecureProtocols' | 'signing'>;
460
463
  };
461
464
  type MetadataConfig = {
462
465
  trustedCAs: ResolverConfig['trustedCAs'];
@@ -474,6 +477,21 @@ type MetadataConfig = {
474
477
  * Defaults to false
475
478
  */
476
479
  allowInsecureProtocols?: boolean;
480
+ /**
481
+ * Optional signing configuration for signing requests to external services.
482
+ * If not provided, then requests will not be signed.
483
+ */
484
+ signing?: {
485
+ /**
486
+ * The account to sign requests with. If not provided, then requests will not be signed.
487
+ */
488
+ account: Account;
489
+ /**
490
+ * Flag indicating if requests that do not explicitly deny signing should be signed.
491
+ * Defaults to false.
492
+ */
493
+ signAllRequests?: boolean;
494
+ };
477
495
  };
478
496
  type ValuizableInstance = {
479
497
  value: ValuizableMethod;
@@ -490,6 +508,7 @@ declare class Metadata implements ValuizableInstance {
490
508
  */
491
509
  static formatMetadata(metadata: ToJSONValuizable<ServiceMetadata>): string;
492
510
  static formatMetadata(metadata: JSONSerializable): string;
511
+ static getExternalURLSignable(url: URL): Signable;
493
512
  /**
494
513
  * Assert that the supplied value is a valid Metadata Root Object
495
514
  */
@@ -511,13 +530,14 @@ declare class Metadata implements ValuizableInstance {
511
530
  */
512
531
  static fullyResolveValuizable(value: ValuizeResolvable, invalidReplacement?: JSONSerializable): Promise<JSONSerializable>;
513
532
  static fullyResolveValuizable(value: any, invalidReplacement?: JSONSerializable): Promise<JSONSerializable>;
514
- constructor(url: string | URL, config: MetadataConfig);
533
+ constructor(url: string | URL | ExternalURL, config: MetadataConfig);
515
534
  /**
516
535
  * @param metadata Metadata to parse -- base64 encoded string or ArrayBuffer
517
536
  */
518
537
  private parseMetadata;
519
538
  private readKeetaNetURL;
520
539
  private readHTTPSURL;
540
+ private getResolvedExternalURL;
521
541
  private readURL;
522
542
  private resolveValue;
523
543
  private assertValuizableKind;
@@ -561,6 +581,7 @@ declare class Resolver {
561
581
  #private;
562
582
  readonly id: string;
563
583
  static readonly Metadata: typeof Metadata;
584
+ static getExternalURLSignable(url: URL): Signable;
564
585
  private readonly lookupMap;
565
586
  constructor(config: ResolverConfig);
566
587
  get stats(): ResolverStats;