@algorandfoundation/algokit-utils 10.0.0-alpha.1 → 10.0.0-alpha.11
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/README.md +27 -5
- package/_virtual/rolldown_runtime.js +20 -11
- package/_virtual/rolldown_runtime.mjs +10 -5
- package/algo25/index.d.ts +2 -0
- package/algo25/index.js +9 -0
- package/algo25/index.mjs +3 -0
- package/algod-client/index.d.ts +2 -5
- package/package.json +1 -1
- package/packages/abi/src/abi-method.d.ts +1 -1
- package/packages/abi/src/abi-method.js.map +1 -1
- package/packages/abi/src/abi-method.mjs.map +1 -1
- package/packages/abi/src/abi-type.d.ts +1 -1
- package/packages/abi/src/abi-type.js +4 -2
- package/packages/abi/src/abi-type.js.map +1 -1
- package/packages/abi/src/abi-type.mjs +4 -2
- package/packages/abi/src/abi-type.mjs.map +1 -1
- package/packages/abi/src/arc56-contract.js +1 -0
- package/packages/abi/src/arc56-contract.js.map +1 -1
- package/packages/abi/src/arc56-contract.mjs +1 -0
- package/packages/abi/src/arc56-contract.mjs.map +1 -1
- package/packages/algo25/src/english.js.map +1 -1
- package/packages/algo25/src/english.mjs.map +1 -1
- package/packages/algo25/src/index.d.ts +40 -0
- package/packages/algo25/src/index.js +44 -0
- package/packages/algo25/src/index.js.map +1 -1
- package/packages/algo25/src/index.mjs +39 -1
- package/packages/algo25/src/index.mjs.map +1 -1
- package/packages/algod_client/src/apis/api-service.d.ts +44 -44
- package/packages/algod_client/src/apis/api-service.js +153 -153
- package/packages/algod_client/src/apis/api-service.js.map +1 -1
- package/packages/algod_client/src/apis/api-service.mjs +153 -153
- package/packages/algod_client/src/apis/api-service.mjs.map +1 -1
- package/packages/algod_client/src/core/api-error.js +3 -1
- package/packages/algod_client/src/core/api-error.js.map +1 -1
- package/packages/algod_client/src/core/api-error.mjs +3 -1
- package/packages/algod_client/src/core/api-error.mjs.map +1 -1
- package/packages/algod_client/src/core/model-runtime.js +4 -4
- package/packages/algod_client/src/core/model-runtime.js.map +1 -1
- package/packages/algod_client/src/core/model-runtime.mjs +6 -6
- package/packages/algod_client/src/core/model-runtime.mjs.map +1 -1
- package/packages/algod_client/src/models/account-participation.js +4 -4
- package/packages/algod_client/src/models/account-participation.js.map +1 -1
- package/packages/algod_client/src/models/account-participation.mjs +4 -4
- package/packages/algod_client/src/models/account-participation.mjs.map +1 -1
- package/packages/algod_client/src/models/application-state-schema.d.ts +2 -2
- package/packages/algod_client/src/models/application-state-schema.js +2 -2
- package/packages/algod_client/src/models/application-state-schema.js.map +1 -1
- package/packages/algod_client/src/models/application-state-schema.mjs +2 -2
- package/packages/algod_client/src/models/application-state-schema.mjs.map +1 -1
- package/packages/algod_client/src/models/asset-params.js +2 -1
- package/packages/algod_client/src/models/asset-params.js.map +1 -1
- package/packages/algod_client/src/models/asset-params.mjs +2 -1
- package/packages/algod_client/src/models/asset-params.mjs.map +1 -1
- package/packages/algod_client/src/models/block-response.js +1 -2
- package/packages/algod_client/src/models/block-response.js.map +1 -1
- package/packages/algod_client/src/models/block-response.mjs +2 -3
- package/packages/algod_client/src/models/block-response.mjs.map +1 -1
- package/packages/algod_client/src/models/block.d.ts +49 -29
- package/packages/algod_client/src/models/block.js +174 -98
- package/packages/algod_client/src/models/block.js.map +1 -1
- package/packages/algod_client/src/models/block.mjs +174 -98
- package/packages/algod_client/src/models/block.mjs.map +1 -1
- package/packages/algod_client/src/models/ledger-state-delta.js +1 -1
- package/packages/algod_client/src/models/ledger-state-delta.js.map +1 -1
- package/packages/algod_client/src/models/ledger-state-delta.mjs +2 -2
- package/packages/algod_client/src/models/ledger-state-delta.mjs.map +1 -1
- package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.d.ts +3 -5
- package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.js +4 -6
- package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.js.map +1 -1
- package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.mjs +3 -5
- package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.mjs.map +1 -1
- package/packages/algod_client/src/models/transaction-parameters-response.js +2 -2
- package/packages/algod_client/src/models/transaction-parameters-response.js.map +1 -1
- package/packages/algod_client/src/models/transaction-parameters-response.mjs +2 -2
- package/packages/algod_client/src/models/transaction-parameters-response.mjs.map +1 -1
- package/packages/common/src/address.js +0 -14
- package/packages/common/src/address.js.map +1 -1
- package/packages/common/src/address.mjs +1 -14
- package/packages/common/src/address.mjs.map +1 -1
- package/packages/common/src/codecs/composite/map.js +7 -4
- package/packages/common/src/codecs/composite/map.js.map +1 -1
- package/packages/common/src/codecs/composite/map.mjs +7 -4
- package/packages/common/src/codecs/composite/map.mjs.map +1 -1
- package/packages/common/src/codecs/composite/record.js +0 -1
- package/packages/common/src/codecs/composite/record.js.map +1 -1
- package/packages/common/src/codecs/primitives/address.js +0 -1
- package/packages/common/src/codecs/primitives/address.js.map +1 -1
- package/packages/common/src/codecs/primitives/bytes.js +0 -1
- package/packages/common/src/codecs/primitives/bytes.js.map +1 -1
- package/packages/common/src/codecs/primitives/fixed-bytes.js +0 -1
- package/packages/common/src/codecs/primitives/fixed-bytes.js.map +1 -1
- package/packages/common/src/codecs/wire.js +0 -1
- package/packages/common/src/codecs/wire.js.map +1 -1
- package/packages/common/src/msgpack.js +0 -1
- package/packages/common/src/msgpack.js.map +1 -1
- package/packages/indexer_client/src/apis/api-service.d.ts +1 -1
- package/packages/indexer_client/src/apis/api-service.js +12 -12
- package/packages/indexer_client/src/apis/api-service.js.map +1 -1
- package/packages/indexer_client/src/apis/api-service.mjs +12 -12
- package/packages/indexer_client/src/apis/api-service.mjs.map +1 -1
- package/packages/indexer_client/src/core/api-error.js +3 -1
- package/packages/indexer_client/src/core/api-error.js.map +1 -1
- package/packages/indexer_client/src/core/api-error.mjs +3 -1
- package/packages/indexer_client/src/core/api-error.mjs.map +1 -1
- package/packages/indexer_client/src/core/model-runtime.js +4 -4
- package/packages/indexer_client/src/core/model-runtime.js.map +1 -1
- package/packages/indexer_client/src/core/model-runtime.mjs +6 -6
- package/packages/indexer_client/src/core/model-runtime.mjs.map +1 -1
- package/packages/indexer_client/src/models/account-participation.js +4 -4
- package/packages/indexer_client/src/models/account-participation.js.map +1 -1
- package/packages/indexer_client/src/models/account-participation.mjs +4 -4
- package/packages/indexer_client/src/models/account-participation.mjs.map +1 -1
- package/packages/indexer_client/src/models/application-state-schema.d.ts +2 -2
- package/packages/indexer_client/src/models/application-state-schema.js +2 -2
- package/packages/indexer_client/src/models/application-state-schema.js.map +1 -1
- package/packages/indexer_client/src/models/application-state-schema.mjs +2 -2
- package/packages/indexer_client/src/models/application-state-schema.mjs.map +1 -1
- package/packages/indexer_client/src/models/asset-params.js +2 -1
- package/packages/indexer_client/src/models/asset-params.js.map +1 -1
- package/packages/indexer_client/src/models/asset-params.mjs +2 -1
- package/packages/indexer_client/src/models/asset-params.mjs.map +1 -1
- package/packages/indexer_client/src/models/block.js +8 -8
- package/packages/indexer_client/src/models/block.js.map +1 -1
- package/packages/indexer_client/src/models/block.mjs +8 -8
- package/packages/indexer_client/src/models/block.mjs.map +1 -1
- package/packages/indexer_client/src/models/eval-delta-key-value.d.ts +1 -1
- package/packages/indexer_client/src/models/eval-delta-key-value.js +2 -2
- package/packages/indexer_client/src/models/eval-delta-key-value.js.map +1 -1
- package/packages/indexer_client/src/models/eval-delta-key-value.mjs +2 -2
- package/packages/indexer_client/src/models/eval-delta-key-value.mjs.map +1 -1
- package/packages/indexer_client/src/models/eval-delta.d.ts +1 -1
- package/packages/indexer_client/src/models/eval-delta.js +2 -2
- package/packages/indexer_client/src/models/eval-delta.js.map +1 -1
- package/packages/indexer_client/src/models/eval-delta.mjs +2 -2
- package/packages/indexer_client/src/models/eval-delta.mjs.map +1 -1
- package/packages/indexer_client/src/models/hb-proof-fields.js +6 -6
- package/packages/indexer_client/src/models/hb-proof-fields.js.map +1 -1
- package/packages/indexer_client/src/models/hb-proof-fields.mjs +6 -6
- package/packages/indexer_client/src/models/hb-proof-fields.mjs.map +1 -1
- package/packages/indexer_client/src/models/state-proof-verifier.js +2 -2
- package/packages/indexer_client/src/models/state-proof-verifier.js.map +1 -1
- package/packages/indexer_client/src/models/state-proof-verifier.mjs +2 -2
- package/packages/indexer_client/src/models/state-proof-verifier.mjs.map +1 -1
- package/packages/indexer_client/src/models/state-schema.d.ts +2 -2
- package/packages/indexer_client/src/models/state-schema.js +2 -2
- package/packages/indexer_client/src/models/state-schema.js.map +1 -1
- package/packages/indexer_client/src/models/state-schema.mjs +2 -2
- package/packages/indexer_client/src/models/state-schema.mjs.map +1 -1
- package/packages/indexer_client/src/models/teal-key-value.d.ts +1 -1
- package/packages/indexer_client/src/models/teal-key-value.js +2 -2
- package/packages/indexer_client/src/models/teal-key-value.js.map +1 -1
- package/packages/indexer_client/src/models/teal-key-value.mjs +2 -2
- package/packages/indexer_client/src/models/teal-key-value.mjs.map +1 -1
- package/packages/indexer_client/src/models/transaction-heartbeat.js +2 -1
- package/packages/indexer_client/src/models/transaction-heartbeat.js.map +1 -1
- package/packages/indexer_client/src/models/transaction-heartbeat.mjs +2 -1
- package/packages/indexer_client/src/models/transaction-heartbeat.mjs.map +1 -1
- package/packages/indexer_client/src/models/transaction-keyreg.js +4 -4
- package/packages/indexer_client/src/models/transaction-keyreg.js.map +1 -1
- package/packages/indexer_client/src/models/transaction-keyreg.mjs +4 -4
- package/packages/indexer_client/src/models/transaction-keyreg.mjs.map +1 -1
- package/packages/indexer_client/src/models/transaction-signature-logicsig.js +2 -1
- package/packages/indexer_client/src/models/transaction-signature-logicsig.js.map +1 -1
- package/packages/indexer_client/src/models/transaction-signature-logicsig.mjs +2 -1
- package/packages/indexer_client/src/models/transaction-signature-logicsig.mjs.map +1 -1
- package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.js +3 -3
- package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.js.map +1 -1
- package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.mjs +3 -3
- package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.mjs.map +1 -1
- package/packages/indexer_client/src/models/transaction.d.ts +2 -2
- package/packages/indexer_client/src/models/transaction.js +6 -5
- package/packages/indexer_client/src/models/transaction.js.map +1 -1
- package/packages/indexer_client/src/models/transaction.mjs +6 -5
- package/packages/indexer_client/src/models/transaction.mjs.map +1 -1
- package/packages/kmd_client/src/apis/api-service.d.ts +5 -5
- package/packages/kmd_client/src/apis/api-service.js +32 -32
- package/packages/kmd_client/src/apis/api-service.js.map +1 -1
- package/packages/kmd_client/src/apis/api-service.mjs +32 -32
- package/packages/kmd_client/src/apis/api-service.mjs.map +1 -1
- package/packages/kmd_client/src/core/api-error.js +3 -1
- package/packages/kmd_client/src/core/api-error.js.map +1 -1
- package/packages/kmd_client/src/core/api-error.mjs +3 -1
- package/packages/kmd_client/src/core/api-error.mjs.map +1 -1
- package/packages/kmd_client/src/core/model-runtime.js +4 -4
- package/packages/kmd_client/src/core/model-runtime.js.map +1 -1
- package/packages/kmd_client/src/core/model-runtime.mjs +6 -6
- package/packages/kmd_client/src/core/model-runtime.mjs.map +1 -1
- package/packages/sdk/src/encoding/encoding.js +12 -2
- package/packages/sdk/src/encoding/encoding.js.map +1 -1
- package/packages/sdk/src/encoding/encoding.mjs +12 -1
- package/packages/sdk/src/encoding/encoding.mjs.map +1 -1
- package/packages/sdk/src/encoding/schema/map.js +0 -2
- package/packages/sdk/src/encoding/schema/map.js.map +1 -1
- package/packages/transact/src/logicsig.d.ts +3 -15
- package/packages/transact/src/logicsig.js +16 -36
- package/packages/transact/src/logicsig.js.map +1 -1
- package/packages/transact/src/logicsig.mjs +18 -36
- package/packages/transact/src/logicsig.mjs.map +1 -1
- package/packages/transact/src/multisig.d.ts +7 -115
- package/packages/transact/src/multisig.js +86 -136
- package/packages/transact/src/multisig.js.map +1 -1
- package/packages/transact/src/multisig.mjs +87 -117
- package/packages/transact/src/multisig.mjs.map +1 -1
- package/packages/transact/src/transactions/app-call.d.ts +10 -10
- package/packages/transact/src/transactions/app-call.js.map +1 -1
- package/packages/transact/src/transactions/app-call.mjs.map +1 -1
- package/packages/transact/src/transactions/reference-types-meta.d.ts +26 -0
- package/packages/transact/src/transactions/reference-types-meta.js +71 -0
- package/packages/transact/src/transactions/reference-types-meta.js.map +1 -0
- package/packages/transact/src/transactions/reference-types-meta.mjs +69 -0
- package/packages/transact/src/transactions/reference-types-meta.mjs.map +1 -0
- package/packages/transact/src/transactions/signed-transaction-meta.js +2 -3
- package/packages/transact/src/transactions/signed-transaction-meta.js.map +1 -1
- package/packages/transact/src/transactions/signed-transaction-meta.mjs +3 -3
- package/packages/transact/src/transactions/signed-transaction-meta.mjs.map +1 -1
- package/packages/transact/src/transactions/signed-transaction.d.ts +2 -2
- package/packages/transact/src/transactions/signed-transaction.js.map +1 -1
- package/packages/transact/src/transactions/signed-transaction.mjs.map +1 -1
- package/packages/transact/src/transactions/transaction-meta.js +29 -23
- package/packages/transact/src/transactions/transaction-meta.js.map +1 -1
- package/packages/transact/src/transactions/transaction-meta.mjs +29 -23
- package/packages/transact/src/transactions/transaction-meta.mjs.map +1 -1
- package/packages/transact/src/transactions/transaction.js +1 -0
- package/packages/transact/src/transactions/transaction.js.map +1 -1
- package/packages/transact/src/transactions/transaction.mjs +1 -0
- package/packages/transact/src/transactions/transaction.mjs.map +1 -1
- package/sdk/index.js +1 -1
- package/testing/account.js +2 -5
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +2 -5
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +3 -3
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/transact/index.d.ts +5 -4
- package/transact/index.js +4 -22
- package/transact/index.mjs +4 -3
- package/transaction/transaction.js +2 -2
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +2 -2
- package/transaction/transaction.mjs.map +1 -1
- package/transactions/app-call.d.ts +4 -3
- package/transactions/app-call.js +15 -15
- package/transactions/app-call.js.map +1 -1
- package/transactions/app-call.mjs +15 -15
- package/transactions/app-call.mjs.map +1 -1
- package/transactions/asset-config.d.ts +1 -1
- package/transactions/asset-config.js +1 -1
- package/transactions/asset-config.js.map +1 -1
- package/transactions/asset-config.mjs +1 -1
- package/transactions/asset-config.mjs.map +1 -1
- package/transactions/method-call.js +69 -77
- package/transactions/method-call.js.map +1 -1
- package/transactions/method-call.mjs +69 -77
- package/transactions/method-call.mjs.map +1 -1
- package/types/account-manager.d.ts +1 -1
- package/types/account-manager.js +3 -3
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +3 -3
- package/types/account-manager.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +97 -83
- package/types/algorand-client-transaction-creator.js +8 -0
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +8 -0
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +100 -86
- package/types/algorand-client-transaction-sender.js +8 -1
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +8 -0
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/app-client.d.ts +265 -260
- package/types/app-client.js +0 -1
- package/types/app-client.js.map +1 -1
- package/types/app-deployer.js +1 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +1 -1
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +91 -88
- package/types/app-manager.d.ts +3 -1
- package/types/app-manager.js +16 -10
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +16 -10
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.js +12 -5
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +12 -5
- package/types/app-spec.mjs.map +1 -1
- package/types/asset-manager.js +1 -1
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +1 -1
- package/types/asset-manager.mjs.map +1 -1
- package/types/composer.d.ts +9 -0
- package/types/composer.js +28 -13
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +28 -12
- package/types/composer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +1 -0
- package/types/kmd-account-manager.js +21 -10
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +22 -11
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/testing.d.ts +2 -2
- package/packages/algod_client/src/models/application-local-reference.d.ts +0 -20
- package/packages/algod_client/src/models/application-local-reference.js +0 -23
- package/packages/algod_client/src/models/application-local-reference.js.map +0 -1
- package/packages/algod_client/src/models/application-local-reference.mjs +0 -23
- package/packages/algod_client/src/models/application-local-reference.mjs.map +0 -1
- package/packages/algod_client/src/models/asset-holding-reference.d.ts +0 -20
- package/packages/algod_client/src/models/asset-holding-reference.js +0 -23
- package/packages/algod_client/src/models/asset-holding-reference.js.map +0 -1
- package/packages/algod_client/src/models/asset-holding-reference.mjs +0 -23
- package/packages/algod_client/src/models/asset-holding-reference.mjs.map +0 -1
- package/packages/algod_client/src/models/box-reference.d.ts +0 -17
- package/packages/algod_client/src/models/box-reference.js +0 -23
- package/packages/algod_client/src/models/box-reference.js.map +0 -1
- package/packages/algod_client/src/models/box-reference.mjs +0 -23
- package/packages/algod_client/src/models/box-reference.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -52,17 +52,33 @@ This is an open source project managed by the Algorand Foundation. See the [Algo
|
|
|
52
52
|
|
|
53
53
|
To successfully run the tests in this repository you need to be running LocalNet via [AlgoKit](https://github.com/algorandfoundation/algokit-cli) and also have package dependencies and `.env.template` copied to `.env` (both of which `algokit bootstrap all` can do for you):
|
|
54
54
|
|
|
55
|
-
```
|
|
55
|
+
```bash
|
|
56
56
|
algokit bootstrap all
|
|
57
57
|
algokit localnet start
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
To run tests you can use VS Code, or:
|
|
61
61
|
|
|
62
|
-
```
|
|
62
|
+
```bash
|
|
63
63
|
npm run test
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### Prerequisites
|
|
67
|
+
|
|
68
|
+
- [Rust](https://rust-lang.org/tools/install/) - Required for building native dependencies
|
|
69
|
+
- [Bun](https://bun.sh/docs/installation) - JavaScript runtime and package manager
|
|
70
|
+
- [Polytest](https://github.com/algorandfoundation/algokit-polytest) - Install via Cargo:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
cargo install polytest
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
To update to a specific version if required:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
cargo install polytest --version {X}
|
|
80
|
+
```
|
|
81
|
+
|
|
66
82
|
### Mock Server for Client Tests
|
|
67
83
|
|
|
68
84
|
The `algod_client`, `indexer_client`, and `kmd_client` packages use a mock server for deterministic API testing against pre-recorded HAR files. The mock server is managed externally (not by the test framework).
|
|
@@ -71,7 +87,13 @@ The `algod_client`, `indexer_client`, and `kmd_client` packages use a mock serve
|
|
|
71
87
|
|
|
72
88
|
**Local development:**
|
|
73
89
|
|
|
74
|
-
1.
|
|
90
|
+
1. Init algokit-polytest on first run
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm run polytest:init
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
2. Start the mock servers:
|
|
75
97
|
|
|
76
98
|
```bash
|
|
77
99
|
npm run polytest:start-mock-servers
|
|
@@ -79,7 +101,7 @@ npm run polytest:start-mock-servers
|
|
|
79
101
|
|
|
80
102
|
This starts algod (port 8000), indexer (port 8002), and kmd (port 8001) in the background.
|
|
81
103
|
|
|
82
|
-
|
|
104
|
+
3. Set environment variables and run tests.
|
|
83
105
|
|
|
84
106
|
| Environment Variable | Description | Default Port |
|
|
85
107
|
| -------------------- | ----------------------- | ------------ |
|
|
@@ -94,7 +116,7 @@ Environment variables can also be set via `.env` file in project root (copy from
|
|
|
94
116
|
npm run test
|
|
95
117
|
```
|
|
96
118
|
|
|
97
|
-
|
|
119
|
+
4. Stop servers when done:
|
|
98
120
|
|
|
99
121
|
```bash
|
|
100
122
|
npm run polytest:stop-mock-servers
|
|
@@ -5,21 +5,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (all) => {
|
|
8
|
+
var __export = (all, symbols) => {
|
|
9
9
|
let target = {};
|
|
10
|
-
for (var name in all)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
for (var name in all) {
|
|
11
|
+
__defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (symbols) {
|
|
17
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
}
|
|
14
19
|
return target;
|
|
15
20
|
};
|
|
16
21
|
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
return to;
|
|
25
34
|
};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
//#region rolldown:runtime
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (all) => {
|
|
3
|
+
var __export = (all, symbols) => {
|
|
4
4
|
let target = {};
|
|
5
|
-
for (var name in all)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
9
14
|
return target;
|
|
10
15
|
};
|
|
11
16
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic } from "../packages/algo25/src/index.js";
|
|
2
|
+
export { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic };
|
package/algo25/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const require_index = require('../packages/algo25/src/index.js');
|
|
2
|
+
|
|
3
|
+
exports.FAIL_TO_DECODE_MNEMONIC_ERROR_MSG = require_index.FAIL_TO_DECODE_MNEMONIC_ERROR_MSG;
|
|
4
|
+
exports.NOT_IN_WORDS_LIST_ERROR_MSG = require_index.NOT_IN_WORDS_LIST_ERROR_MSG;
|
|
5
|
+
exports.masterDerivationKeyToMnemonic = require_index.masterDerivationKeyToMnemonic;
|
|
6
|
+
exports.mnemonicFromSeed = require_index.mnemonicFromSeed;
|
|
7
|
+
exports.mnemonicToMasterDerivationKey = require_index.mnemonicToMasterDerivationKey;
|
|
8
|
+
exports.secretKeyToMnemonic = require_index.secretKeyToMnemonic;
|
|
9
|
+
exports.seedFromMnemonic = require_index.seedFromMnemonic;
|
package/algo25/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic } from "../packages/algo25/src/index.mjs";
|
|
2
|
+
|
|
3
|
+
export { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic };
|
package/algod-client/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ApiError } from "../packages/algod_client/src/core/api-error.js";
|
|
|
5
5
|
import { decodeJson, decodeMsgpack, encodeJson, encodeMsgpack } from "../packages/algod_client/src/core/model-runtime.js";
|
|
6
6
|
import { GenesisAllocation } from "../packages/algod_client/src/models/genesis-allocation.js";
|
|
7
7
|
import { Genesis } from "../packages/algod_client/src/models/genesis.js";
|
|
8
|
-
import { ApplyData, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHeader, BlockStateProofTrackingData, ParticipationUpdates, SignedTxnInBlock, SignedTxnWithAD } from "../packages/algod_client/src/models/block.js";
|
|
8
|
+
import { ApplyData, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHeader, BlockStateProofTrackingData, ParticipationUpdates, RewardState, SignedTxnInBlock, SignedTxnWithAD, TxnCommitments, UpgradeState, UpgradeVote } from "../packages/algod_client/src/models/block.js";
|
|
9
9
|
import { LedgerStateDelta } from "../packages/algod_client/src/models/ledger-state-delta.js";
|
|
10
10
|
import { LedgerStateDeltaForTransactionGroup } from "../packages/algod_client/src/models/ledger-state-delta-for-transaction-group.js";
|
|
11
11
|
import { AccountParticipation } from "../packages/algod_client/src/models/account-participation.js";
|
|
@@ -20,8 +20,6 @@ import { AssetParams } from "../packages/algod_client/src/models/asset-params.js
|
|
|
20
20
|
import { Asset } from "../packages/algod_client/src/models/asset.js";
|
|
21
21
|
import { AssetHolding } from "../packages/algod_client/src/models/asset-holding.js";
|
|
22
22
|
import { Account } from "../packages/algod_client/src/models/account.js";
|
|
23
|
-
import { AssetHoldingReference } from "../packages/algod_client/src/models/asset-holding-reference.js";
|
|
24
|
-
import { ApplicationLocalReference } from "../packages/algod_client/src/models/application-local-reference.js";
|
|
25
23
|
import { AvmValue } from "../packages/algod_client/src/models/avm-value.js";
|
|
26
24
|
import { AvmKeyValue } from "../packages/algod_client/src/models/avm-key-value.js";
|
|
27
25
|
import { EvalDelta } from "../packages/algod_client/src/models/eval-delta.js";
|
|
@@ -33,7 +31,6 @@ import { SimulateTraceConfig } from "../packages/algod_client/src/models/simulat
|
|
|
33
31
|
import { SimulateRequest } from "../packages/algod_client/src/models/simulate-request.js";
|
|
34
32
|
import { Box } from "../packages/algod_client/src/models/box.js";
|
|
35
33
|
import { BoxDescriptor } from "../packages/algod_client/src/models/box-descriptor.js";
|
|
36
|
-
import { BoxReference } from "../packages/algod_client/src/models/box-reference.js";
|
|
37
34
|
import { BuildVersion } from "../packages/algod_client/src/models/build-version.js";
|
|
38
35
|
import { Version } from "../packages/algod_client/src/models/version.js";
|
|
39
36
|
import { PendingTransactionResponse } from "../packages/algod_client/src/models/pending-transaction-response.js";
|
|
@@ -73,4 +70,4 @@ import { DisassembleResponse } from "../packages/algod_client/src/models/disasse
|
|
|
73
70
|
import { SuggestedParams, SuggestedParamsMeta } from "../packages/algod_client/src/models/suggested-params.js";
|
|
74
71
|
import { AlgodApi } from "../packages/algod_client/src/apis/api-service.js";
|
|
75
72
|
import { AlgodClient } from "../packages/algod_client/src/client.js";
|
|
76
|
-
export { Account, AccountApplicationResponse, AccountAssetResponse, AccountParticipation, AccountStateDelta, AlgodApi, AlgodClient, ApiError, ApiRequestOptions, Application, ApplicationInitialStates, ApplicationKvStorage,
|
|
73
|
+
export { Account, AccountApplicationResponse, AccountAssetResponse, AccountParticipation, AccountStateDelta, AlgodApi, AlgodClient, ApiError, ApiRequestOptions, Application, ApplicationInitialStates, ApplicationKvStorage, ApplicationLocalState, ApplicationParams, ApplicationStateOperation, ApplicationStateSchema, ApplyData, Asset, AssetHolding, AssetParams, AvmKeyValue, AvmValue, BaseHttpRequest, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHashResponse, BlockHeader, BlockResponse, BlockStateProofTrackingData, BlockTxidsResponse, Box, BoxDescriptor, BoxesResponse, BuildVersion, ClientConfig, CompileResponse, DisassembleResponse, EvalDelta, EvalDeltaKeyValue, FetchHttpRequest, Genesis, GenesisAllocation, GetBlockTimeStampOffsetResponse, GetSyncRoundResponse, LedgerStateDelta, LedgerStateDeltaForTransactionGroup, LightBlockHeaderProof, NodeStatusResponse, ParticipationUpdates, PendingTransactionResponse, PendingTransactionsResponse, PostTransactionsResponse, RewardState, ScratchChange, SignedTxnInBlock, SignedTxnWithAD, SimulateInitialStates, SimulateRequest, SimulateRequestTransactionGroup, SimulateResponse, SimulateTraceConfig, SimulateTransactionGroupResult, SimulateTransactionResult, SimulateUnnamedResourcesAccessed, SimulationEvalOverrides, SimulationOpcodeTraceUnit, SimulationTransactionExecTrace, SourceMap, StateDelta, StateProof, StateProofMessage, SuggestedParams, SuggestedParamsMeta, SupplyResponse, TealKeyValue, TealKeyValueStore, TealValue, TransactionGroupLedgerStateDeltasForRoundResponse, TransactionParametersResponse, TransactionProof, TxnCommitments, UpgradeState, UpgradeVote, Version, decodeJson, decodeMsgpack, encodeJson, encodeMsgpack, inputValueAsString };
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"**"
|
|
7
7
|
],
|
|
8
8
|
"name": "@algorandfoundation/algokit-utils",
|
|
9
|
-
"version": "10.0.0-alpha.
|
|
9
|
+
"version": "10.0.0-alpha.11",
|
|
10
10
|
"private": false,
|
|
11
11
|
"description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
|
|
12
12
|
"author": "Algorand Foundation",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-method.js","names":["sha512","parseTupleContent","ABIType","convertedDefaultValue: ABIDefaultValue | undefined","ABIStructType","ABIUintType","ABIAddressType"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB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gB,eAAe,SAAkB,OAA6B;AAC5E,SAAQ,SAAR;EACE,KAAK,YACH,QAAOA,yBAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;EAC7C,KAAK;AACH,OAAI,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK,OAAO,QAAQ;AACjE,OAAI,OAAO,UAAU,YAAY,EAAE,iBAAiB,YAClD,OAAM,IAAI,MAAM,8CAA8C,QAAQ;AACxE,UAAO;EACT,KAAK,YACH,QAAOA,yBAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,UAAU,MAAgC;AACxD,QAAO,OAAO,SAAS,aAAa,SAAS,eAAe,SAAS,cAAc,SAAS;;AAG9F,SAAgB,mBAAmB,MAA4C,OAA6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAIG,6BAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAIC,iCAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
|
|
1
|
+
{"version":3,"file":"abi-method.js","names":["sha512","parseTupleContent","ABIType","convertedDefaultValue: ABIDefaultValue | undefined","ABIStructType","ABIUintType","ABIAddressType"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError?: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB,MAAM,OAAO,KAAK,KACf,KAAK,QAAQ;AACZ,OAAI,qBAAqB,IAAI,KAAK,IAAI,mBAAmB,IAAI,KAAK,CAAE,QAAO,IAAI;AAC/E,UAAO,IAAI,KAAK;IAChB,CACD,KAAK,IAAI;AAEZ,SAAO,GAAG,KAAK,KAAK,GAAG,KAAK,GADZ,KAAK,QAAQ,SAAS,SAAS,SAAS,KAAK,QAAQ,KAAK;;;;;;CAQ5E,cAA0B;EACxB,MAAM,OAAOA,kBAAO,WAAW,MAAM,KAAK,cAAc,CAAC;AACzD,SAAO,IAAI,WAAW,KAAK,MAAM,GAAG,EAAE,CAAC;;;;;;;;CASzC,OAAO,cAAc,WAA8B;EACjD,MAAM,YAAY,UAAU,QAAQ,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AA6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAIG,6BAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAIC,iCAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-method.mjs","names":["convertedDefaultValue: ABIDefaultValue | undefined"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;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AAO,GAAG,OAAO,KAAK,GAAG,KAAK,GADd,OAAO,QAAQ;;AAIjC,SAAgB,eAAe,SAAkB,OAA6B;AAC5E,SAAQ,SAAR;EACE,KAAK,YACH,QAAO,OAAO,KAAK,MAAM,CAAC,SAAS,QAAQ;EAC7C,KAAK,WACH,QAAO;EACT,KAAK,YACH,QAAO,QAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,eAAe,SAAkB,OAA6B;AAC5E,SAAQ,SAAR;EACE,KAAK,YACH,QAAO,QAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;EAC7C,KAAK;AACH,OAAI,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK,OAAO,QAAQ;AACjE,OAAI,OAAO,UAAU,YAAY,EAAE,iBAAiB,YAClD,OAAM,IAAI,MAAM,8CAA8C,QAAQ;AACxE,UAAO;EACT,KAAK,YACH,QAAO,QAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,UAAU,MAAgC;AACxD,QAAO,OAAO,SAAS,aAAa,SAAS,eAAe,SAAS,cAAc,SAAS;;AAG9F,SAAgB,mBAAmB,MAA4C,OAA6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAI,YAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAI,gBAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
|
|
1
|
+
{"version":3,"file":"abi-method.mjs","names":["convertedDefaultValue: ABIDefaultValue | undefined"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError?: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB,MAAM,OAAO,KAAK,KACf,KAAK,QAAQ;AACZ,OAAI,qBAAqB,IAAI,KAAK,IAAI,mBAAmB,IAAI,KAAK,CAAE,QAAO,IAAI;AAC/E,UAAO,IAAI,KAAK;IAChB,CACD,KAAK,IAAI;AAEZ,SAAO,GAAG,KAAK,KAAK,GAAG,KAAK,GADZ,KAAK,QAAQ,SAAS,SAAS,SAAS,KAAK,Q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;EACT,KAAK,YACH,QAAO,QAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,UAAU,MAAgC;AACxD,QAAO,OAAO,SAAS,aAAa,SAAS,eAAe,SAAS,cAAc,SAAS;;AAG9F,SAAgB,mBAAmB,MAA4C,OAA6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAI,YAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAI,gBAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
|
|
@@ -114,7 +114,7 @@ declare class ABIAddressType extends ABIType {
|
|
|
114
114
|
isDynamic(): boolean;
|
|
115
115
|
byteLen(): number;
|
|
116
116
|
encode(value: ABIValue): Uint8Array;
|
|
117
|
-
decode(bytes: Uint8Array):
|
|
117
|
+
decode(bytes: Uint8Array): string;
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* A boolean ABI type.
|
|
@@ -167,10 +167,11 @@ var ABIAddressType = class ABIAddressType extends ABIType {
|
|
|
167
167
|
encode(value) {
|
|
168
168
|
if (typeof value === "string") return require_address.Address.fromString(value).publicKey;
|
|
169
169
|
if (value instanceof require_address.Address) return value.publicKey;
|
|
170
|
+
if (value instanceof Uint8Array && value.length === 32) return value;
|
|
170
171
|
throw new Error(`Cannot encode value as address: ${value}`);
|
|
171
172
|
}
|
|
172
173
|
decode(bytes) {
|
|
173
|
-
return new require_address.Address(bytes);
|
|
174
|
+
return new require_address.Address(bytes).toString();
|
|
174
175
|
}
|
|
175
176
|
};
|
|
176
177
|
/**
|
|
@@ -526,8 +527,9 @@ var ABIStructType = class ABIStructType extends ABIType {
|
|
|
526
527
|
})));
|
|
527
528
|
}
|
|
528
529
|
encode(value) {
|
|
529
|
-
if (
|
|
530
|
+
if (value instanceof Uint8Array || value instanceof require_address.Address || typeof value !== "object") throw new Error(`Cannot encode value as ${this.name}: ${value}`);
|
|
530
531
|
const tupleType = this.toABITupleType();
|
|
532
|
+
if (Array.isArray(value)) return tupleType.encode(value);
|
|
531
533
|
const tupleValue = this.getTupleValueFromStructValue(value);
|
|
532
534
|
return tupleType.encode(tupleValue);
|
|
533
535
|
}
|