Skip to content

Commit 8edc2fc

Browse files
committed
Initial commit
0 parents  commit 8edc2fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6836
-0
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
packages/truffle/build

.eslintrc.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"es2021": true,
5+
"node": true
6+
},
7+
"globals": {
8+
"BUNDLE_VERSION": "readonly",
9+
"BUNDLE_CHAIN_FILENAME": "readonly",
10+
"BUNDLE_ANALYTICS_FILENAME": "readonly",
11+
"BUNDLE_LIBRARY_FILENAME": "readonly",
12+
"BUNDLE_CONSOLE_CHILD_FILENAME": "readonly"
13+
},
14+
"extends": [
15+
"plugin:react-hooks/recommended"
16+
],
17+
"parser": "@typescript-eslint/parser",
18+
"plugins": ["@typescript-eslint"],
19+
"parserOptions": {
20+
"sourceType": "module"
21+
},
22+
"ignorePatterns": ["dist"],
23+
"rules": {
24+
"@typescript-eslint/no-unused-vars": [
25+
"error",
26+
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^debug$|^_" }
27+
],
28+
"quote-props": [ "error", "consistent" ],
29+
"@typescript-eslint/semi": [ "error", "always" ],
30+
"no-mixed-operators": "warn",
31+
"no-tabs": "warn",
32+
"no-useless-escape": "warn",
33+
"no-undef": ["error", { "typeof": true }],
34+
"semi":["error"]
35+
}
36+
}

.eslintrc.package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": ["./**/test/**/*.[tj]s"],
5+
"env": {
6+
"mocha": true,
7+
"jest": true
8+
}
9+
}
10+
]
11+
}

.eslintrc.truffle.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": ["./test/**/*.js"],
5+
"env": {
6+
"mocha": true
7+
},
8+
"globals": {
9+
"interfaceAdapter": "readonly",
10+
"web3": "readonly",
11+
"assert": "readonly",
12+
"expect": "readonly",
13+
"artifacts": "readonly",
14+
"config": "readonly",
15+
"debug": "readonly",
16+
"contract": "readonly"
17+
}
18+
},
19+
{
20+
"files": ["./migrations/**/*.js"],
21+
"globals": {
22+
"artifacts": "readonly",
23+
"config": "readonly"
24+
}
25+
}
26+
]
27+
}
28+

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sol linguist-language=Solidity,tabwidth=4

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
dependency-graph.pdf
2+
lerna-debug.log
3+
packages/**/node_modules
4+
node_modules
5+
yarn-error.log
6+
.vscode
7+
.DS_Store
8+
Thumbs.db
9+
$RECYCLE.BIN/
10+
11+
# truffle
12+
packages/truffle/build
13+
packages/truffle/stats.json
14+
packages/truffle/.DS_Store
15+
packages/truffle/Thumbs.db
16+
packages/truffle/.tern-port
17+
packages/truffle/dependencies
18+
packages/truffle/$RECYCLE.BIN/
19+
20+
# @truffle/debugger
21+
packages/debugger/.tmp
22+
23+
# @truffle/contract
24+
packages/contract/dist

.nycrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"all": true,
3+
"reporter": "lcovonly",
4+
"exclude": [
5+
"**/node_modules/**",
6+
"**/.tmp",
7+
"**/scripts/**",
8+
"**/test/**",
9+
"**/build/**",
10+
"**/dist/**",
11+
"**/webpack",
12+
"**/*webpack.config*",
13+
"notes/"
14+
]
15+
}

.prettierrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"arrowParens": "avoid",
3+
"trailingComma": "none",
4+
"bracketSpacing": true
5+
}

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017-2019 Truffle Blockchain Group, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# @truffle/hdwallet-provider
2+
HD Wallet-enabled Web3 provider. Use it to sign transactions for addresses derived from a 12 or 24 word mnemonic.
3+
4+
## Install
5+
6+
```
7+
$ npm install @truffle/hdwallet-provider
8+
```
9+
10+
## Requirements
11+
```
12+
Node >= 12
13+
Web3 ^1.2.0
14+
```
15+
16+
## General Usage
17+
18+
You can use this provider wherever a Web3 provider is needed, not just in Truffle. For Truffle-specific usage, see next section.
19+
20+
By default, the `HDWalletProvider` will use the address of the first address that's generated from the mnemonic. If you pass in a specific index, it'll use that address instead.
21+
22+
### Instantiation
23+
24+
You can instantiate `hdwallet-provider` with options passed in an object with
25+
named keys. You can specify the following options in your object:
26+
27+
Parameters:
28+
29+
| Parameter | Type | Default | Required | Description |
30+
| ------ | ---- | ------- | ----------- | ----------- |
31+
| `mnemonic` | `object\|string` | `null` | [ ] | Object containing `phrase` and `password` (optional) properties. `phrase` is a 12 word mnemonic string which addresses are created from. Alternately the value for mnemonic can be a string with your mnemonic phrase. |
32+
| `privateKeys` | `string[]` | `null` | [ ] | Array containing 1 or more private keys. |
33+
| `providerOrUrl` | `string\|object` | `null` | [x] | URI or Ethereum client to send all other non-transaction-related Web3 requests |
34+
| `addressIndex` | `number` | `0` | [ ] | If specified, will tell the provider to manage the address at the index specified |
35+
| `numberOfAddresses` | `number` | `1` | [ ] | If specified, will create `numberOfAddresses` addresses when instantiated |
36+
| `shareNonce` | `boolean` | `true` | [ ] | If `false`, a new WalletProvider will track its own nonce-state |
37+
| `derivationPath` | `string` | `"m/44'/60'/0'/0/"` | [ ] | If specified, will tell the wallet engine what derivation path should use to derive addresses. |
38+
| `pollingInterval` | `number` | `4000` | [ ] | If specified, will tell the wallet engine to use a custom interval when polling to track blocks. Specified in milliseconds. |
39+
| `chainId` | `number\|string` | `undefined` | [ ] | Specify to enable signed transactions that are EIP-155 compliant for major chains. |
40+
41+
Some examples can be found below:
42+
43+
```javascript
44+
const HDWalletProvider = require("@truffle/hdwallet-provider");
45+
const Web3 = require("web3");
46+
const mnemonicPhrase = "mountains supernatural bird..."; // 12 word mnemonic
47+
let provider = new HDWalletProvider({
48+
mnemonic: {
49+
phrase: mnemonicPhrase
50+
},
51+
providerOrUrl: "http://localhost:8545"
52+
});
53+
54+
// Or, alternatively pass in a zero-based address index.
55+
provider = new HDWalletProvider({
56+
mnemonic: mnemonicPhrase,
57+
providerOrUrl: "http://localhost:8545",
58+
addressIndex: 5
59+
});
60+
61+
// Or, use your own hierarchical derivation path
62+
provider = new HDWalletProvider({
63+
mnemonic: mnemonicPhrase,
64+
providerOrUrl: "http://localhost:8545",
65+
numberOfAddresses: 1,
66+
shareNonce: true,
67+
derivationPath: "m/44'/137'/0'/0/"
68+
});
69+
70+
// To make HDWallet less "chatty" over JSON-RPC,
71+
// configure a higher value for the polling interval.
72+
provider = new HDWalletProvider({
73+
mnemonic: {
74+
phrase: mnemonicPhrase
75+
},
76+
providerOrUrl: "http://localhost:8545",
77+
pollingInterval: 8000
78+
});
79+
80+
// HDWalletProvider is compatible with Web3. Use it at Web3 constructor, just like any other Web3 Provider
81+
const web3 = new Web3(provider);
82+
83+
// Or, if web3 is alreay initialized, you can call the 'setProvider' on web3, web3.eth, web3.shh and/or web3.bzz
84+
web3.setProvider(provider)
85+
86+
// ...
87+
// Write your code here.
88+
// ...
89+
90+
// At termination, `provider.engine.stop()' should be called to finish the process elegantly.
91+
provider.engine.stop();
92+
```
93+
94+
**Note: If both mnemonic and private keys are provided, the mnemonic is used.**
95+
96+
### Using the legacy interface (deprecated)
97+
98+
The legacy interface is deprecated and it is recommended to pass options in an
99+
object as detailed above. The following method of passing options is here
100+
primarily to document the interface thoroughly and avoid confusion.
101+
102+
You can specify the following options in the order below.
103+
Pass `undefined` if you want to omit a parameter.
104+
105+
Parameters:
106+
107+
| Parameter | Type | Default | Required | Description |
108+
| ------ | ---- | ------- | ----------- | ----------- |
109+
| `mnemonic`/`privateKeys` | `string`/`string[]` | `null` | [x] | 12 word mnemonic which addresses are created from or array of private keys. |
110+
| `providerOrUrl` | `string\|object` | `null` | [x] | URI or Ethereum client to send all other non-transaction-related Web3 requests |
111+
| `addressIndex` | `number` | `0` | [ ] | If specified, will tell the provider to manage the address at the index specified |
112+
| `numberOfAddresses` | `number` | `1` | [ ] | If specified, will create `numberOfAddresses` addresses when instantiated |
113+
| `shareNonce` | `boolean` | `true` | [ ] | If `false`, a new WalletProvider will track its own nonce-state |
114+
| `derivationPath` | `string` | `"m/44'/60'/0'/0/"` | [ ] | If specified, will tell the wallet engine what derivation path should use to derive addresses. |
115+
| `chainId` | `number\|string` | `undefined` | [ ] | Specify to enable signed transactions that are EIP-155 compliant for major chains. |
116+
117+
Instead of a mnemonic, you can alternatively provide a private key or array of
118+
private keys as the first parameter. When providing an array, `addressIndex`
119+
and `numberOfAddresses` are fully supported.
120+
121+
```javascript
122+
const HDWalletProvider = require("@truffle/hdwallet-provider");
123+
//load single private key as string
124+
let provider = new HDWalletProvider("3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", "http://localhost:8545");
125+
126+
// Or, pass an array of private keys, and optionally use a certain subset of addresses
127+
const privateKeys = [
128+
"3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
129+
"9549f39decea7b7504e15572b2c6a72766df0281cea22bd1a3bc87166b1ca290",
130+
];
131+
provider = new HDWalletProvider(privateKeys, "http://localhost:8545", 0, 2); //start at address_index 0 and load both addresses
132+
```
133+
**NOTE: This is just an example. NEVER hard code production/mainnet private
134+
keys in your code or commit them to git. They should always be loaded from
135+
environment variables or a secure secret management system.**
136+
137+
## Truffle Usage
138+
139+
You can easily use this within a Truffle configuration. For instance:
140+
141+
truffle-config.js
142+
```javascript
143+
const HDWalletProvider = require("@truffle/hdwallet-provider");
144+
145+
const mnemonicPhrase = "mountains supernatural bird ...";
146+
147+
module.exports = {
148+
networks: {
149+
development: {
150+
host: "localhost",
151+
port: 8545,
152+
network_id: "*" // Match any network id
153+
},
154+
ropsten: {
155+
// must be a thunk, otherwise truffle commands may hang in CI
156+
provider: () =>
157+
new HDWalletProvider({
158+
mnemonic: {
159+
phrase: mnemonicPhrase
160+
},
161+
providerOrUrl: "https://ropsten.infura.io/v3/YOUR-PROJECT-ID",
162+
numberOfAddresses: 1,
163+
shareNonce: true,
164+
derivationPath: "m/44'/1'/0'/0/"
165+
}),
166+
network_id: '3',
167+
}
168+
}
169+
};
170+
```

dist/constructor/Constructor.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Mnemonic, MnemonicPhrase, PrivateKey, Provider, ProviderUrl, ProviderOrUrl, AddressIndex, NumberOfAddresses, PollingInterval, ShareNonce, DerivationPath, ChainId, ChainSettings } from "./types";
2+
export interface MnemonicSigningAuthority {
3+
mnemonic: Mnemonic;
4+
}
5+
export interface MnemonicPhraseSigningAuthority {
6+
mnemonic: MnemonicPhrase;
7+
}
8+
export interface PrivateKeysSigningAuthority {
9+
privateKeys: PrivateKey[];
10+
}
11+
export declare type SigningAuthority = MnemonicSigningAuthority | PrivateKeysSigningAuthority;
12+
export declare type InputSigningAuthority = MnemonicSigningAuthority | MnemonicPhraseSigningAuthority | PrivateKeysSigningAuthority;
13+
export interface CommonOptions {
14+
providerOrUrl?: ProviderOrUrl;
15+
provider?: Provider;
16+
url?: ProviderUrl;
17+
addressIndex?: AddressIndex;
18+
numberOfAddresses?: NumberOfAddresses;
19+
shareNonce?: ShareNonce;
20+
derivationPath?: DerivationPath;
21+
pollingInterval?: PollingInterval;
22+
chainId?: ChainId;
23+
chainSettings?: ChainSettings;
24+
}
25+
export declare type Options = SigningAuthority & CommonOptions;
26+
export declare type InputOptions = InputSigningAuthority & CommonOptions;

dist/constructor/Constructor.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/constructor/Constructor.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type * as LegacyConstructor from "./LegacyConstructor";
2+
import type * as Constructor from "./Constructor";
3+
export declare type ConstructorArguments = LegacyConstructor.Arguments | [Constructor.InputOptions];

dist/constructor/ConstructorArguments.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/constructor/ConstructorArguments.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)