@bsv/wallet-toolbox 1.4.11 → 1.5.1

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 (169) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/mobile/out/src/CWIStyleWalletManager.js +1 -1
  3. package/mobile/out/src/CWIStyleWalletManager.js.map +1 -1
  4. package/mobile/out/src/SetupClient.mobile.d.ts +90 -0
  5. package/mobile/out/src/SetupClient.mobile.d.ts.map +1 -0
  6. package/mobile/out/src/SetupClient.mobile.js +183 -0
  7. package/mobile/out/src/SetupClient.mobile.js.map +1 -0
  8. package/mobile/out/src/SetupWallet.mobile.d.ts +93 -0
  9. package/mobile/out/src/SetupWallet.mobile.d.ts.map +1 -0
  10. package/mobile/out/src/SetupWallet.mobile.js +3 -0
  11. package/mobile/out/src/SetupWallet.mobile.js.map +1 -0
  12. package/mobile/out/src/monitor/tasks/TaskReviewStatus.d.ts +1 -1
  13. package/mobile/out/src/monitor/tasks/TaskReviewStatus.js +1 -1
  14. package/mobile/out/src/services/chaintracker/{BHServiceClient.d.ts → BhsChainTracker.d.ts} +16 -12
  15. package/mobile/out/src/services/chaintracker/BhsChainTracker.d.ts.map +1 -0
  16. package/mobile/out/src/services/chaintracker/BhsChainTracker.js +84 -0
  17. package/mobile/out/src/services/chaintracker/BhsChainTracker.js.map +1 -0
  18. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts +98 -0
  19. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +1 -0
  20. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js +38 -0
  21. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +1 -0
  22. package/mobile/out/src/services/chaintracker/index.d.ts +1 -1
  23. package/mobile/out/src/services/chaintracker/index.js +1 -1
  24. package/mobile/out/src/services/createDefaultWalletServicesOptions.d.ts +1 -1
  25. package/mobile/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
  26. package/mobile/out/src/services/createDefaultWalletServicesOptions.js +7 -10
  27. package/mobile/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
  28. package/mobile/out/src/storage/WalletStorageManager.d.ts +25 -19
  29. package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  30. package/mobile/out/src/storage/WalletStorageManager.js +69 -64
  31. package/mobile/out/src/storage/WalletStorageManager.js.map +1 -1
  32. package/mobile/out/src/storage/methods/createAction.d.ts.map +1 -1
  33. package/mobile/out/src/storage/methods/createAction.js +4 -9
  34. package/mobile/out/src/storage/methods/createAction.js.map +1 -1
  35. package/mobile/out/src/storage/methods/processAction.js +1 -1
  36. package/mobile/out/src/storage/methods/processAction.js.map +1 -1
  37. package/mobile/package-lock.json +6 -6
  38. package/mobile/package.json +2 -2
  39. package/out/src/AuthFetchDebug.d.ts +88 -0
  40. package/out/src/AuthFetchDebug.d.ts.map +1 -0
  41. package/out/src/AuthFetchDebug.js +518 -0
  42. package/out/src/AuthFetchDebug.js.map +1 -0
  43. package/out/src/SetupClient.mobile.d.ts +90 -0
  44. package/out/src/SetupClient.mobile.d.ts.map +1 -0
  45. package/out/src/SetupClient.mobile.js +183 -0
  46. package/out/src/SetupClient.mobile.js.map +1 -0
  47. package/out/src/SetupWallet.mobile.d.ts +93 -0
  48. package/out/src/SetupWallet.mobile.d.ts.map +1 -0
  49. package/out/src/SetupWallet.mobile.js +3 -0
  50. package/out/src/SetupWallet.mobile.js.map +1 -0
  51. package/out/src/SimplifiedFetchTransport.d.ts +1 -0
  52. package/out/src/SimplifiedFetchTransport.d.ts.map +1 -0
  53. package/out/src/SimplifiedFetchTransport.js +2 -0
  54. package/out/src/SimplifiedFetchTransport.js.map +1 -0
  55. package/out/src/services/BhsChainTracker.d.ts +1 -0
  56. package/out/src/services/BhsChainTracker.d.ts.map +1 -0
  57. package/out/src/services/BhsChainTracker.js +2 -0
  58. package/out/src/services/BhsChainTracker.js.map +1 -0
  59. package/out/src/services/chaintracker/BhsChainTracker.d.ts +38 -0
  60. package/out/src/services/chaintracker/BhsChainTracker.d.ts.map +1 -0
  61. package/out/src/services/chaintracker/BhsChainTracker.js +84 -0
  62. package/out/src/services/chaintracker/BhsChainTracker.js.map +1 -0
  63. package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts +98 -0
  64. package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +1 -0
  65. package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js +38 -0
  66. package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +1 -0
  67. package/out/src/storage/StorageProvider copy.d.ts +209 -0
  68. package/out/src/storage/StorageProvider copy.d.ts.map +1 -0
  69. package/out/src/storage/StorageProvider copy.js +550 -0
  70. package/out/src/storage/StorageProvider copy.js.map +1 -0
  71. package/out/src/storage/StorageProvider.mobile.d.ts +209 -0
  72. package/out/src/storage/StorageProvider.mobile.d.ts.map +1 -0
  73. package/out/src/storage/StorageProvider.mobile.js +550 -0
  74. package/out/src/storage/StorageProvider.mobile.js.map +1 -0
  75. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  76. package/out/src/storage/WalletStorageManager.js.map +1 -1
  77. package/out/src/storage/remoting/StorageClient copy.d.ts +283 -0
  78. package/out/src/storage/remoting/StorageClient copy.d.ts.map +1 -0
  79. package/out/src/storage/remoting/StorageClient copy.js +477 -0
  80. package/out/src/storage/remoting/StorageClient copy.js.map +1 -0
  81. package/out/test/Wallet/action/abortAction.test.d.ts.map +1 -0
  82. package/out/test/{wallet → Wallet}/action/abortAction.test.js.map +1 -1
  83. package/out/test/Wallet/action/createAction.test.d.ts.map +1 -0
  84. package/out/test/{wallet → Wallet}/action/createAction.test.js.map +1 -1
  85. package/out/test/{wallet → Wallet}/action/createAction2.test.d.ts.map +1 -1
  86. package/out/test/{wallet → Wallet}/action/createAction2.test.js.map +1 -1
  87. package/out/test/Wallet/action/createActionToGenerateBeefs.man.test.d.ts.map +1 -0
  88. package/out/test/{wallet → Wallet}/action/createActionToGenerateBeefs.man.test.js.map +1 -1
  89. package/out/test/Wallet/action/internalizeAction.test.d.ts.map +1 -0
  90. package/out/test/{wallet → Wallet}/action/internalizeAction.test.js.map +1 -1
  91. package/out/test/Wallet/action/relinquishOutput.test.d.ts.map +1 -0
  92. package/out/test/{wallet → Wallet}/action/relinquishOutput.test.js.map +1 -1
  93. package/out/test/Wallet/construct/Wallet.constructor.test.d.ts.map +1 -0
  94. package/out/test/{wallet → Wallet}/construct/Wallet.constructor.test.js.map +1 -1
  95. package/out/test/Wallet/list/listActions.test.d.ts.map +1 -0
  96. package/out/test/{wallet → Wallet}/list/listActions.test.js.map +1 -1
  97. package/out/test/Wallet/list/listActions2.test.d.ts.map +1 -0
  98. package/out/test/{wallet → Wallet}/list/listActions2.test.js.map +1 -1
  99. package/out/test/Wallet/list/listCertificates.test.d.ts.map +1 -0
  100. package/out/test/{wallet → Wallet}/list/listCertificates.test.js.map +1 -1
  101. package/out/test/Wallet/list/listOutputs.test.d.ts.map +1 -0
  102. package/out/test/{wallet → Wallet}/list/listOutputs.test.js.map +1 -1
  103. package/out/test/Wallet/sync/Wallet.sync.test.d.ts.map +1 -0
  104. package/out/test/{wallet → Wallet}/sync/Wallet.sync.test.js.map +1 -1
  105. package/out/tsconfig.all.tsbuildinfo +1 -1
  106. package/package.json +4 -4
  107. package/src/storage/WalletStorageManager.ts +1 -3
  108. package/mobile/out/src/services/chaintracker/BHServiceClient.d.ts.map +0 -1
  109. package/mobile/out/src/services/chaintracker/BHServiceClient.js +0 -163
  110. package/mobile/out/src/services/chaintracker/BHServiceClient.js.map +0 -1
  111. package/mobile/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts +0 -140
  112. package/mobile/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts.map +0 -1
  113. package/mobile/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js +0 -467
  114. package/mobile/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js.map +0 -1
  115. package/mobile/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts +0 -20
  116. package/mobile/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts.map +0 -1
  117. package/mobile/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js +0 -31
  118. package/mobile/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js.map +0 -1
  119. package/mobile/out/src/utility/utilityHelpers.buffer.d.ts +0 -18
  120. package/mobile/out/src/utility/utilityHelpers.buffer.d.ts.map +0 -1
  121. package/mobile/out/src/utility/utilityHelpers.buffer.js +0 -45
  122. package/mobile/out/src/utility/utilityHelpers.buffer.js.map +0 -1
  123. package/out/test/wallet/action/abortAction.test.d.ts.map +0 -1
  124. package/out/test/wallet/action/createAction.test.d.ts.map +0 -1
  125. package/out/test/wallet/action/createActionToGenerateBeefs.man.test.d.ts.map +0 -1
  126. package/out/test/wallet/action/internalizeAction.test.d.ts.map +0 -1
  127. package/out/test/wallet/action/relinquishOutput.test.d.ts.map +0 -1
  128. package/out/test/wallet/construct/Wallet.constructor.test.d.ts.map +0 -1
  129. package/out/test/wallet/list/listActions.test.d.ts.map +0 -1
  130. package/out/test/wallet/list/listActions2.test.d.ts.map +0 -1
  131. package/out/test/wallet/list/listCertificates.test.d.ts.map +0 -1
  132. package/out/test/wallet/list/listOutputs.test.d.ts.map +0 -1
  133. package/out/test/wallet/sync/Wallet.sync.test.d.ts.map +0 -1
  134. /package/out/test/{wallet → Wallet}/action/abortAction.test.d.ts +0 -0
  135. /package/out/test/{wallet → Wallet}/action/abortAction.test.js +0 -0
  136. /package/out/test/{wallet → Wallet}/action/createAction.test.d.ts +0 -0
  137. /package/out/test/{wallet → Wallet}/action/createAction.test.js +0 -0
  138. /package/out/test/{wallet → Wallet}/action/createAction2.test.d.ts +0 -0
  139. /package/out/test/{wallet → Wallet}/action/createAction2.test.js +0 -0
  140. /package/out/test/{wallet → Wallet}/action/createActionToGenerateBeefs.man.test.d.ts +0 -0
  141. /package/out/test/{wallet → Wallet}/action/createActionToGenerateBeefs.man.test.js +0 -0
  142. /package/out/test/{wallet → Wallet}/action/internalizeAction.test.d.ts +0 -0
  143. /package/out/test/{wallet → Wallet}/action/internalizeAction.test.js +0 -0
  144. /package/out/test/{wallet → Wallet}/action/relinquishOutput.test.d.ts +0 -0
  145. /package/out/test/{wallet → Wallet}/action/relinquishOutput.test.js +0 -0
  146. /package/out/test/{wallet → Wallet}/construct/Wallet.constructor.test.d.ts +0 -0
  147. /package/out/test/{wallet → Wallet}/construct/Wallet.constructor.test.js +0 -0
  148. /package/out/test/{wallet → Wallet}/list/listActions.test.d.ts +0 -0
  149. /package/out/test/{wallet → Wallet}/list/listActions.test.js +0 -0
  150. /package/out/test/{wallet → Wallet}/list/listActions2.test.d.ts +0 -0
  151. /package/out/test/{wallet → Wallet}/list/listActions2.test.js +0 -0
  152. /package/out/test/{wallet → Wallet}/list/listCertificates.test.d.ts +0 -0
  153. /package/out/test/{wallet → Wallet}/list/listCertificates.test.js +0 -0
  154. /package/out/test/{wallet → Wallet}/list/listOutputs.test.d.ts +0 -0
  155. /package/out/test/{wallet → Wallet}/list/listOutputs.test.js +0 -0
  156. /package/out/test/{wallet → Wallet}/sync/Wallet.sync.test.d.ts +0 -0
  157. /package/out/test/{wallet → Wallet}/sync/Wallet.sync.test.js +0 -0
  158. /package/test/{wallet → Wallet}/action/abortAction.test.ts +0 -0
  159. /package/test/{wallet → Wallet}/action/createAction.test.ts +0 -0
  160. /package/test/{wallet → Wallet}/action/createAction2.test.ts +0 -0
  161. /package/test/{wallet → Wallet}/action/createActionToGenerateBeefs.man.test.ts +0 -0
  162. /package/test/{wallet → Wallet}/action/internalizeAction.test.ts +0 -0
  163. /package/test/{wallet → Wallet}/action/relinquishOutput.test.ts +0 -0
  164. /package/test/{wallet → Wallet}/construct/Wallet.constructor.test.ts +0 -0
  165. /package/test/{wallet → Wallet}/list/listActions.test.ts +0 -0
  166. /package/test/{wallet → Wallet}/list/listActions2.test.ts +0 -0
  167. /package/test/{wallet → Wallet}/list/listCertificates.test.ts +0 -0
  168. /package/test/{wallet → Wallet}/list/listOutputs.test.ts +0 -0
  169. /package/test/{wallet → Wallet}/sync/Wallet.sync.test.ts +0 -0
@@ -0,0 +1,88 @@
1
+ import { WalletInterface } from '../../wallet/Wallet.interfaces.js';
2
+ import { Peer } from '../Peer.js';
3
+ import { SessionManager } from '../SessionManager.js';
4
+ import { RequestedCertificateSet } from '../types.js';
5
+ import { VerifiableCertificate } from '../certificates/VerifiableCertificate.js';
6
+ interface SimplifiedFetchRequestOptions {
7
+ method?: string;
8
+ headers?: Record<string, string>;
9
+ body?: any;
10
+ retryCounter?: number;
11
+ }
12
+ interface AuthPeer {
13
+ peer: Peer;
14
+ identityKey?: string;
15
+ supportsMutualAuth?: boolean;
16
+ pendingCertificateRequests: Array<true>;
17
+ }
18
+ /**
19
+ * AuthFetch provides a lightweight fetch client for interacting with servers
20
+ * over a simplified HTTP transport mechanism. It integrates session management, peer communication,
21
+ * and certificate handling to enable secure and mutually-authenticated requests.
22
+ *
23
+ * Additionally, it automatically handles 402 Payment Required responses by creating
24
+ * and sending BSV payment transactions when necessary.
25
+ */
26
+ export declare class AuthFetch {
27
+ private readonly sessionManager;
28
+ private readonly wallet;
29
+ private callbacks;
30
+ private readonly certificatesReceived;
31
+ private readonly requestedCertificates?;
32
+ peers: Record<string, AuthPeer>;
33
+ /**
34
+ * Constructs a new AuthFetch instance.
35
+ * @param wallet - The wallet instance for signing and authentication.
36
+ * @param requestedCertificates - Optional set of certificates to request from peers.
37
+ */
38
+ constructor(wallet: WalletInterface, requestedCertificates?: RequestedCertificateSet, sessionManager?: SessionManager);
39
+ /**
40
+ * Mutually authenticates and sends a HTTP request to a server.
41
+ *
42
+ * 1) Attempt the request.
43
+ * 2) If 402 Payment Required, automatically create and send payment.
44
+ * 3) Return the final response.
45
+ *
46
+ * @param url - The URL to send the request to.
47
+ * @param config - Configuration options for the request, including method, headers, and body.
48
+ * @returns A promise that resolves with the server's response, structured as a Response-like object.
49
+ *
50
+ * @throws Will throw an error if unsupported headers are used or other validation fails.
51
+ */
52
+ fetch(url: string, config?: SimplifiedFetchRequestOptions): Promise<Response>;
53
+ /**
54
+ * Request Certificates from a Peer
55
+ * @param baseUrl
56
+ * @param certificatesToRequest
57
+ */
58
+ sendCertificateRequest(baseUrl: string, certificatesToRequest: RequestedCertificateSet): Promise<VerifiableCertificate[]>;
59
+ /**
60
+ * Return any certificates we've collected thus far, then clear them out.
61
+ */
62
+ consumeReceivedCertificates(): VerifiableCertificate[];
63
+ /**
64
+ * Serializes the HTTP request to be sent over the Transport.
65
+ *
66
+ * @param method - The HTTP method (e.g., 'GET', 'POST') for the request.
67
+ * @param headers - A record of HTTP headers to include in the request.
68
+ * @param body - The body of the request, if applicable (e.g., for POST/PUT requests).
69
+ * @param parsedUrl - The parsed URL object containing the full request URL.
70
+ * @param requestNonce - A unique random nonce to ensure request integrity.
71
+ * @returns A promise that resolves to a `Writer` containing the serialized request.
72
+ *
73
+ * @throws Will throw an error if unsupported headers are used or serialization fails.
74
+ */
75
+ private serializeRequest;
76
+ /**
77
+ * Handles a non-authenticated fetch requests and validates that the server is not claiming to be authenticated.
78
+ */
79
+ private handleFetchAndValidate;
80
+ /**
81
+ * If we get 402 Payment Required, we build a transaction via wallet.createAction()
82
+ * and re-attempt the request with an x-bsv-payment header.
83
+ */
84
+ private handlePaymentAndRetry;
85
+ private normalizeBodyToNumberArray;
86
+ }
87
+ export {};
88
+ //# sourceMappingURL=AuthFetchDebug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthFetchDebug.d.ts","sourceRoot":"","sources":["../../src/AuthFetchDebug.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC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gB;IAqG9B;;OAEG;YACW,sBAAsB;IAgBpC;;;OAGG;YACW,qBAAqB;YAyErB,0BAA0B;CAwDzC"}
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AuthFetch = void 0;
40
+ // @ts-nocheck
41
+ const Utils = __importStar(require("../../primitives/utils.js"));
42
+ const Random_js_1 = __importDefault(require("../../primitives/Random.js"));
43
+ const P2PKH_js_1 = __importDefault(require("../../script/templates/P2PKH.js"));
44
+ const PublicKey_js_1 = __importDefault(require("../../primitives/PublicKey.js"));
45
+ const createNonce_js_1 = require("../utils/createNonce.js");
46
+ const Peer_js_1 = require("../Peer.js");
47
+ const SessionManager_js_1 = require("../SessionManager.js");
48
+ const index_js_1 = require("../utils/index.js");
49
+ const PAYMENT_VERSION = '1.0';
50
+ /**
51
+ * AuthFetch provides a lightweight fetch client for interacting with servers
52
+ * over a simplified HTTP transport mechanism. It integrates session management, peer communication,
53
+ * and certificate handling to enable secure and mutually-authenticated requests.
54
+ *
55
+ * Additionally, it automatically handles 402 Payment Required responses by creating
56
+ * and sending BSV payment transactions when necessary.
57
+ */
58
+ class AuthFetch {
59
+ /**
60
+ * Constructs a new AuthFetch instance.
61
+ * @param wallet - The wallet instance for signing and authentication.
62
+ * @param requestedCertificates - Optional set of certificates to request from peers.
63
+ */
64
+ constructor(wallet, requestedCertificates, sessionManager) {
65
+ this.callbacks = {};
66
+ this.certificatesReceived = [];
67
+ this.peers = {};
68
+ this.wallet = wallet;
69
+ this.requestedCertificates = requestedCertificates;
70
+ this.sessionManager = sessionManager || new SessionManager_js_1.SessionManager();
71
+ }
72
+ /**
73
+ * Mutually authenticates and sends a HTTP request to a server.
74
+ *
75
+ * 1) Attempt the request.
76
+ * 2) If 402 Payment Required, automatically create and send payment.
77
+ * 3) Return the final response.
78
+ *
79
+ * @param url - The URL to send the request to.
80
+ * @param config - Configuration options for the request, including method, headers, and body.
81
+ * @returns A promise that resolves with the server's response, structured as a Response-like object.
82
+ *
83
+ * @throws Will throw an error if unsupported headers are used or other validation fails.
84
+ */
85
+ async fetch(url, config = {}) {
86
+ if (typeof config.retryCounter === 'number') {
87
+ if (config.retryCounter <= 0) {
88
+ throw new Error('Request failed after maximum number of retries.');
89
+ }
90
+ config.retryCounter--;
91
+ }
92
+ const response = await new Promise((async (resolve, reject) => {
93
+ try {
94
+ // Apply defaults
95
+ const { method = 'GET', headers = {}, body } = config;
96
+ // Extract a base url
97
+ const parsedUrl = new URL(url);
98
+ const baseURL = parsedUrl.origin;
99
+ // Create a new transport for this base url if needed
100
+ let peerToUse;
101
+ if (typeof this.peers[baseURL] === 'undefined') {
102
+ // Create a peer for the request
103
+ const newTransport = new SimplifiedFetchTransport(baseURL);
104
+ peerToUse = {
105
+ peer: new Peer_js_1.Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager),
106
+ pendingCertificateRequests: []
107
+ };
108
+ this.peers[baseURL] = peerToUse;
109
+ this.peers[baseURL].peer.listenForCertificatesReceived((senderPublicKey, certs) => {
110
+ this.certificatesReceived.push(...certs);
111
+ });
112
+ this.peers[baseURL].peer.listenForCertificatesRequested((async (verifier, requestedCertificates) => {
113
+ try {
114
+ this.peers[baseURL].pendingCertificateRequests.push(true);
115
+ const certificatesToInclude = await (0, index_js_1.getVerifiableCertificates)(this.wallet, requestedCertificates, verifier);
116
+ await this.peers[baseURL].peer.sendCertificateResponse(verifier, certificatesToInclude);
117
+ }
118
+ finally {
119
+ // Give the backend 500 ms to process the certificates we just sent, before releasing the queue entry
120
+ await new Promise(resolve => setTimeout(resolve, 500));
121
+ this.peers[baseURL].pendingCertificateRequests.shift();
122
+ }
123
+ }));
124
+ }
125
+ else {
126
+ // Check if there's a session associated with this baseURL
127
+ if (this.peers[baseURL].supportsMutualAuth === false) {
128
+ // Use standard fetch if mutual authentication is not supported
129
+ try {
130
+ const response = await this.handleFetchAndValidate(url, config, this.peers[baseURL]);
131
+ resolve(response);
132
+ }
133
+ catch (error) {
134
+ reject(error);
135
+ }
136
+ return;
137
+ }
138
+ peerToUse = this.peers[baseURL];
139
+ }
140
+ // Serialize the simplified fetch request.
141
+ const requestNonce = (0, Random_js_1.default)(32);
142
+ const requestNonceAsBase64 = Utils.toBase64(requestNonce);
143
+ const writer = await this.serializeRequest(method, headers, body, parsedUrl, requestNonce);
144
+ // Setup general message listener to resolve requests once a response is received
145
+ this.callbacks[requestNonceAsBase64] = { resolve, reject };
146
+ const listenerId = peerToUse.peer.listenForGeneralMessages((senderPublicKey, payload) => {
147
+ // Create a reader
148
+ const responseReader = new Utils.Reader(payload);
149
+ // Deserialize first 32 bytes of payload
150
+ const responseNonceAsBase64 = Utils.toBase64(responseReader.read(32));
151
+ if (responseNonceAsBase64 !== requestNonceAsBase64) {
152
+ return;
153
+ }
154
+ peerToUse.peer.stopListeningForGeneralMessages(listenerId);
155
+ // Save the identity key for the peer for future requests, since we have it here.
156
+ this.peers[baseURL].identityKey = senderPublicKey;
157
+ this.peers[baseURL].supportsMutualAuth = true;
158
+ // Status code
159
+ const statusCode = responseReader.readVarIntNum();
160
+ // Headers
161
+ const responseHeaders = {};
162
+ const nHeaders = responseReader.readVarIntNum();
163
+ if (nHeaders > 0) {
164
+ for (let i = 0; i < nHeaders; i++) {
165
+ const nHeaderKeyBytes = responseReader.readVarIntNum();
166
+ const headerKeyBytes = responseReader.read(nHeaderKeyBytes);
167
+ const headerKey = Utils.toUTF8(headerKeyBytes);
168
+ const nHeaderValueBytes = responseReader.readVarIntNum();
169
+ const headerValueBytes = responseReader.read(nHeaderValueBytes);
170
+ const headerValue = Utils.toUTF8(headerValueBytes);
171
+ responseHeaders[headerKey] = headerValue;
172
+ }
173
+ }
174
+ // Add back the server identity key header
175
+ responseHeaders['x-bsv-auth-identity-key'] = senderPublicKey;
176
+ // Body
177
+ let responseBody;
178
+ const responseBodyBytes = responseReader.readVarIntNum();
179
+ if (responseBodyBytes > 0) {
180
+ responseBody = responseReader.read(responseBodyBytes);
181
+ }
182
+ // Create the Response object
183
+ const responseValue = new Response(responseBody ? new Uint8Array(responseBody) : null, {
184
+ status: statusCode,
185
+ statusText: `${statusCode}`,
186
+ headers: new Headers(responseHeaders)
187
+ });
188
+ // Resolve or reject the correct request with the response data
189
+ this.callbacks[requestNonceAsBase64].resolve(responseValue);
190
+ // Clean up
191
+ delete this.callbacks[requestNonceAsBase64];
192
+ });
193
+ // Before sending general messages to the peer, ensure that no certificate requests are pending.
194
+ // This way, the user would need to choose to either allow or reject the certificate request first.
195
+ // If the server has a resource that requires certificates to be sent before access would be granted,
196
+ // this makes sure the user has a chance to send the certificates before the resource is requested.
197
+ if (peerToUse.pendingCertificateRequests.length > 0) {
198
+ await new Promise(resolve => {
199
+ setInterval(() => {
200
+ if (peerToUse.pendingCertificateRequests.length === 0) {
201
+ resolve();
202
+ }
203
+ }, 100); // Check every 100 ms for the user to finish responding
204
+ });
205
+ }
206
+ // Send the request, now that all listeners are set up
207
+ await peerToUse.peer.toPeer(writer.toArray(), peerToUse.identityKey).catch(async (error) => {
208
+ var _a;
209
+ if (error.message.includes('Session not found for nonce')) {
210
+ delete this.peers[baseURL];
211
+ (_a = config.retryCounter) !== null && _a !== void 0 ? _a : (config.retryCounter = 3);
212
+ const response = await this.fetch(url, config);
213
+ resolve(response);
214
+ return;
215
+ }
216
+ if (error.message.includes('HTTP server failed to authenticate')) {
217
+ try {
218
+ const response = await this.handleFetchAndValidate(url, config, peerToUse);
219
+ resolve(response);
220
+ return;
221
+ }
222
+ catch (fetchError) {
223
+ reject(fetchError);
224
+ }
225
+ }
226
+ else {
227
+ reject(error);
228
+ }
229
+ });
230
+ }
231
+ catch (e) {
232
+ reject(e);
233
+ }
234
+ }));
235
+ // Check if server requires payment to access the requested route
236
+ if (response.status === 402) {
237
+ // Create and attach a payment, then retry
238
+ return await this.handlePaymentAndRetry(url, config, response);
239
+ }
240
+ return response;
241
+ }
242
+ /**
243
+ * Request Certificates from a Peer
244
+ * @param baseUrl
245
+ * @param certificatesToRequest
246
+ */
247
+ async sendCertificateRequest(baseUrl, certificatesToRequest) {
248
+ const parsedUrl = new URL(baseUrl);
249
+ const baseURL = parsedUrl.origin;
250
+ let peerToUse;
251
+ if (typeof this.peers[baseURL] !== 'undefined') {
252
+ peerToUse = { peer: this.peers[baseURL].peer };
253
+ }
254
+ else {
255
+ const newTransport = new SimplifiedFetchTransport(baseURL);
256
+ peerToUse = {
257
+ peer: new Peer_js_1.Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager)
258
+ };
259
+ this.peers[baseURL] = peerToUse;
260
+ }
261
+ // Return a promise that resolves when certificates are received
262
+ return await new Promise((async (resolve, reject) => {
263
+ // Set up the listener before making the request
264
+ const callbackId = peerToUse.peer.listenForCertificatesReceived((_senderPublicKey, certs) => {
265
+ peerToUse.peer.stopListeningForCertificatesReceived(callbackId);
266
+ this.certificatesReceived.push(...certs);
267
+ resolve(certs);
268
+ });
269
+ try {
270
+ // Initiate the certificate request
271
+ await peerToUse.peer.requestCertificates(certificatesToRequest, peerToUse.identityKey);
272
+ }
273
+ catch (err) {
274
+ peerToUse.peer.stopListeningForCertificatesReceived(callbackId);
275
+ reject(err);
276
+ }
277
+ }));
278
+ }
279
+ /**
280
+ * Return any certificates we've collected thus far, then clear them out.
281
+ */
282
+ consumeReceivedCertificates() {
283
+ return this.certificatesReceived.splice(0);
284
+ }
285
+ /**
286
+ * Serializes the HTTP request to be sent over the Transport.
287
+ *
288
+ * @param method - The HTTP method (e.g., 'GET', 'POST') for the request.
289
+ * @param headers - A record of HTTP headers to include in the request.
290
+ * @param body - The body of the request, if applicable (e.g., for POST/PUT requests).
291
+ * @param parsedUrl - The parsed URL object containing the full request URL.
292
+ * @param requestNonce - A unique random nonce to ensure request integrity.
293
+ * @returns A promise that resolves to a `Writer` containing the serialized request.
294
+ *
295
+ * @throws Will throw an error if unsupported headers are used or serialization fails.
296
+ */
297
+ async serializeRequest(method, headers, body, parsedUrl, requestNonce) {
298
+ const writer = new Utils.Writer();
299
+ // Write request nonce
300
+ writer.write(requestNonce);
301
+ // Method length
302
+ writer.writeVarIntNum(method.length);
303
+ // Method
304
+ writer.write(Utils.toArray(method));
305
+ // Handle pathname (e.g. /path/to/resource)
306
+ if (parsedUrl.pathname.length > 0) {
307
+ // Pathname length
308
+ const pathnameAsArray = Utils.toArray(parsedUrl.pathname);
309
+ writer.writeVarIntNum(pathnameAsArray.length);
310
+ // Pathname
311
+ writer.write(pathnameAsArray);
312
+ }
313
+ else {
314
+ writer.writeVarIntNum(-1);
315
+ }
316
+ // Handle search params (e.g. ?q=hello)
317
+ if (parsedUrl.search.length > 0) {
318
+ // search length
319
+ const searchAsArray = Utils.toArray(parsedUrl.search);
320
+ writer.writeVarIntNum(searchAsArray.length);
321
+ // search
322
+ writer.write(searchAsArray);
323
+ }
324
+ else {
325
+ writer.writeVarIntNum(-1);
326
+ }
327
+ // Construct headers to send / sign:
328
+ // Ensures clients only provided supported HTTP request headers
329
+ // - Include custom headers prefixed with x-bsv (excluding those starting with x-bsv-auth)
330
+ // - Include a normalized version of the content-type header
331
+ // - Include the authorization header
332
+ const includedHeaders = [];
333
+ for (let [k, v] of Object.entries(headers)) {
334
+ k = k.toLowerCase(); // We will always sign lower-case header keys
335
+ if (k.startsWith('x-bsv-') || k === 'authorization') {
336
+ if (k.startsWith('x-bsv-auth')) {
337
+ throw new Error('No BSV auth headers allowed here!');
338
+ }
339
+ includedHeaders.push([k, v]);
340
+ }
341
+ else if (k.startsWith('content-type')) {
342
+ // Normalize the Content-Type header by removing any parameters (e.g., "; charset=utf-8")
343
+ v = v.split(';')[0].trim();
344
+ includedHeaders.push([k, v]);
345
+ }
346
+ else {
347
+ throw new Error('Unsupported header in the simplified fetch implementation. Only content-type, authorization, and x-bsv-* headers are supported.');
348
+ }
349
+ }
350
+ // Sort the headers by key to ensure a consistent order for signing and verification.
351
+ includedHeaders.sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
352
+ // nHeaders
353
+ writer.writeVarIntNum(includedHeaders.length);
354
+ for (let i = 0; i < includedHeaders.length; i++) {
355
+ // headerKeyLength
356
+ const headerKeyAsArray = Utils.toArray(includedHeaders[i][0], 'utf8');
357
+ writer.writeVarIntNum(headerKeyAsArray.length);
358
+ // headerKey
359
+ writer.write(headerKeyAsArray);
360
+ // headerValueLength
361
+ const headerValueAsArray = Utils.toArray(includedHeaders[i][1], 'utf8');
362
+ writer.writeVarIntNum(headerValueAsArray.length);
363
+ // headerValue
364
+ writer.write(headerValueAsArray);
365
+ }
366
+ // If method typically carries a body and body is undefined, default it
367
+ // This prevents signature verification errors due to mismatch default body types with express
368
+ const methodsThatTypicallyHaveBody = ['POST', 'PUT', 'PATCH', 'DELETE'];
369
+ if (methodsThatTypicallyHaveBody.includes(method.toUpperCase()) && body === undefined) {
370
+ // Check if content-type is application/json
371
+ const contentTypeHeader = includedHeaders.find(([k]) => k === 'content-type');
372
+ if (contentTypeHeader && contentTypeHeader[1].includes('application/json')) {
373
+ body = '{}';
374
+ }
375
+ else {
376
+ body = '';
377
+ }
378
+ }
379
+ // Handle body
380
+ if (body) {
381
+ const reqBody = await this.normalizeBodyToNumberArray(body); // Use the utility function
382
+ writer.writeVarIntNum(reqBody.length);
383
+ writer.write(reqBody);
384
+ }
385
+ else {
386
+ writer.writeVarIntNum(-1); // No body
387
+ }
388
+ return writer;
389
+ }
390
+ /**
391
+ * Handles a non-authenticated fetch requests and validates that the server is not claiming to be authenticated.
392
+ */
393
+ async handleFetchAndValidate(url, config, peerToUse) {
394
+ const response = await fetch(url, config);
395
+ response.headers.forEach(header => {
396
+ if (header.toLocaleLowerCase().startsWith('x-bsv')) {
397
+ throw new Error('The server is trying to claim it has been authenticated when it has not!');
398
+ }
399
+ });
400
+ if (response.ok) {
401
+ peerToUse.supportsMutualAuth = false;
402
+ return response;
403
+ }
404
+ else {
405
+ throw new Error(`Request failed with status: ${response.status}`);
406
+ }
407
+ }
408
+ /**
409
+ * If we get 402 Payment Required, we build a transaction via wallet.createAction()
410
+ * and re-attempt the request with an x-bsv-payment header.
411
+ */
412
+ async handlePaymentAndRetry(url, config = {}, originalResponse) {
413
+ var _a;
414
+ // Make sure the server is using the correct payment version
415
+ const paymentVersion = originalResponse.headers.get('x-bsv-payment-version');
416
+ if (!paymentVersion || paymentVersion !== PAYMENT_VERSION) {
417
+ throw new Error(`Unsupported x-bsv-payment-version response header. Client version: ${PAYMENT_VERSION}, Server version: ${paymentVersion}`);
418
+ }
419
+ // Get required headers from the 402 response
420
+ const satoshisRequiredHeader = originalResponse.headers.get('x-bsv-payment-satoshis-required');
421
+ if (!satoshisRequiredHeader) {
422
+ throw new Error('Missing x-bsv-payment-satoshis-required response header.');
423
+ }
424
+ const satoshisRequired = parseInt(satoshisRequiredHeader);
425
+ if (isNaN(satoshisRequired) || satoshisRequired <= 0) {
426
+ throw new Error('Invalid x-bsv-payment-satoshis-required response header value.');
427
+ }
428
+ const serverIdentityKey = originalResponse.headers.get('x-bsv-auth-identity-key');
429
+ if (!serverIdentityKey) {
430
+ throw new Error('Missing x-bsv-auth-identity-key response header.');
431
+ }
432
+ const derivationPrefix = originalResponse.headers.get('x-bsv-payment-derivation-prefix');
433
+ if (typeof derivationPrefix !== 'string' || derivationPrefix.length < 1) {
434
+ throw new Error('Missing x-bsv-payment-derivation-prefix response header.');
435
+ }
436
+ // Create a random suffix for the derivation path
437
+ const derivationSuffix = await (0, createNonce_js_1.createNonce)(this.wallet);
438
+ // Derive the script hex from the server identity key
439
+ const { publicKey: derivedPublicKey } = await this.wallet.getPublicKey({
440
+ protocolID: [2, '3241645161d8'], // wallet payment protocol
441
+ keyID: `${derivationPrefix} ${derivationSuffix}`,
442
+ counterparty: serverIdentityKey
443
+ });
444
+ const lockingScript = new P2PKH_js_1.default().lock(PublicKey_js_1.default.fromString(derivedPublicKey).toAddress()).toHex();
445
+ // Create the payment transaction using createAction
446
+ const { tx } = await this.wallet.createAction({
447
+ description: `Payment for request to ${new URL(url).origin}`,
448
+ outputs: [{
449
+ satoshis: satoshisRequired,
450
+ lockingScript,
451
+ customInstructions: JSON.stringify({ derivationPrefix, derivationSuffix, payee: serverIdentityKey }),
452
+ outputDescription: 'HTTP request payment'
453
+ }],
454
+ options: {
455
+ randomizeOutputs: false
456
+ }
457
+ });
458
+ // Attach the payment to the request headers
459
+ config.headers = config.headers || {};
460
+ config.headers['x-bsv-payment'] = JSON.stringify({
461
+ derivationPrefix,
462
+ derivationSuffix,
463
+ transaction: Utils.toBase64(tx)
464
+ });
465
+ (_a = config.retryCounter) !== null && _a !== void 0 ? _a : (config.retryCounter = 3);
466
+ // Re-attempt request with payment attached
467
+ return this.fetch(url, config);
468
+ }
469
+ async normalizeBodyToNumberArray(body) {
470
+ // 0. Null / undefined
471
+ if (body == null) {
472
+ return [];
473
+ }
474
+ // 1. object
475
+ if (typeof body === 'object') {
476
+ return Utils.toArray(JSON.stringify(body, 'utf8'));
477
+ }
478
+ // 2. number[]
479
+ if (Array.isArray(body) && body.every((item) => typeof item === 'number')) {
480
+ return body; // Return the array as is
481
+ }
482
+ // 3. string
483
+ if (typeof body === 'string') {
484
+ return Utils.toArray(body, 'utf8');
485
+ }
486
+ // 4. ArrayBuffer / TypedArrays
487
+ if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
488
+ const typedArray = body instanceof ArrayBuffer ? new Uint8Array(body) : new Uint8Array(body.buffer);
489
+ return Array.from(typedArray);
490
+ }
491
+ // 5. Blob
492
+ if (body instanceof Blob) {
493
+ const arrayBuffer = await body.arrayBuffer();
494
+ return Array.from(new Uint8Array(arrayBuffer));
495
+ }
496
+ // 6. FormData
497
+ if (body instanceof FormData) {
498
+ const entries = [];
499
+ body.forEach((value, key) => {
500
+ entries.push([key, value.toString()]);
501
+ });
502
+ const urlEncoded = new URLSearchParams(entries).toString();
503
+ return Utils.toArray(urlEncoded, 'utf8');
504
+ }
505
+ // 7. URLSearchParams
506
+ if (body instanceof URLSearchParams) {
507
+ return Utils.toArray(body.toString(), 'utf8');
508
+ }
509
+ // 8. ReadableStream
510
+ if (body instanceof ReadableStream) {
511
+ throw new Error('ReadableStream cannot be directly converted to number[].');
512
+ }
513
+ // 9. Fallback
514
+ throw new Error('Unsupported body type in this SimplifiedFetch implementation.');
515
+ }
516
+ }
517
+ exports.AuthFetch = AuthFetch;
518
+ //# sourceMappingURL=AuthFetchDebug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthFetchDebug.js","sourceRoot":"","sources":["../../src/AuthFetchDebug.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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