@massalabs/wallet-provider 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Massa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
`Wallet-provider` is a TypeScript library that one could utilize to establish a connection between a frontend application and any browser wallet extensions that implement the [massa standard](https://github.com/massalabs/massa-standards/blob/main/wallet/dapps-communication.md). With this library one can access all massa-blockchain wallets and their standardized functionalities for ready use.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
`Wallet-provider` could be used as a library for frameworks or as a stand-alone bundled js file which can be easily loaded into the browser.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Library (Node.js/React/Vue.js) usage
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
> npm install @massalabs/wallet-provider
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Browser usage
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Add the following script to your html file:
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
|
|
37
|
+
<script
|
|
38
|
+
|
|
39
|
+
type="text/javascript"
|
|
40
|
+
|
|
41
|
+
src="https://cdn.jsdelivr.net/npm/@massalabs/wallet-provider@x.x.x/bundle.js"
|
|
42
|
+
|
|
43
|
+
></script>
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
whereby the x.x.x is one of the available released versions under [Wallet-provider's releases page](https://github.com/massalabs/wallet-provider/releases).
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
In your code, once the script is fully loaded, just use `window.wallet` to access all `wallet-provider`'s' exported functionalities.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
|
|
58
|
+
<script>
|
|
59
|
+
|
|
60
|
+
const providers = window.massa.providers();
|
|
61
|
+
|
|
62
|
+
console.log("Massa Providers ", providers);
|
|
63
|
+
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
Wallet-provider provides complete documentation of all available functions and objects.
|
|
73
|
+
|
|
74
|
+
To generate the documentation for a specific branch, run the following command:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
npm run doc
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The documentation will be generated in the `docs/documentation/html` directory.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Web3 Wallet Provider Requirement and Initialization
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Requirements
|
|
88
|
+
|
|
89
|
+
- NodeJS 16+
|
|
90
|
+
|
|
91
|
+
- npm / yarn (see package.json)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
### Initialization
|
|
95
|
+
|
|
96
|
+
1. Run `npm install` to install all dependencies
|
|
97
|
+
|
|
98
|
+
2. Run `npx playwright install --with-deps` to install playwright and its dependencies
|
|
99
|
+
|
|
100
|
+
3. Run `npm run build` to build distribution content
|
|
101
|
+
|
|
102
|
+
4. Run `npm run test` to run integration and unit tests
|
|
103
|
+
|
|
104
|
+
<br>
|
|
105
|
+
|
|
106
|
+
The library exports a function called `providers` which can be executed to return a vector of all massa-wallet providers currently initialized in the space. As shown below in the example code, each provider has its own callable methods for listing, importing and deleting accounts. Each account can return its name, address and has methods to retrieve its balance and sign a data array.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
|
|
110
|
+
import { providers } from "@massalabs/wallet-provider";
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// get all available massa-wallet providers
|
|
114
|
+
|
|
115
|
+
const providers = providers();
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// get a provider
|
|
119
|
+
|
|
120
|
+
const myProvider = providers[0];
|
|
121
|
+
|
|
122
|
+
console.log("Provider Name", myProvider.name());
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// import an account via the massa-wallet provider
|
|
126
|
+
|
|
127
|
+
console.log("Importing an account ...");
|
|
128
|
+
|
|
129
|
+
const privateKey = "Sxxxxxxxxxxxxxx";
|
|
130
|
+
|
|
131
|
+
const publicKey = "Pxxxxxxxxxxxxxxx";
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
await myProvider.importAccount(publicKey, privateKey);
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
// get accounts
|
|
138
|
+
|
|
139
|
+
console.log("Retrieving the accounts ...");
|
|
140
|
+
|
|
141
|
+
const myAccounts = await myProvider.accounts();
|
|
142
|
+
|
|
143
|
+
console.log("Provider accounts ...", myAccounts);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// getting one account
|
|
147
|
+
|
|
148
|
+
const myAccount = myAccounts[0];
|
|
149
|
+
|
|
150
|
+
console.log("Account address ", myAccount.address());
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
// getting account balance
|
|
154
|
+
|
|
155
|
+
console.log("Retrieving the account balance ...");
|
|
156
|
+
|
|
157
|
+
const accountBalance = await myAccount.balance();
|
|
158
|
+
|
|
159
|
+
console.log("Account Balance = ", accountBalance.balance);
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
// signing a message
|
|
163
|
+
|
|
164
|
+
console.log("Signing a message ...");
|
|
165
|
+
|
|
166
|
+
const signature = await myAccount.sign([0, 1, 2]);
|
|
167
|
+
|
|
168
|
+
console.log("Signature = ", signature);
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// deleting an account
|
|
172
|
+
|
|
173
|
+
console.log("Deleting an account ...");
|
|
174
|
+
|
|
175
|
+
await myProvider.importAccount(myAccount.address());
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## Contributing
|
|
181
|
+
We welcome contributions from the community!
|
|
182
|
+
|
|
183
|
+
If you would like to contribute to Massa-as-sdk, please read the [CONTRIBUTING file](https://github.com/massalabs/wallet-provider/blob/main/CONTRIBUTING.md).
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@massalabs/wallet-provider",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "massa's wallet provider",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"up": "npm update",
|
|
9
|
+
"check": "npm outdated",
|
|
10
|
+
"upgrade": "npm run up && npm run check && npm run build",
|
|
11
|
+
"build-package": "rimraf dist/* && tsc -d -p ./tsconfig.json",
|
|
12
|
+
"build-bundle": "npm run gen-bundle",
|
|
13
|
+
"gen-bundle": "browserify dist/index.js -p esmify --standalone wallet > bundle.js",
|
|
14
|
+
"uglify-bundle-optimize": "browserify dist/index.js -p esmify -i node-fetch -i http -i https -o bundle.min.js && browserify dist/index.js -p esmify -i node-fetch -g uglifyify --compress --mangle -o bundle.min.js",
|
|
15
|
+
"build": "npm run fmt && npm run build-package && npm run build-bundle",
|
|
16
|
+
"update-version-major": "npm version major",
|
|
17
|
+
"update-version-minor": "npm version minor",
|
|
18
|
+
"update-version-patch": "npm version patch",
|
|
19
|
+
"test:serve-dapp": "cp ./bundle.js ./test/dapp/bundle.js && http-server test/dapp --cors --port 9009",
|
|
20
|
+
"test": "cd ./test && npx playwright test",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"lint:fix": "eslint . --fix",
|
|
23
|
+
"prettier": "prettier --check .",
|
|
24
|
+
"prettier:fix": "prettier --write .",
|
|
25
|
+
"fmt": "npm run prettier:fix && npm run lint:fix",
|
|
26
|
+
"fmt:check": "npm run prettier && npm run lint",
|
|
27
|
+
"doc": "typedoc src/index.ts --name massa-wallet-provider --out docs/documentation/html --tsconfig tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
"author": "Massa Labs <info@massa.net>",
|
|
30
|
+
"contributors": [
|
|
31
|
+
"Evgeni Pirianov"
|
|
32
|
+
],
|
|
33
|
+
"license": "(MIT AND Apache-2.0)",
|
|
34
|
+
"homepage": "https://github.com/massalabs/massa-wallet-provider",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/massalabs/massa-wallet-provider"
|
|
38
|
+
},
|
|
39
|
+
"private": false,
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"web3",
|
|
46
|
+
"ts",
|
|
47
|
+
"sdk",
|
|
48
|
+
"massa"
|
|
49
|
+
],
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"bundle.js",
|
|
53
|
+
"bundle.min.js"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"bignumber.js": "^9.1.1",
|
|
57
|
+
"buffer": "^6.0.3",
|
|
58
|
+
"esmify": "^2.1.1",
|
|
59
|
+
"uid": "^2.0.1"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@massalabs/eslint-config": "^0.0.9",
|
|
63
|
+
"@massalabs/prettier-config-as": "^0.0.2",
|
|
64
|
+
"@playwright/test": "^1.32.3",
|
|
65
|
+
"@types/bn.js": "^5.1.1",
|
|
66
|
+
"@types/chai": "^4.3.4",
|
|
67
|
+
"@types/mocha": "^10.0.1",
|
|
68
|
+
"@types/node": "^18.13.0",
|
|
69
|
+
"@types/secp256k1": "^4.0.3",
|
|
70
|
+
"browserify": "^17.0.0",
|
|
71
|
+
"chai": "^4.3.7",
|
|
72
|
+
"chalk": "^4.1.0",
|
|
73
|
+
"eslint-plugin-jsdoc": "^41.1.1",
|
|
74
|
+
"express": "^4.18.2",
|
|
75
|
+
"fs-extra": "^11.1.1",
|
|
76
|
+
"http-server": "^14.1.1",
|
|
77
|
+
"mocha": "^10.2.0",
|
|
78
|
+
"node-ts": "^5.1.2",
|
|
79
|
+
"ts-node": "^10.9.1",
|
|
80
|
+
"tslib": "^2.5.0",
|
|
81
|
+
"tslint": "^6.1.3",
|
|
82
|
+
"typedoc": "^0.23.25",
|
|
83
|
+
"typescript": "^4.9.5",
|
|
84
|
+
"uglify-js": "^3.17.4",
|
|
85
|
+
"uglifyify": "^5.0.2"
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"bufferutil": "^4.0.7",
|
|
89
|
+
"utf-8-validate": "^6.0.2"
|
|
90
|
+
},
|
|
91
|
+
"prettier": "@massalabs/prettier-config-as"
|
|
92
|
+
}
|