@airgap/icp 0.13.9-beta.2
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.md +7 -0
- package/airgap-coinlib-icp.min.js +91766 -0
- package/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +71 -0
- package/readme.md +121 -0
- package/v1/block-explorer/ICPBlockExplorer.d.ts +9 -0
- package/v1/block-explorer/ICPBlockExplorer.js +74 -0
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -0
- package/v1/index.d.ts +12 -0
- package/v1/index.js +11 -0
- package/v1/index.js.map +1 -0
- package/v1/module/ICPModule.d.ts +15 -0
- package/v1/module/ICPModule.js +107 -0
- package/v1/module/ICPModule.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +26 -0
- package/v1/protocol/ICPImplementation.js +334 -0
- package/v1/protocol/ICPImplementation.js.map +1 -0
- package/v1/protocol/ICPProtocol.d.ts +38 -0
- package/v1/protocol/ICPProtocol.js +414 -0
- package/v1/protocol/ICPProtocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +32 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +19 -0
- package/v1/serializer/v3/serializer-companion.d.ts +14 -0
- package/v1/serializer/v3/serializer-companion.js +174 -0
- package/v1/serializer/v3/serializer-companion.js.map +1 -0
- package/v1/serializer/v3/validators/transaction-validator.d.ts +10 -0
- package/v1/serializer/v3/validators/transaction-validator.js +100 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/serializer/v3/validators/validators.d.ts +5 -0
- package/v1/serializer/v3/validators/validators.js +106 -0
- package/v1/serializer/v3/validators/validators.js.map +1 -0
- package/v1/types/governance.d.ts +580 -0
- package/v1/types/governance.js +796 -0
- package/v1/types/governance.js.map +1 -0
- package/v1/types/ledger.d.ts +143 -0
- package/v1/types/ledger.js +146 -0
- package/v1/types/ledger.js.map +1 -0
- package/v1/types/management_idl.d.ts +7 -0
- package/v1/types/management_idl.js +72 -0
- package/v1/types/management_idl.js.map +1 -0
- package/v1/types/protocol.d.ts +8 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/transaction.d.ts +11 -0
- package/v1/types/transaction.js +3 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/account.d.ts +24 -0
- package/v1/utils/account.js +112 -0
- package/v1/utils/account.js.map +1 -0
- package/v1/utils/actor.d.ts +246 -0
- package/v1/utils/actor.js +458 -0
- package/v1/utils/actor.js.map +1 -0
- package/v1/utils/agent.d.ts +156 -0
- package/v1/utils/agent.js +16 -0
- package/v1/utils/agent.js.map +1 -0
- package/v1/utils/auth.d.ts +110 -0
- package/v1/utils/auth.js +261 -0
- package/v1/utils/auth.js.map +1 -0
- package/v1/utils/bls.d.ts +38 -0
- package/v1/utils/bls.js +204 -0
- package/v1/utils/bls.js.map +1 -0
- package/v1/utils/buffer.d.ts +70 -0
- package/v1/utils/buffer.js +216 -0
- package/v1/utils/buffer.js.map +1 -0
- package/v1/utils/cbor.d.ts +9 -0
- package/v1/utils/cbor.js +178 -0
- package/v1/utils/cbor.js.map +1 -0
- package/v1/utils/certificate.d.ts +74 -0
- package/v1/utils/certificate.js +396 -0
- package/v1/utils/certificate.js.map +1 -0
- package/v1/utils/convert.d.ts +8 -0
- package/v1/utils/convert.js +80 -0
- package/v1/utils/convert.js.map +1 -0
- package/v1/utils/crypto.d.ts +0 -0
- package/v1/utils/crypto.js +104 -0
- package/v1/utils/crypto.js.map +1 -0
- package/v1/utils/der.d.ts +35 -0
- package/v1/utils/der.js +176 -0
- package/v1/utils/der.js.map +1 -0
- package/v1/utils/errors.d.ts +7 -0
- package/v1/utils/errors.js +38 -0
- package/v1/utils/errors.js.map +1 -0
- package/v1/utils/hdkey.d.ts +13 -0
- package/v1/utils/hdkey.js +242 -0
- package/v1/utils/hdkey.js.map +1 -0
- package/v1/utils/http.d.ts +284 -0
- package/v1/utils/http.js +614 -0
- package/v1/utils/http.js.map +1 -0
- package/v1/utils/idl.d.ts +515 -0
- package/v1/utils/idl.js +2103 -0
- package/v1/utils/idl.js.map +1 -0
- package/v1/utils/leb128.d.ts +63 -0
- package/v1/utils/leb128.js +224 -0
- package/v1/utils/leb128.js.map +1 -0
- package/v1/utils/polling.d.ts +59 -0
- package/v1/utils/polling.js +325 -0
- package/v1/utils/polling.js.map +1 -0
- package/v1/utils/principal.d.ts +58 -0
- package/v1/utils/principal.js +543 -0
- package/v1/utils/principal.js.map +1 -0
- package/v1/utils/secp256k1.d.ts +79 -0
- package/v1/utils/secp256k1.js +253 -0
- package/v1/utils/secp256k1.js.map +1 -0
- package/v1/utils/transaction.d.ts +3 -0
- package/v1/utils/transaction.js +56 -0
- package/v1/utils/transaction.js.map +1 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v1';
|
package/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./v1"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAoB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@airgap/icp",
|
|
3
|
+
"version": "0.13.9-beta.2",
|
|
4
|
+
"description": "The @airgap/icp is an ICP implementation of the ICoinProtocol interface from @airgap/coinlib-core.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"airgap",
|
|
7
|
+
"blockchain",
|
|
8
|
+
"crypto",
|
|
9
|
+
"icp"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://www.airgap.it",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/airgap-it/airgap-coin-lib"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rm -rf ./dist && tsc && node scripts/copy-files-after-build.js",
|
|
22
|
+
"build-scripts": "tsc scripts/*.ts",
|
|
23
|
+
"lint": "tslint -c ./tslint.json --project ./tsconfig.json --format stylish --fix",
|
|
24
|
+
"lint:prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
25
|
+
"lint-ci": "tslint -t json -o ../../lint-reports/icp.json --project . || true",
|
|
26
|
+
"lint-ci:prettier": "prettier \"src/**/*.ts\" \"test/**/*.ts\" --list-different",
|
|
27
|
+
"test": "",
|
|
28
|
+
"test-ci": "nyc --reporter=lcov npm test",
|
|
29
|
+
"test-legacy": "",
|
|
30
|
+
"browserify": "browserify ./dist/index.js -p realpathify -s airgapCoinLibICP > ./dist/airgap-coinlib-icp.min.js"
|
|
31
|
+
},
|
|
32
|
+
"author": "Papers GmbH <contact@papers.ch> (https://papers.ch)",
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@airgap/coinlib-core": "^0.13.9-beta.2",
|
|
35
|
+
"@airgap/module-kit": "^0.13.9-beta.2",
|
|
36
|
+
"@airgap/serializer": "^0.13.9-beta.2",
|
|
37
|
+
"@stablelib/ed25519": "1.0.3"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@dfinity/candid": "^0.15.1",
|
|
41
|
+
"@dfinity/identity-secp256k1": "^0.15.1",
|
|
42
|
+
"@dfinity/nns": "^0.10.0",
|
|
43
|
+
"@dfinity/principal": "^0.15.1",
|
|
44
|
+
"@dfinity/utils": "^0.0.6",
|
|
45
|
+
"isomorphic-fetch": "^3.0.0",
|
|
46
|
+
"js-sha256": "^0.9.0",
|
|
47
|
+
"secp256k1": "^5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"nyc": {
|
|
50
|
+
"include": [
|
|
51
|
+
"src/**/*.ts"
|
|
52
|
+
],
|
|
53
|
+
"exclude": [
|
|
54
|
+
"test/**/*.spec.ts"
|
|
55
|
+
],
|
|
56
|
+
"extension": [
|
|
57
|
+
".ts"
|
|
58
|
+
],
|
|
59
|
+
"require": [
|
|
60
|
+
"ts-node/register"
|
|
61
|
+
],
|
|
62
|
+
"reporter": [
|
|
63
|
+
"text",
|
|
64
|
+
"text-summary"
|
|
65
|
+
],
|
|
66
|
+
"report-dir": "../../coverage/icp",
|
|
67
|
+
"sourceMap": true,
|
|
68
|
+
"instrument": true
|
|
69
|
+
},
|
|
70
|
+
"gitHead": "8e8feb6788204501b7173aa825f5456c2a5f185b"
|
|
71
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# AirGap Coin Library
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/airgap-coin-lib)
|
|
4
|
+
[](https://airgap-it.github.io/airgap-coin-lib/)
|
|
5
|
+
[](https://travis-ci.org/airgap-it/airgap-coin-lib/)
|
|
6
|
+
[](https://codecov.io/gh/airgap-it/airgap-coin-lib/)
|
|
7
|
+
|
|
8
|
+
The `airgap-coin-lib` is a protocol-agnostic library that allows easy handling of the most important tasks relating cryptocurrencies and blockchains.
|
|
9
|
+
|
|
10
|
+
It implements operations such as preparing, signing and broadcasting transactions for a range of protocols.
|
|
11
|
+
|
|
12
|
+
The library consists of a shared interface for all implemented protocols. This is especially useful in the context of AirGap because methods are designed to support offline key management and signing. The following core operations are specified:
|
|
13
|
+
|
|
14
|
+
- `prepareTransaction` - This is done on AirGap Wallet (online) side. Either a public key or extended public key is used and will fetch the required information from the network.
|
|
15
|
+
- `signTransaction` - This is done in AirGap Vault (offline) side. The output of "prepareTransaction" is the input for this method (hence the output of "prepareTransaction" is transferred via URL scheme (same-device) or QR code (2-device-setup)).
|
|
16
|
+
- `broadcastTransaction` - This is done in AirGap Wallet (online) side. The output of "signTransaction" is the input for this method (hence the output of "signTransaction" is transferred via URL scheme (same-device) or QR code (2-device-setup)).
|
|
17
|
+
|
|
18
|
+
## Supported Protocols
|
|
19
|
+
|
|
20
|
+
The modular design used in this library allows you to simply add new protocols with special logic. Adding a new Bitcoin-like protocol basically means:
|
|
21
|
+
|
|
22
|
+
1. select the correct network parameters (see `src/networks.ts`)
|
|
23
|
+
2. set the Insight API URL to communicate with the blockchain
|
|
24
|
+
|
|
25
|
+
Adding a new Ethereum-like protocol means:
|
|
26
|
+
|
|
27
|
+
1. set the correct chain id
|
|
28
|
+
2. set the JSON RPC URL
|
|
29
|
+
|
|
30
|
+
Currently supported are:
|
|
31
|
+
|
|
32
|
+
- Bitcoin
|
|
33
|
+
- Ethereum
|
|
34
|
+
- Generic ERC20 Tokens
|
|
35
|
+
- Aeternity
|
|
36
|
+
- Tezos
|
|
37
|
+
- FA1.2 tokens
|
|
38
|
+
- tzBTC
|
|
39
|
+
- USDtz
|
|
40
|
+
- FA2 tokens
|
|
41
|
+
- Groestlcoin
|
|
42
|
+
- Cosmos
|
|
43
|
+
- Polkadot
|
|
44
|
+
- Kusama
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
### Protocols
|
|
49
|
+
|
|
50
|
+
The way the interface was designed is to allow stateless calls. This means the class stores very little state itself.
|
|
51
|
+
All required input comes from the method params (public key, extended public key, etc...)
|
|
52
|
+
|
|
53
|
+
Currently we support for Bitcoin-like (UTXO) protocols:
|
|
54
|
+
|
|
55
|
+
- Single Address Wallets (deprecated)
|
|
56
|
+
- HD Wallets
|
|
57
|
+
|
|
58
|
+
Currently we support for Ethereum-like (Account-based) protocols:
|
|
59
|
+
|
|
60
|
+
- Single Address Wallets
|
|
61
|
+
|
|
62
|
+
### Delegation
|
|
63
|
+
|
|
64
|
+
There is a different interface that can be implemented if the protocol supports delegation. The delegation flow usually requires some changes in the user interface of the AirGap Wallet as well.
|
|
65
|
+
|
|
66
|
+
### Inter App Communication
|
|
67
|
+
|
|
68
|
+
A serializer is included that encodes JSON structures with RLP and base58check. Those strings can then be sent to the other app, either through QR codes or a URL. The serializer can only serialize messages in predefined formats, so new message types have to be added when new protocols are added.
|
|
69
|
+
|
|
70
|
+
### Tezos FA1.2 and FA2 tokens
|
|
71
|
+
|
|
72
|
+
It is possible to interact (fetch balances, create transfers, etc.) with an FA1.2 and FA2 smart contracts using the `TezosFA12Protocol` and `TezosFA2Protocol` classes. An example on how to use them can be found in `examples/custom/protocols/tezos/fa2-smart-contract.ts`.
|
|
73
|
+
|
|
74
|
+
## Synchronising information between wallet and vault
|
|
75
|
+
|
|
76
|
+
Such that the system works we need to be able to synchronise wallets. A wallet can be:
|
|
77
|
+
|
|
78
|
+
- Single Address Wallet
|
|
79
|
+
- HD Wallet
|
|
80
|
+
|
|
81
|
+
For the single address wallet we only need to share the public key. For HD Wallet we need to share the extended public key.
|
|
82
|
+
|
|
83
|
+
## Getting started
|
|
84
|
+
|
|
85
|
+
### Requirements
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
npm >= 6
|
|
89
|
+
NodeJS >= 12
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Build dependencies get installed using `npm install`.
|
|
93
|
+
|
|
94
|
+
### Clone and Run
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
$ git clone https://github.com/airgap-it/airgap-coin-lib.git
|
|
98
|
+
$ cd airgap-coin-lib
|
|
99
|
+
$ npm install
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
To run the tests, you will have to install the test dependencies
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
$ npm run install-test-dependencies
|
|
106
|
+
$ npm test
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
To remove the test dependencies and clean up the `package.json` and `package-lock.json`, execute this command
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
$ npm run install-build-dependencies
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Contributing
|
|
116
|
+
|
|
117
|
+
We welcome contributions from the community. Simple readme updates or bugfixes can be addressed with a PR directly.
|
|
118
|
+
|
|
119
|
+
For larger changes like new protocols, new features or larger refactorings, please contact us first by opening an issue. This project is under constant development and until version `1.x.x` has been reached, there will be frequent breaking changes. So make sure to take a look at the `develop` branch.
|
|
120
|
+
|
|
121
|
+
Regarding new protocols / currencies, we cannot guarantee that they will be merged, but we're more than happy to discuss the details of a specific integration in a github issue.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AirGapBlockExplorer, BlockExplorerMetadata } from '@airgap/module-kit';
|
|
2
|
+
export declare class ICPBlockExplorer implements AirGapBlockExplorer {
|
|
3
|
+
readonly url: string;
|
|
4
|
+
constructor(url?: string);
|
|
5
|
+
private readonly metadata;
|
|
6
|
+
getMetadata(): Promise<BlockExplorerMetadata>;
|
|
7
|
+
createAddressUrl(address: string): Promise<string>;
|
|
8
|
+
createTransactionUrl(transactionId: string): Promise<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ICPBlockExplorer = void 0;
|
|
40
|
+
var BLOCK_EXPLORER_URL = 'https://dashboard.internetcomputer.org/';
|
|
41
|
+
var ICPBlockExplorer = /** @class */ (function () {
|
|
42
|
+
function ICPBlockExplorer(url) {
|
|
43
|
+
if (url === void 0) { url = BLOCK_EXPLORER_URL; }
|
|
44
|
+
this.url = url;
|
|
45
|
+
this.metadata = {
|
|
46
|
+
name: 'ICP Explorer',
|
|
47
|
+
url: this.url
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
ICPBlockExplorer.prototype.getMetadata = function () {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
return [2 /*return*/, this.metadata];
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
ICPBlockExplorer.prototype.createAddressUrl = function (address) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
return [2 /*return*/, "".concat(this.url, "/account/").concat(address)];
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
ICPBlockExplorer.prototype.createTransactionUrl = function (transactionId) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
return [2 /*return*/, "".concat(this.url, "/transaction/").concat(transactionId)];
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
return ICPBlockExplorer;
|
|
72
|
+
}());
|
|
73
|
+
exports.ICPBlockExplorer = ICPBlockExplorer;
|
|
74
|
+
//# sourceMappingURL=ICPBlockExplorer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICPBlockExplorer.js","sourceRoot":"","sources":["../../../src/v1/block-explorer/ICPBlockExplorer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,kBAAkB,GAAW,yCAAyC,CAAA;AAE5E;IACE,0BAAmC,GAAgC;QAAhC,oBAAA,EAAA,wBAAgC;QAAhC,QAAG,GAAH,GAAG,CAA6B;QAElD,aAAQ,GAA0B;YACjD,IAAI,EAAE,cAAc;YACpB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAA;IALqE,CAAC;IAO1D,sCAAW,GAAxB;;;gBACE,sBAAO,IAAI,CAAC,QAAQ,EAAA;;;KACrB;IAEY,2CAAgB,GAA7B,UAA8B,OAAe;;;gBAC3C,sBAAO,UAAG,IAAI,CAAC,GAAG,sBAAY,OAAO,CAAE,EAAA;;;KACxC;IACY,+CAAoB,GAAjC,UAAkC,aAAqB;;;gBACrD,sBAAO,UAAG,IAAI,CAAC,GAAG,0BAAgB,aAAa,CAAE,EAAA;;;KAClD;IACH,uBAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,4CAAgB"}
|
package/v1/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICPBlockExplorer } from './block-explorer/ICPBlockExplorer';
|
|
2
|
+
import { ICPModule } from './module/ICPModule';
|
|
3
|
+
import { ICPProtocol, createICPProtocol, createICPProtocolOptions } from './protocol/ICPProtocol';
|
|
4
|
+
import { ICPTransactionSignRequest } from './serializer/v3/schemas/definitions/transaction-sign-request-icp';
|
|
5
|
+
import { ICPTransactionSignResponse } from './serializer/v3/schemas/definitions/transaction-sign-response-icp';
|
|
6
|
+
import { ICPProtocolNetwork, ICPProtocolOptions, ICPUnits } from './types/protocol';
|
|
7
|
+
import { ICPSignedTransaction, ICPUnsignedTransaction } from './types/transaction';
|
|
8
|
+
export { ICPModule };
|
|
9
|
+
export { ICPProtocol, createICPProtocol, createICPProtocolOptions };
|
|
10
|
+
export { ICPBlockExplorer };
|
|
11
|
+
export { ICPUnits, ICPProtocolOptions, ICPProtocolNetwork, ICPUnsignedTransaction, ICPSignedTransaction };
|
|
12
|
+
export { ICPTransactionSignRequest, ICPTransactionSignResponse };
|
package/v1/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ICPBlockExplorer = exports.createICPProtocolOptions = exports.createICPProtocol = exports.ICPModule = void 0;
|
|
4
|
+
var ICPBlockExplorer_1 = require("./block-explorer/ICPBlockExplorer");
|
|
5
|
+
Object.defineProperty(exports, "ICPBlockExplorer", { enumerable: true, get: function () { return ICPBlockExplorer_1.ICPBlockExplorer; } });
|
|
6
|
+
var ICPModule_1 = require("./module/ICPModule");
|
|
7
|
+
Object.defineProperty(exports, "ICPModule", { enumerable: true, get: function () { return ICPModule_1.ICPModule; } });
|
|
8
|
+
var ICPProtocol_1 = require("./protocol/ICPProtocol");
|
|
9
|
+
Object.defineProperty(exports, "createICPProtocol", { enumerable: true, get: function () { return ICPProtocol_1.createICPProtocol; } });
|
|
10
|
+
Object.defineProperty(exports, "createICPProtocolOptions", { enumerable: true, get: function () { return ICPProtocol_1.createICPProtocolOptions; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/v1/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,sEAAoE;AAkB3D,iGAlBA,mCAAgB,OAkBA;AAjBzB,gDAA8C;AASrC,0FATA,qBAAS,OASA;AARlB,sDAAiG;AAY3E,kGAZA,+BAAiB,OAYA;AAAE,yGAZA,sCAAwB,OAYA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MainProtocolSymbols } from '@airgap/coinlib-core';
|
|
2
|
+
import { AirGapBlockExplorer, AirGapModule, AirGapOfflineProtocol, AirGapOnlineProtocol, AirGapV3SerializerCompanion, ProtocolConfiguration } from '@airgap/module-kit';
|
|
3
|
+
declare type SupportedProtocols = MainProtocolSymbols.ICP;
|
|
4
|
+
export declare class ICPModule implements AirGapModule<{
|
|
5
|
+
Protocols: SupportedProtocols;
|
|
6
|
+
}> {
|
|
7
|
+
private readonly networkRegistries;
|
|
8
|
+
readonly supportedProtocols: Record<SupportedProtocols, ProtocolConfiguration>;
|
|
9
|
+
createV3SerializerCompanion(): Promise<AirGapV3SerializerCompanion>;
|
|
10
|
+
createOfflineProtocol(identifier: SupportedProtocols): Promise<AirGapOfflineProtocol | undefined>;
|
|
11
|
+
createOnlineProtocol(identifier: SupportedProtocols, networkId?: string): Promise<AirGapOnlineProtocol | undefined>;
|
|
12
|
+
createBlockExplorer(identifier: SupportedProtocols, networkId?: string): Promise<AirGapBlockExplorer | undefined>;
|
|
13
|
+
private createProtocol;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ICPModule = void 0;
|
|
40
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
42
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
43
|
+
var ICPBlockExplorer_1 = require("../block-explorer/ICPBlockExplorer");
|
|
44
|
+
var ICPProtocol_1 = require("../protocol/ICPProtocol");
|
|
45
|
+
var serializer_companion_1 = require("../serializer/v3/serializer-companion");
|
|
46
|
+
var ICPModule = /** @class */ (function () {
|
|
47
|
+
function ICPModule() {
|
|
48
|
+
var _a;
|
|
49
|
+
this.networkRegistries = (_a = {},
|
|
50
|
+
_a[coinlib_core_1.MainProtocolSymbols.ICP] = new module_kit_1.ModuleNetworkRegistry({
|
|
51
|
+
supportedNetworks: [ICPProtocol_1.ICP_MAINNET_PROTOCOL_NETWORK]
|
|
52
|
+
}),
|
|
53
|
+
_a);
|
|
54
|
+
this.supportedProtocols = (0, module_kit_1.createSupportedProtocols)(this.networkRegistries);
|
|
55
|
+
}
|
|
56
|
+
ICPModule.prototype.createV3SerializerCompanion = function () {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
return [2 /*return*/, new serializer_companion_1.ICPV3SerializerCompanion()];
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
ICPModule.prototype.createOfflineProtocol = function (identifier) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
return [2 /*return*/, this.createProtocol(identifier)];
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
ICPModule.prototype.createOnlineProtocol = function (identifier, networkId) {
|
|
71
|
+
var _a;
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var network;
|
|
74
|
+
return __generator(this, function (_b) {
|
|
75
|
+
network = (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkId);
|
|
76
|
+
if (network === undefined) {
|
|
77
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, 'Protocol network not supported.');
|
|
78
|
+
}
|
|
79
|
+
return [2 /*return*/, this.createProtocol(identifier, network)];
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
ICPModule.prototype.createBlockExplorer = function (identifier, networkId) {
|
|
84
|
+
var _a;
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var network;
|
|
87
|
+
return __generator(this, function (_b) {
|
|
88
|
+
network = (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkId);
|
|
89
|
+
if ((network === null || network === void 0 ? void 0 : network.type) !== 'mainnet') {
|
|
90
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, 'Block Explorer network not supported.');
|
|
91
|
+
}
|
|
92
|
+
return [2 /*return*/, new ICPBlockExplorer_1.ICPBlockExplorer()];
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
ICPModule.prototype.createProtocol = function (identifier, network) {
|
|
97
|
+
switch (identifier) {
|
|
98
|
+
case coinlib_core_1.MainProtocolSymbols.ICP:
|
|
99
|
+
return (0, ICPProtocol_1.createICPProtocol)({ network: network });
|
|
100
|
+
default:
|
|
101
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported."));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return ICPModule;
|
|
105
|
+
}());
|
|
106
|
+
exports.ICPModule = ICPModule;
|
|
107
|
+
//# sourceMappingURL=ICPModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICPModule.js","sourceRoot":"","sources":["../../../src/v1/module/ICPModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAkE;AAClE,sDAAqE;AACrE,iDAW2B;AAE3B,uEAAqE;AACrE,uDAAyF;AACzF,8EAAgF;AAIhF;IAAA;;QACmB,sBAAiB;YAChC,GAAC,kCAAmB,CAAC,GAAG,IAAG,IAAI,kCAAqB,CAAC;gBACnD,iBAAiB,EAAE,CAAC,0CAA4B,CAAC;aAClD,CAAC;gBACH;QACe,uBAAkB,GAAsD,IAAA,qCAAwB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAoC1I,CAAC;IAlCc,+CAA2B,GAAxC;;;gBACE,sBAAO,IAAI,+CAAwB,EAAE,EAAA;;;KACtC;IAEY,yCAAqB,GAAlC,UAAmC,UAA8B;;;gBAC/D,sBAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAA;;;KACvC;IAEY,wCAAoB,GAAjC,UAAkC,UAA8B,EAAE,SAAkB;;;;;gBAC5E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,OAAO,KAAK,SAAS,EAAE;oBACzB,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,GAAG,EAAE,iCAAiC,CAAC,CAAA;iBACjF;gBAED,sBAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,EAAA;;;KAChD;IAEY,uCAAmB,GAAhC,UAAiC,UAA8B,EAAE,SAAkB;;;;;gBAC3E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,SAAS,EAAE;oBAC/B,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,GAAG,EAAE,uCAAuC,CAAC,CAAA;iBACvF;gBAED,sBAAO,IAAI,mCAAgB,EAAE,EAAA;;;KAC9B;IAEO,kCAAc,GAAtB,UAAuB,UAA8B,EAAE,OAAyB;QAC9E,QAAQ,UAAU,EAAE;YAClB,KAAK,kCAAmB,CAAC,GAAG;gBAC1B,OAAO,IAAA,+BAAiB,EAAC,EAAE,OAAO,SAAA,EAAE,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,GAAG,EAAE,mBAAY,UAAU,oBAAiB,CAAC,CAAA;SACzF;IACH,CAAC;IACH,gBAAC;AAAD,CAAC,AA1CD,IA0CC;AA1CY,8BAAS"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
2
|
+
interface Transaction {
|
|
3
|
+
to: string;
|
|
4
|
+
amount: bigint;
|
|
5
|
+
fee: bigint;
|
|
6
|
+
}
|
|
7
|
+
export declare function getKeyPairFromMnemonic(mnemonic: string): {
|
|
8
|
+
publicKey: string;
|
|
9
|
+
privateKey: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function getAddressFromPublicKey(publicKey: string, subAccount?: Uint8Array): string;
|
|
12
|
+
export declare function createUnsignedTransaction(transaction: Transaction): string;
|
|
13
|
+
export declare function getInfoFromUnsignedTransaction(unsignedTransaction: string): {
|
|
14
|
+
to: string;
|
|
15
|
+
fee: bigint;
|
|
16
|
+
memo: bigint;
|
|
17
|
+
from_subaccount: string[];
|
|
18
|
+
created_at_time: any[];
|
|
19
|
+
amount: bigint;
|
|
20
|
+
};
|
|
21
|
+
export declare function signTransaction(unsignedTransaction: string, privateKey: string): Promise<string>;
|
|
22
|
+
export declare function getInfoFromSignedTransaction(signedTransaction: string): any;
|
|
23
|
+
export declare function decodeArguments(args: ArrayBuffer): any;
|
|
24
|
+
export declare function getBalanceFromAddress(address: string, host: string): Promise<bigint>;
|
|
25
|
+
export declare function broadcastTransaction(signedTransaction: string, host: string): Promise<string>;
|
|
26
|
+
export {};
|