@bitgo/account-lib 2.18.0-rc.0 → 2.18.0-rc.4
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/DEVELOPER.md +45 -18
- package/README.md +83 -48
- package/dist/browser/bitgo-account-lib.min.js +1 -1
- package/dist/package.json +6 -4
- package/dist/src/coin/baseCoin/ed25519KeyPair.d.ts +9 -1
- package/dist/src/coin/baseCoin/ed25519KeyPair.d.ts.map +1 -1
- package/dist/src/coin/baseCoin/ed25519KeyPair.js +21 -3
- package/dist/src/coin/dot/utils.d.ts +7 -0
- package/dist/src/coin/dot/utils.d.ts.map +1 -1
- package/dist/src/coin/dot/utils.js +10 -1
- package/dist/src/coin/sol/index.d.ts +3 -0
- package/dist/src/coin/sol/index.d.ts.map +1 -1
- package/dist/src/coin/sol/index.js +8 -2
- package/dist/src/coin/sol/keyPair.d.ts +4 -22
- package/dist/src/coin/sol/keyPair.d.ts.map +1 -1
- package/dist/src/coin/sol/keyPair.js +42 -89
- package/dist/src/coin/sol/transactionBuilder.d.ts.map +1 -1
- package/dist/src/coin/sol/transactionBuilder.js +8 -2
- package/dist/src/coin/stx/sendmanyBuilder.d.ts.map +1 -1
- package/dist/src/coin/stx/sendmanyBuilder.js +5 -2
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -2
- package/dist/src/mpc/curves.d.ts +14 -0
- package/dist/src/mpc/curves.d.ts.map +1 -0
- package/dist/src/mpc/curves.js +99 -0
- package/dist/src/mpc/shamir.d.ts +7 -0
- package/dist/src/mpc/shamir.d.ts.map +1 -0
- package/dist/src/mpc/shamir.js +91 -0
- package/dist/src/mpc/tss.d.ts +69 -0
- package/dist/src/mpc/tss.d.ts.map +1 -0
- package/dist/src/mpc/tss.js +255 -0
- package/dist/src/utils/ed25519KeyDeriver.d.ts +49 -0
- package/dist/src/utils/ed25519KeyDeriver.d.ts.map +1 -0
- package/dist/src/utils/ed25519KeyDeriver.js +92 -0
- package/package.json +6 -4
package/DEVELOPER.md
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
# Developer Guide
|
|
2
|
-
Thanks for contributing to this library. Below are some tips to help you understand:
|
|
3
|
-
* the structure of the project
|
|
4
|
-
* the important classes and how they are used
|
|
5
|
-
* how to run the test suite
|
|
6
|
-
* how to contribute to the project
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
Thanks for contributing to this library. Below are some tips to help you
|
|
4
|
+
understand:
|
|
5
|
+
|
|
6
|
+
- the structure of the project
|
|
7
|
+
- the important classes and how they are used
|
|
8
|
+
- how to run the test suite
|
|
9
|
+
- how to contribute to the project
|
|
9
10
|
|
|
11
|
+
## Project Architecture
|
|
10
12
|
|
|
11
13
|
### Base Classes
|
|
12
|
-
As specified in [the project README](README.md), there are two main classes that users will interact with:
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
As specified in [the project README](README.md), there are two main classes that
|
|
16
|
+
users will interact with:
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
- `TransactionBuilder`: A class that implements coin specific logic to handle
|
|
19
|
+
the construction, validation, and signing of blockchain transactions.
|
|
20
|
+
- `Transaction`: JavaScript representations of blockchain transactions.
|
|
21
|
+
|
|
22
|
+
The `TransactionBuilder`'s job is to build and sign `transactions` for a
|
|
23
|
+
specific blockchain.
|
|
18
24
|
|
|
19
25
|
The flow typically looks something like:
|
|
20
26
|
|
|
@@ -39,20 +45,35 @@ const signedTxJson = tx.toJson();
|
|
|
39
45
|
```
|
|
40
46
|
|
|
41
47
|
### Coin Specific Implementations
|
|
42
|
-
If you have spent time poking around the project, you likely noticed that we have base `TransactionBuilder` and base `Transaction` classes - they live in `src/coin/baseCoin`. These classes define the core interfaces that all subclasses will extend and implement.
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
If you have spent time poking around the project, you likely noticed that we
|
|
50
|
+
have base `TransactionBuilder` and base `Transaction` classes - they live in
|
|
51
|
+
`src/coin/baseCoin`. These classes define the core interfaces that all
|
|
52
|
+
subclasses will extend and implement.
|
|
53
|
+
|
|
54
|
+
Coin specific implementations of the `TransactionBuilder` and `Transaction`
|
|
55
|
+
classes live under the coin's ticker symbol in `src/coin` (ie: `src/coin/trx`
|
|
56
|
+
for Tron). This is where the meat of the signing, validation, and encoding logic
|
|
57
|
+
lives for each blockchain supported by the library.
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
We recommend that you follow this pattern when adding a new coin to the library:
|
|
47
60
|
|
|
48
61
|
### Test Structure
|
|
49
|
-
This library comes with unit tests and it is expected that all changes introduced to the library increase test coverage. Tests live in `test`. Coin specific tests live in `test/unit/coin/<coin-ticker>/<coin-ticker.js>`.
|
|
50
62
|
|
|
63
|
+
Account Lib comes with unit tests and it is expected that all changes introduced
|
|
64
|
+
to the library increase test coverage. Tests live in `test`. Coin specific tests
|
|
65
|
+
live in `test/unit/coin/<coin-ticker>/<coin-ticker.js>`.
|
|
51
66
|
|
|
52
67
|
## (External) Resources
|
|
53
|
-
|
|
68
|
+
|
|
69
|
+
There are situations in which this library requires upstream dependencies, but
|
|
70
|
+
you might not want to pull in the entire library only to use the tiny slice of
|
|
71
|
+
functionality that we require. Rather, you can take snippets of the external
|
|
72
|
+
code and stick them in `resources/`. See
|
|
73
|
+
[the README in that directory for more information](resources/README.md).
|
|
54
74
|
|
|
55
75
|
## Running Tests
|
|
76
|
+
|
|
56
77
|
To run the test suite locally:
|
|
57
78
|
|
|
58
79
|
```
|
|
@@ -60,7 +81,13 @@ npm test
|
|
|
60
81
|
```
|
|
61
82
|
|
|
62
83
|
## Coding Norms & Expectations
|
|
63
|
-
When contributing, it is recommended that you follow the existing patterns defined in the project. Pull requests that break these norms will likely be rejected or require a round of feedback. A few specific notes:
|
|
64
84
|
|
|
65
|
-
|
|
66
|
-
|
|
85
|
+
When contributing, we recommend that you follow the existing patterns defined in
|
|
86
|
+
the project. Pull requests that break these norms will likely be rejected or
|
|
87
|
+
require a round of feedback.
|
|
88
|
+
|
|
89
|
+
Take note:
|
|
90
|
+
|
|
91
|
+
> Do not specify default accessors. In TypeScript, the default accessor for a
|
|
92
|
+
> class attribute is `public`, so specifying it for functions and attributes is
|
|
93
|
+
> redundant.
|
package/README.md
CHANGED
|
@@ -1,50 +1,72 @@
|
|
|
1
1
|
# BitGo Account Lib
|
|
2
2
|
|
|
3
|
-
This library is responsible for building and signing transactions for
|
|
3
|
+
This library is responsible for building and signing transactions for
|
|
4
|
+
account-based coins (for example, Ethereum, Algorand, EOS, Tron, etc.). Account
|
|
5
|
+
Lib was developed for BitGo and BitGo's multi-sig wallets, but it can also be
|
|
6
|
+
used independently, outside of our wallet ecosystem.
|
|
7
|
+
|
|
8
|
+
> Account Lib can be used in an offline environment.
|
|
4
9
|
|
|
5
10
|
## Supported Coins
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|Ethereum
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
11
|
+
|
|
12
|
+
Below is the list of coins supported by this library -- as well as those that
|
|
13
|
+
are on the roadmap.
|
|
14
|
+
|
|
15
|
+
| Coin | Mainnet Ticker | Testnet Ticker | Supported In Library |
|
|
16
|
+
| :--------------- | :------------- | :------------- | :------------------- |
|
|
17
|
+
| Tron | trx | ttrx | Yes |
|
|
18
|
+
| Tezos | xtz | txtz | Yes |
|
|
19
|
+
| Ethereum | eth | teth | Yes |
|
|
20
|
+
| CELO | celo | tcelo | Yes |
|
|
21
|
+
| Ethereum Classic | etc | tetc | Yes |
|
|
22
|
+
| RSK | rbtc | trbtc | Yes |
|
|
23
|
+
| EOS | eos | teos | Not yet... |
|
|
24
|
+
| Alogrand | algo | talgo | Not yet... |
|
|
25
|
+
| Ripple | xrp | txrp | Not yet... |
|
|
26
|
+
| Stellar | xlm | txlm | Not yet... |
|
|
20
27
|
|
|
21
28
|
## Core Concepts
|
|
22
29
|
|
|
23
30
|
### TransactionBuilder
|
|
24
|
-
|
|
31
|
+
|
|
32
|
+
The `TranssactionBuilder` class guides a user through the construction of a
|
|
33
|
+
transaction. The purpose of the `TransactionBuilder` is to yield a `Transaction`
|
|
34
|
+
object that can broadcast to the network.
|
|
25
35
|
|
|
26
36
|
### Transaction
|
|
27
|
-
|
|
37
|
+
|
|
38
|
+
`Transaction` objects are JavaScript representations of blockchain transactions
|
|
39
|
+
that implement protocol specific validation rules. `Transactions` provide
|
|
40
|
+
encoding mechanisms that allow them to be validly broadcast to their respective
|
|
41
|
+
network.
|
|
28
42
|
|
|
29
43
|
#### Transaction Types
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
|
|
45
|
+
`TransactionBuilder` supports the following transaction types:
|
|
46
|
+
|
|
47
|
+
- **Send**: Transfers funds from a wallet.
|
|
48
|
+
|
|
49
|
+
- **Wallet Initialization**: Initializes a wallet's account on the network
|
|
50
|
+
(e.g., multi-sig contract deployment).
|
|
51
|
+
|
|
52
|
+
- **Address Initialization**: Initializes a wallet's address on the network
|
|
53
|
+
(e.g., forwarder contract deployment).
|
|
54
|
+
|
|
55
|
+
- **Account Update**: Updates an account on the network (e.g., public key
|
|
56
|
+
revelation operation for Tezos).
|
|
39
57
|
|
|
40
58
|
### Offline Availability
|
|
41
|
-
|
|
59
|
+
|
|
60
|
+
Account Lib was designed to be used for offline signings in an offline
|
|
61
|
+
environment.
|
|
42
62
|
|
|
43
63
|
---
|
|
44
64
|
|
|
45
65
|
## Installation
|
|
46
66
|
|
|
47
|
-
Install the library
|
|
67
|
+
Install the library with npm. If you plan on contributing to the project, you
|
|
68
|
+
may wish to follow different installation instructions
|
|
69
|
+
[outlined in this doc](DEVELOPER.md).
|
|
48
70
|
|
|
49
71
|
```
|
|
50
72
|
$ cd <your_project>
|
|
@@ -52,10 +74,13 @@ $ npm install @bitgo/account-lib
|
|
|
52
74
|
```
|
|
53
75
|
|
|
54
76
|
## Usage
|
|
55
|
-
|
|
77
|
+
|
|
78
|
+
Below is an example that demonstrates how the library can be used to build and
|
|
79
|
+
sign a Tron testnet transaction.
|
|
56
80
|
|
|
57
81
|
### Instantiation
|
|
58
|
-
|
|
82
|
+
|
|
83
|
+
Instantiate the `TransactionBuilder` for the coin you want to work with:
|
|
59
84
|
|
|
60
85
|
```javascript
|
|
61
86
|
// Import the package (javascript import)
|
|
@@ -67,8 +92,10 @@ import * as accountLib from '@bitgo/account-lib';
|
|
|
67
92
|
const txBuilder = accountLib.getBuilder('ttrx');
|
|
68
93
|
```
|
|
69
94
|
|
|
70
|
-
### Transaction Construction
|
|
71
|
-
|
|
95
|
+
### Transaction Construction and Signing
|
|
96
|
+
|
|
97
|
+
Use the transaction builder instance (created in the previous step) to sign a
|
|
98
|
+
transaction:
|
|
72
99
|
|
|
73
100
|
```javascript
|
|
74
101
|
// Define an unsigned Tron transaction object
|
|
@@ -76,38 +103,46 @@ const unsignedBuildTransaction = {
|
|
|
76
103
|
visible: false,
|
|
77
104
|
txID: '80b8b9eaed51c8bba3b49f7f0e7cc5f21ac99a6f3e2893c663b544bf2c695b1d',
|
|
78
105
|
raw_data: {
|
|
79
|
-
contract: [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
106
|
+
contract: [
|
|
107
|
+
{
|
|
108
|
+
parameter: {
|
|
109
|
+
value: {
|
|
110
|
+
amount: 1718,
|
|
111
|
+
owner_address: '41c4530f6bfa902b7398ac773da56106a15af15f92',
|
|
112
|
+
to_address: '4189ffaf9da8c6fae32189b2e6dce228249b1129aa',
|
|
113
|
+
},
|
|
114
|
+
type_url: 'type.googleapis.com/protocol.TransferContract',
|
|
85
115
|
},
|
|
86
|
-
|
|
116
|
+
type: 'TransferContract',
|
|
87
117
|
},
|
|
88
|
-
|
|
89
|
-
} ],
|
|
118
|
+
],
|
|
90
119
|
ref_block_bytes: '90e4',
|
|
91
120
|
ref_block_hash: 'a018bf9892ddb138',
|
|
92
121
|
expiration: 1571811468000,
|
|
93
|
-
timestamp: 1571811410819
|
|
122
|
+
timestamp: 1571811410819,
|
|
94
123
|
},
|
|
95
|
-
raw_data_hex:
|
|
124
|
+
raw_data_hex:
|
|
125
|
+
'0a0290e42208a018bf9892ddb13840e0c58ebadf2d5a66080112620a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412310a1541c4530f6bfa902b7398ac773da56106a15af15f9212154189ffaf9da8c6fae32189b2e6dce228249b1129aa18b60d7083878bbadf2d',
|
|
96
126
|
};
|
|
97
127
|
|
|
98
128
|
// Use that object to build and sign a transaction
|
|
99
129
|
txBuilder.from(unsignedBuildTransaction);
|
|
100
130
|
txBuilder.sign({
|
|
101
|
-
key: 'A81B2E0C55A7E2B2E837ZZC437A6397B316536196989A6F09EE49C19AD33590W'
|
|
131
|
+
key: 'A81B2E0C55A7E2B2E837ZZC437A6397B316536196989A6F09EE49C19AD33590W',
|
|
102
132
|
});
|
|
103
133
|
const tx = await txBuilder.build();
|
|
104
134
|
```
|
|
105
135
|
|
|
106
136
|
More examples:
|
|
107
|
-
|
|
108
|
-
|
|
137
|
+
|
|
138
|
+
- [Tron transaction building examples](https://github.com/BitGo/bitgo-account-lib/blob/master/test/unit/coin/trx/transactionBuilder.ts)
|
|
139
|
+
- [Tezos transaction building examples](https://github.com/BitGo/bitgo-account-lib/blob/master/test/unit/coin/xtz/transactionBuilder.ts)
|
|
109
140
|
|
|
110
141
|
## Developers
|
|
111
|
-
If you'd like to contribute to this project, see the [developer guide](DEVELOPER.md) for contribution norms and expectations.
|
|
112
142
|
|
|
113
|
-
|
|
143
|
+
If you'd like to contribute to this project, see the
|
|
144
|
+
[developer guide](DEVELOPER.md) for contribution norms and expectations.
|
|
145
|
+
|
|
146
|
+
There is a near-term goal to move this library toward a plugin-based
|
|
147
|
+
architecture for coin registration. Until then, PRs adding support for new coins
|
|
148
|
+
will be put on hold.
|