@algorandfoundation/algokit-utils 7.0.0-beta.8 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/account/account.js +6 -4
- package/account/account.js.map +1 -1
- package/account/account.mjs +6 -4
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.js.map +1 -1
- package/amount.mjs.map +1 -1
- package/app-client.js.map +1 -1
- package/app-client.mjs.map +1 -1
- package/app-deploy.js +2 -10
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +3 -11
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +2 -2
- package/app.js +2 -2
- package/app.js.map +1 -1
- package/app.mjs +2 -2
- package/app.mjs.map +1 -1
- package/asset.js.map +1 -1
- package/asset.mjs.map +1 -1
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs.map +1 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +6 -0
- package/index.js.map +1 -1
- package/index.mjs +2 -1
- package/index.mjs.map +1 -1
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.js.map +1 -1
- package/network-client.mjs.map +1 -1
- package/package.json +5 -5
- package/testing/account.js.map +1 -1
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/legacy-bridge.js +2 -2
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +3 -3
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.js +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +14 -7
- package/transaction/transaction.js +57 -31
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +55 -30
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +1 -1
- package/types/account-manager.js +10 -8
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +11 -9
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +9 -0
- package/types/account.js.map +1 -1
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +2 -2
- package/types/algorand-client-transaction-creator.d.ts +5 -3
- package/types/algorand-client-transaction-creator.js +3 -1
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +3 -1
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +12 -8
- package/types/algorand-client-transaction-sender.js +6 -2
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +6 -2
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +3 -4
- package/types/algorand-client.js +2 -5
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +4 -4
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.js.map +1 -1
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +31 -20
- package/types/app-arc56.js.map +1 -1
- package/types/app-arc56.mjs.map +1 -1
- package/types/app-client.d.ts +97 -78
- package/types/app-client.js +171 -54
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +169 -52
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.js +1 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +2 -2
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +30 -10
- package/types/app-factory.js +26 -20
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +26 -20
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.js +105 -23
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +105 -23
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.js +8 -2
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +8 -2
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +8 -7
- package/types/app.js.map +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +4 -4
- package/types/asset-manager.js +2 -2
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +2 -2
- package/types/asset-manager.mjs.map +1 -1
- package/types/async-event-emitter.d.ts +1 -10
- package/types/async-event-emitter.js +0 -5
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs +1 -6
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.js +2 -2
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +2 -2
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +40 -25
- package/types/composer.js +114 -40
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +115 -39
- package/types/composer.mjs.map +1 -1
- package/types/config.js.map +1 -1
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +1 -1
- package/types/debugging.js +1 -1
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +1 -1
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs.map +1 -1
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.js +1 -1
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +2 -2
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -3
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +1 -1
- package/types/urlTokenBaseHTTPClient.js.map +1 -1
- package/types/urlTokenBaseHTTPClient.mjs.map +1 -1
- package/util.js.map +1 -1
- package/util.mjs.map +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.EventType = void 0;
|
|
4
|
+
(function (EventType) {
|
|
5
|
+
EventType["TxnGroupSimulated"] = "TxnGroupSimulated";
|
|
6
|
+
EventType["AppCompiled"] = "AppCompiled";
|
|
7
|
+
})(exports.EventType || (exports.EventType = {}));
|
|
8
|
+
//# sourceMappingURL=lifecycle-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-events.js","sources":["../../src/types/lifecycle-events.ts"],"sourcesContent":["import { AVMTracesEventData, TealSourcesDebugEventData } from './debugging'\n\nexport enum EventType {\n TxnGroupSimulated = 'TxnGroupSimulated',\n AppCompiled = 'AppCompiled',\n}\n\nexport type EventDataMap = {\n [EventType.TxnGroupSimulated]: AVMTracesEventData\n [EventType.AppCompiled]: TealSourcesDebugEventData\n [key: string]: unknown\n}\n"],"names":["EventType"],"mappings":";;AAEYA;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC;AACvC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC7B,CAAC,EAHWA,iBAAS,KAATA,iBAAS,GAGpB,EAAA,CAAA,CAAA;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-events.mjs","sources":["../../src/types/lifecycle-events.ts"],"sourcesContent":["import { AVMTracesEventData, TealSourcesDebugEventData } from './debugging'\n\nexport enum EventType {\n TxnGroupSimulated = 'TxnGroupSimulated',\n AppCompiled = 'AppCompiled',\n}\n\nexport type EventDataMap = {\n [EventType.TxnGroupSimulated]: AVMTracesEventData\n [EventType.AppCompiled]: TealSourcesDebugEventData\n [key: string]: unknown\n}\n"],"names":[],"mappings":"IAEY;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC;AACvC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC7B,CAAC,EAHW,SAAS,KAAT,SAAS,GAGpB,EAAA,CAAA,CAAA;;;;"}
|
package/types/logging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":";;AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK
|
|
1
|
+
{"version":3,"file":"logging.js","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":";;AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,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["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":"AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK
|
|
1
|
+
{"version":3,"file":"logging.mjs","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":"AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK;;AAGT,MAAA,iBAAiB,GAAW;IACvC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;AACjB,IAAA,KAAK,EAAE,MAAK,GAAG;;AAGJ,MAAA,oBAAoB,GAAW;IAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,KAAK,EAAE,OAAO,CAAC,KAAK;;AAGT,MAAA,oBAAoB,GAAW;IAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,IAAI,EAAE,MAAK,GAAG;AACd,IAAA,OAAO,EAAE,MAAK,GAAG;AACjB,IAAA,KAAK,EAAE,MAAK,GAAG;;AAGjB;AACa,MAAA,UAAU,GAAW;;AAEhC,IAAA,KAAK,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAExE,IAAA,IAAI,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAEvE,IAAA,IAAI,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAEvE,IAAA,OAAO,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAE1E,IAAA,KAAK,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;;;;"}
|
package/types/logic-error.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type algosdk from 'algosdk';
|
|
2
1
|
/**
|
|
3
2
|
* Details about a smart contract logic error
|
|
4
3
|
*/
|
|
@@ -30,7 +29,7 @@ export declare class LogicError extends Error {
|
|
|
30
29
|
* Create a new logic error object.
|
|
31
30
|
* @param errorDetails The details of the logic error
|
|
32
31
|
* @param program The TEAL source code, split by line
|
|
33
|
-
* @param
|
|
32
|
+
* @param getLineForPc The source map of the TEAL source code
|
|
34
33
|
*/
|
|
35
|
-
constructor(errorDetails: LogicErrorDetails, program: string[],
|
|
34
|
+
constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined);
|
|
36
35
|
}
|
package/types/logic-error.js
CHANGED
|
@@ -25,15 +25,15 @@ class LogicError extends Error {
|
|
|
25
25
|
* Create a new logic error object.
|
|
26
26
|
* @param errorDetails The details of the logic error
|
|
27
27
|
* @param program The TEAL source code, split by line
|
|
28
|
-
* @param
|
|
28
|
+
* @param getLineForPc The source map of the TEAL source code
|
|
29
29
|
*/
|
|
30
|
-
constructor(errorDetails, program,
|
|
30
|
+
constructor(errorDetails, program, getLineForPc) {
|
|
31
31
|
super();
|
|
32
32
|
this.lines = 5;
|
|
33
33
|
this.teal_line = 0;
|
|
34
34
|
this.led = errorDetails;
|
|
35
35
|
this.program = program;
|
|
36
|
-
const line =
|
|
36
|
+
const line = getLineForPc(errorDetails.pc);
|
|
37
37
|
this.teal_line = line === undefined ? 0 : line;
|
|
38
38
|
this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`;
|
|
39
39
|
if (this.teal_line > 0) {
|
package/types/logic-error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic-error.js","sources":["../../src/types/logic-error.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"logic-error.js","sources":["../../src/types/logic-error.ts"],"sourcesContent":["const LOGIC_ERROR = /transaction ([A-Z0-9]+): logic eval error: (.*). Details: .*pc=([0-9]+).*/\n\n/**\n * Details about a smart contract logic error\n */\nexport interface LogicErrorDetails {\n /** The ID of the transaction with the logic error */\n txId: string\n /** The program counter where the error was */\n pc: number\n /** The error message */\n msg: string\n /** The full error description */\n desc: string\n /** Any trace information included in the error */\n traces: Record<string, unknown>[]\n}\n\n/** Wraps key functionality around processing logic errors */\nexport class LogicError extends Error {\n /** Takes an error message and parses out the details of any logic errors in there.\n * @param error The error message to parse\n * @returns The logic error details if any, or undefined\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static parseLogicError(error: any): LogicErrorDetails | undefined {\n const errorMessage = error.message\n const res = LOGIC_ERROR.exec(errorMessage)\n if (res === null || res.length <= 3) return undefined\n\n return {\n txId: res[1],\n msg: res[2],\n desc: errorMessage,\n pc: parseInt(res[3] ? res[3] : '0'),\n traces: error.traces,\n } as LogicErrorDetails\n }\n\n public led: LogicErrorDetails\n public program: string[]\n public lines = 5\n public teal_line = 0\n override stack?: string\n\n /**\n * Create a new logic error object.\n * @param errorDetails The details of the logic error\n * @param program The TEAL source code, split by line\n * @param getLineForPc The source map of the TEAL source code\n */\n constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined) {\n super()\n this.led = errorDetails\n this.program = program\n\n const line = getLineForPc(errorDetails.pc)\n this.teal_line = line === undefined ? 0 : line\n\n this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`\n\n if (this.teal_line > 0) {\n const start = this.teal_line > this.lines ? this.teal_line - this.lines : 0\n const stop = program.length > this.teal_line + this.lines ? this.teal_line + this.lines : program.length\n\n const stack_lines = program.slice(start, stop)\n\n stack_lines[stack_lines.length / 2] += ' <--- Error'\n\n this.stack = stack_lines.join('\\n')\n }\n }\n}\n"],"names":[],"mappings":";;AAAA,MAAM,WAAW,GAAG,2EAA2E;AAkB/F;AACM,MAAO,UAAW,SAAQ,KAAK,CAAA;AACnC;;;AAGG;;IAEH,OAAO,eAAe,CAAC,KAAU,EAAA;AAC/B,QAAA,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO;QAClC,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1C,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;AAAE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AAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;YAE9C,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,aAAa;YAEpD,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;;AAGxC;;;;"}
|
package/types/logic-error.mjs
CHANGED
|
@@ -23,15 +23,15 @@ class LogicError extends Error {
|
|
|
23
23
|
* Create a new logic error object.
|
|
24
24
|
* @param errorDetails The details of the logic error
|
|
25
25
|
* @param program The TEAL source code, split by line
|
|
26
|
-
* @param
|
|
26
|
+
* @param getLineForPc The source map of the TEAL source code
|
|
27
27
|
*/
|
|
28
|
-
constructor(errorDetails, program,
|
|
28
|
+
constructor(errorDetails, program, getLineForPc) {
|
|
29
29
|
super();
|
|
30
30
|
this.lines = 5;
|
|
31
31
|
this.teal_line = 0;
|
|
32
32
|
this.led = errorDetails;
|
|
33
33
|
this.program = program;
|
|
34
|
-
const line =
|
|
34
|
+
const line = getLineForPc(errorDetails.pc);
|
|
35
35
|
this.teal_line = line === undefined ? 0 : line;
|
|
36
36
|
this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`;
|
|
37
37
|
if (this.teal_line > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic-error.mjs","sources":["../../src/types/logic-error.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"logic-error.mjs","sources":["../../src/types/logic-error.ts"],"sourcesContent":["const LOGIC_ERROR = /transaction ([A-Z0-9]+): logic eval error: (.*). Details: .*pc=([0-9]+).*/\n\n/**\n * Details about a smart contract logic error\n */\nexport interface LogicErrorDetails {\n /** The ID of the transaction with the logic error */\n txId: string\n /** The program counter where the error was */\n pc: number\n /** The error message */\n msg: string\n /** The full error description */\n desc: string\n /** Any trace information included in the error */\n traces: Record<string, unknown>[]\n}\n\n/** Wraps key functionality around processing logic errors */\nexport class LogicError extends Error {\n /** Takes an error message and parses out the details of any logic errors in there.\n * @param error The error message to parse\n * @returns The logic error details if any, or undefined\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static parseLogicError(error: any): LogicErrorDetails | undefined {\n const errorMessage = error.message\n const res = LOGIC_ERROR.exec(errorMessage)\n if (res === null || res.length <= 3) return undefined\n\n return {\n txId: res[1],\n msg: res[2],\n desc: errorMessage,\n pc: parseInt(res[3] ? res[3] : '0'),\n traces: error.traces,\n } as LogicErrorDetails\n }\n\n public led: LogicErrorDetails\n public program: string[]\n public lines = 5\n public teal_line = 0\n override stack?: string\n\n /**\n * Create a new logic error object.\n * @param errorDetails The details of the logic error\n * @param program The TEAL source code, split by line\n * @param getLineForPc The source map of the TEAL source code\n */\n constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined) {\n super()\n this.led = errorDetails\n this.program = program\n\n const line = getLineForPc(errorDetails.pc)\n this.teal_line = line === undefined ? 0 : line\n\n this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`\n\n if (this.teal_line > 0) {\n const start = this.teal_line > this.lines ? this.teal_line - this.lines : 0\n const stop = program.length > this.teal_line + this.lines ? this.teal_line + this.lines : program.length\n\n const stack_lines = program.slice(start, stop)\n\n stack_lines[stack_lines.length / 2] += ' <--- Error'\n\n this.stack = stack_lines.join('\\n')\n }\n }\n}\n"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,2EAA2E;AAkB/F;AACM,MAAO,UAAW,SAAQ,KAAK,CAAA;AACnC;;;AAGG;;IAEH,OAAO,eAAe,CAAC,KAAU,EAAA;AAC/B,QAAA,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO;QAClC,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1C,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;AAAE,YAAA,OAAO,SAAS;QAErD,OAAO;AACL,YAAA,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AACZ,YAAA,GA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AC,IAAI,aAAa;YAEpD,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;;AAGxC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-client.js","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":";;AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc
|
|
1
|
+
{"version":3,"file":"network-client.js","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":";;AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc;AAChG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-client.mjs","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":"AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc
|
|
1
|
+
{"version":3,"file":"network-client.mjs","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":"AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc;AAChG;;;;"}
|
package/types/testing.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TransactionLogger } from '../testing';
|
|
|
3
3
|
import { TestLogger } from '../testing/test-logger';
|
|
4
4
|
import { AlgoAmount } from '../types/amount';
|
|
5
5
|
import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account';
|
|
6
|
-
import AlgorandClient from './algorand-client';
|
|
6
|
+
import { AlgorandClient } from './algorand-client';
|
|
7
7
|
import { TransactionLookupResult } from './indexer';
|
|
8
8
|
import { AlgoConfig } from './network-client';
|
|
9
9
|
import Account = algosdk.Account;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlTokenBaseHTTPClient.js","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":["Buffer"],"mappings":";;;;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAwB;AAGvC,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;KACzB;AACF,CAAA;AAID;;;;AAIG;MACU,sBAAsB,CAAA;;AAKjC,IAAA,WAAA,CACE,WAAwB,EACxB,UAAkB,EAClB,IAAsB;;AAEd,IAAA,cAAA,GAAsC,EAAE,EAAA;QAAxC,IAAc,CAAA,cAAA,GAAd,cAAc,CAA0B;;;;AAKhD,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,CAAG,EAAA,UAAU,GAAG,CAAA;AAChF,QAA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MAAM,MAAM,CACV,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB,CAAA;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC,CAAA;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;KACvD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"urlTokenBaseHTTPClient.js","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":["Buffer"],"mappings":";;;;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ;AAGf,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ;;AAE3B;AAID;;;;AAIG;MACU,sBAAsB,CAAA;;AAKjC,IAAA,WAAA,CACE,WAAwB,EACxB,UAAkB,EAClB,IAAsB;;AAEd,IAAA,cAAA,GAAsC,EAAE,EAAA;QAAxC,IAAc,CAAA,cAAA,GAAd,cAAc;;;;AAKtB,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,CAAG,EAAA,UAAU,GAAG;AAChF,QAAA,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC;AAC9C,QAAA,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;AAC/B,YAAA,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE;;QAGtC,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACvC,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;;AAGvE,QAAA,IAAI,CAAC,OAAO,GAAG,aAAa;AAC5B,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;;AAGhC;;;;;;;AAOG;IACK,MAAM,CAAC,YAAoB,EAAE,KAAqB,EAAA;AACxD,QAAA,IAAI,iBAAyB;AAC7B,QAAA,IAAI,YAAY,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D,MAAM,IAAI,CACR,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;IAGxD,MAAM,MAAM,CACV,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;AAEzD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlTokenBaseHTTPClient.mjs","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":[],"mappings":";;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAwB;AAGvC,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;KACzB;AACF,CAAA;AAID;;;;AAIG;MACU,sBAAsB,CAAA;;AAKjC,IAAA,WAAA,CACE,WAAwB,EACxB,UAAkB,EAClB,IAAsB;;AAEd,IAAA,cAAA,GAAsC,EAAE,EAAA;QAAxC,IAAc,CAAA,cAAA,GAAd,cAAc,CAA0B;;;;AAKhD,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG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sB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;KACvD;IAED,MAAM,MAAM,CACV,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB,CAAA;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC,CAAA;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;KACvD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"urlTokenBaseHTTPClient.mjs","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":[],"mappings":";;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ;AAGf,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ;;AAE3B;AAID;;;;AAIG;MACU,sBAAsB,CAAA;;AAKjC,IAAA,WAAA,CACE,WAAwB,EACxB,UAAkB,EAClB,IAAsB;;AAEd,IAAA,cAAA,GAAsC,EAAE,EAAA;QAAxC,IAAc,CAAA,cAAA,GAAd,cAAc;;;;AAKtB,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,CAAG,EAAA,UAAU,GAAG;AAChF,QAAA,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC;AAC9C,QAAA,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;AAC/B,YAAA,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE;;QAGtC,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACvC,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;;AAGvE,QAAA,IAAI,CAAC,OAAO,GAAG,aAAa;AAC5B,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;;AAGhC;;;;;;;AAOG;IACK,MAAM,CAAC,YAAoB,EAAE,KAAqB,EAAA;AACxD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sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;IAGxD,MAAM,IAAI,CACR,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;IAGxD,MAAM,MAAM,CACV,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;AAEzD;;;;"}
|
package/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAC3C,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,oFAAA,CAAsF,CAC9G;;SACI,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAClD,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,qFAAA,CAAuF,CAC/G;;AAEH,IAAA,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB;AAEM,MAAO,qBAAsB,SAAQ,KAAK,CAAA;AAAG;AAEnD;;;;;;AAMG;AACU,MAAA,mBAAmB,GAAG,C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MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC;AAAE,YAAA,OAAO,KAAK;;AAE7C,IAAA,OAAO,IAAI;AACb;;;;;;;;;"}
|
package/util.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.mjs","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK
|
|
1
|
+
{"version":3,"file":"util.mjs","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAC3C,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