unwallet-client-sdk 0.4.0 → 0.4.1
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 +5 -74
- package/docs/functions-1.md +108 -0
- package/docs/functions-2.md +32 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# unWallet client-side SDK
|
|
2
2
|
|
|
3
|
-
:warning:
|
|
3
|
+
:warning: This SDK works fine only on browsers.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,11 +8,7 @@
|
|
|
8
8
|
$ npm install unwallet-client-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
To execute the sample codes below, you need to create an application with unWallet Enterprise in advance.
|
|
14
|
-
|
|
15
|
-
### Initialization
|
|
11
|
+
## Initialization
|
|
16
12
|
|
|
17
13
|
```js
|
|
18
14
|
import { UnWallet } from "unwallet-client-sdk";
|
|
@@ -22,72 +18,7 @@ const unWallet = await UnWallet.init({
|
|
|
22
18
|
});
|
|
23
19
|
```
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```js
|
|
28
|
-
unWallet.authorize({
|
|
29
|
-
redirectURL: "http://your.app.com/callback",
|
|
30
|
-
nonce: "pdITKAtep0pfPOrUXdzjqW6gKvXezurJ", // arbitrary string to prevent replay attacks
|
|
31
|
-
});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Requesting a signature for a message
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
const sig = await unWallet.sign({
|
|
38
|
-
message: "ARBITRARY_MESSAGE",
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
#### Example return value
|
|
43
|
-
|
|
44
|
-
```json
|
|
45
|
-
{
|
|
46
|
-
"digest": "0xc71ed5b0509d8da72abc9527ed72530743822e8d9b33f9695b42e20ece78c09b",
|
|
47
|
-
"signature": "0xd94388b5d51395c46b00f6197de318ba275cd7f9c5e4dccf2059373a4b41b3975403852e2587f262375e6d2b3318380dcd95535ecebec7e8c7ebbbefdcf22a371b"
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Requesting a signature for a transaction
|
|
52
|
-
|
|
53
|
-
```js
|
|
54
|
-
const metaTx = await unWallet.signTransaction({
|
|
55
|
-
to: "0xB481148EB6A5f6b5b9Cc10cb0C8304B9B179A8e6", // the address the transaction is directed to
|
|
56
|
-
value: "0x0", // the MATIC value sent with this transaction (optional)
|
|
57
|
-
data: "0x...", // the hash of the invoked method signature and encoded parameters (optional)
|
|
58
|
-
});
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
#### Example return value
|
|
62
|
-
|
|
63
|
-
```json
|
|
64
|
-
{
|
|
65
|
-
"executor": "0x3ADBDCBa56d70Fc15Dcbe98901432cC07B2aAaeF",
|
|
66
|
-
"data": "0x...",
|
|
67
|
-
"signature": "0x19eb83842bc2d2c55567d4da63981ae9d4ce76ec567b591f18e18f4e030c4389331ba3ce0f1549331cb51710881320982b7b7a3632a7d81ca214690ecf3267c51c"
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
To execute the transaction, call [POST /metaTransactions of unWallet Enterprise API](https://developers.ent.unwallet.world/ja/latest/unwallet-ent-api.html#post-metatransactions).
|
|
72
|
-
|
|
73
|
-
### Requesting a signature for a token transfer transaction
|
|
74
|
-
|
|
75
|
-
```js
|
|
76
|
-
const metaTx = await unWallet.signTokenTransfer({
|
|
77
|
-
id: 101, // token ID
|
|
78
|
-
to: "0xB481148EB6A5f6b5b9Cc10cb0C8304B9B179A8e6", // destination address
|
|
79
|
-
amount: 1, // token amount
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
#### Example return value
|
|
84
|
-
|
|
85
|
-
```json
|
|
86
|
-
{
|
|
87
|
-
"executor": "0x3ADBDCBa56d70Fc15Dcbe98901432cC07B2aAaeF",
|
|
88
|
-
"data": "0x...",
|
|
89
|
-
"signature": "0x19eb83842bc2d2c55567d4da63981ae9d4ce76ec567b591f18e18f4e030c4389331ba3ce0f1549331cb51710881320982b7b7a3632a7d81ca214690ecf3267c51c"
|
|
90
|
-
}
|
|
91
|
-
```
|
|
21
|
+
## Functions
|
|
92
22
|
|
|
93
|
-
|
|
23
|
+
- [For all developers](docs/functions-1.md)
|
|
24
|
+
- [For web3 developers](docs/functions-2.md)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Functions (for all developers)
|
|
2
|
+
|
|
3
|
+
> **Note**\
|
|
4
|
+
> To execute the sample codes below, you need to create an application with unWallet Enterprise in advance.
|
|
5
|
+
|
|
6
|
+
## authorize
|
|
7
|
+
|
|
8
|
+
`authorize` requests a user's ID token in accordance with OpenID Connect (response_type: id_token).
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
unWallet.authorize({
|
|
12
|
+
redirectURL: "http://your.app.com/callback",
|
|
13
|
+
nonce: "pdITKAtep0pfPOrUXdzjqW6gKvXezurJ", // arbitrary string to prevent replay attacks
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## sign
|
|
18
|
+
|
|
19
|
+
`sign` requests a signature for a message.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const sig = await unWallet.sign({
|
|
23
|
+
message: "ARBITRARY_MESSAGE",
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Example return value
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"digest": "0xc71ed5b0509d8da72abc9527ed72530743822e8d9b33f9695b42e20ece78c09b",
|
|
32
|
+
"signature": "0xd94388b5d51395c46b00f6197de318ba275cd7f9c5e4dccf2059373a4b41b3975403852e2587f262375e6d2b3318380dcd95535ecebec7e8c7ebbbefdcf22a371b"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### How to verify a signature
|
|
37
|
+
|
|
38
|
+
See also [ERC1271](https://eips.ethereum.org/EIPS/eip-1271).
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const ethers = require("ethers");
|
|
42
|
+
|
|
43
|
+
(async () => {
|
|
44
|
+
const contract = new ethers.Contract(
|
|
45
|
+
"<CONTRACT_WALLET_ADDRESS>",
|
|
46
|
+
[
|
|
47
|
+
{
|
|
48
|
+
inputs: [
|
|
49
|
+
{
|
|
50
|
+
internalType: "bytes32",
|
|
51
|
+
name: "hash",
|
|
52
|
+
type: "bytes32",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
internalType: "bytes",
|
|
56
|
+
name: "signature",
|
|
57
|
+
type: "bytes",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
name: "isValidSignature",
|
|
61
|
+
outputs: [
|
|
62
|
+
{
|
|
63
|
+
internalType: "bytes4",
|
|
64
|
+
name: "",
|
|
65
|
+
type: "bytes4",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
stateMutability: "view",
|
|
69
|
+
type: "function",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
new ethers.providers.JsonRpcProvider("<YOUR_RPC_URL>")
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
await contract.isValidSignature("<DIGEST>", "<SIGNATURE>");
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.log("invalid");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
console.log("valid");
|
|
83
|
+
})();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## signTokenTransfer
|
|
87
|
+
|
|
88
|
+
`signTokenTransfer` requests a signature for a token transfer transaction.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
const metaTx = await unWallet.signTokenTransfer({
|
|
92
|
+
id: 101, // token ID
|
|
93
|
+
to: "0xB481148EB6A5f6b5b9Cc10cb0C8304B9B179A8e6", // destination address
|
|
94
|
+
amount: 1, // token amount
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Example return value
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"executor": "0x3ADBDCBa56d70Fc15Dcbe98901432cC07B2aAaeF",
|
|
103
|
+
"data": "0x...",
|
|
104
|
+
"signature": "0x19eb83842bc2d2c55567d4da63981ae9d4ce76ec567b591f18e18f4e030c4389331ba3ce0f1549331cb51710881320982b7b7a3632a7d81ca214690ecf3267c51c"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
To execute the transaction, call [POST /metaTransactions of unWallet Enterprise API](https://developers.ent.unwallet.world/ja/latest/unwallet-ent-api.html#post-metatransactions).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Functions (for web3 developers)
|
|
2
|
+
|
|
3
|
+
Use the following functions only if you want to work with your own contracts.
|
|
4
|
+
|
|
5
|
+
> **Note**\
|
|
6
|
+
> To execute the sample codes below, you need to create an application with unWallet Enterprise in advance.
|
|
7
|
+
|
|
8
|
+
## signTransaction
|
|
9
|
+
|
|
10
|
+
`signTransaction` requests a signature for a transaction.
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
const metaTx = await unWallet.signTransaction({
|
|
14
|
+
to: "0xB481148EB6A5f6b5b9Cc10cb0C8304B9B179A8e6", // the address the transaction is directed to
|
|
15
|
+
value: "0x0", // the MATIC value sent with this transaction (optional)
|
|
16
|
+
data: "0x...", // the hash of the invoked method signature and encoded parameters (optional)
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
:warning: You cannot specify parameters related to gas here because the gas consumed by the meta transaction is paid by the provider wallet.
|
|
21
|
+
|
|
22
|
+
### Example return value
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"executor": "0x3ADBDCBa56d70Fc15Dcbe98901432cC07B2aAaeF",
|
|
27
|
+
"data": "0x...",
|
|
28
|
+
"signature": "0x19eb83842bc2d2c55567d4da63981ae9d4ce76ec567b591f18e18f4e030c4389331ba3ce0f1549331cb51710881320982b7b7a3632a7d81ca214690ecf3267c51c"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To execute the transaction, call [POST /metaTransactions of unWallet Enterprise API](https://developers.ent.unwallet.world/ja/latest/unwallet-ent-api.html#post-metatransactions).
|