1
- import { describeLitentry , generateVerificationMessage , getMessage } from "./utils" ;
2
- import { hexToU8a , u8aToHex } from "@polkadot/util" ;
1
+ import {
2
+ describeLitentry ,
3
+ generateVerificationMessage ,
4
+ getMessage ,
5
+ listenEncryptedEvents ,
6
+ } from "./utils" ;
7
+ import { hexToU8a , u8aToHex , stringToU8a } from "@polkadot/util" ;
3
8
import {
4
9
createIdentity ,
5
10
setUserShieldingKey ,
@@ -10,6 +15,9 @@ import { step } from "mocha-steps";
10
15
import { assert } from "chai" ;
11
16
import { LitentryIdentity , LitentryValidationData } from "./type-definitions" ;
12
17
import { Sign } from "./web3/functions" ;
18
+ import { generateTestKeys } from "./web3/functions" ;
19
+ import { ethers } from "ethers" ;
20
+ import { HexString } from "@polkadot/util/types" ;
13
21
const twitterIdentity = < LitentryIdentity > {
14
22
handle : {
15
23
PlainString : `0x${ Buffer . from ( "mock_user" , "utf8" ) . toString ( "hex" ) } ` ,
@@ -19,6 +27,27 @@ const twitterIdentity = <LitentryIdentity>{
19
27
} ,
20
28
} ;
21
29
30
+ const ethereumIdentity = < LitentryIdentity > {
31
+ handle : {
32
+ Address20 : `0xff93B45308FD417dF303D6515aB04D9e89a750Ca` ,
33
+ } ,
34
+ web_type : {
35
+ Web3Identity : {
36
+ Evm : "Ethereum" ,
37
+ } ,
38
+ } ,
39
+ } ;
40
+
41
+ const substrateIdentity = < LitentryIdentity > {
42
+ handle : {
43
+ Address32 : `0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d` , //alice
44
+ } ,
45
+ web_type : {
46
+ Web3Identity : {
47
+ Substrate : "Litentry" ,
48
+ } ,
49
+ } ,
50
+ } ;
22
51
const twitterValidationData = < LitentryValidationData > {
23
52
Web2Validation : {
24
53
Twitter : {
@@ -27,6 +56,32 @@ const twitterValidationData = <LitentryValidationData>{
27
56
} ,
28
57
} ;
29
58
59
+ const ethereumValidationData = < LitentryValidationData > {
60
+ Web3Validation : {
61
+ Evm : {
62
+ message : `0x${ Buffer . from ( "mock_message" , "utf8" ) . toString ( "hex" ) } ` ,
63
+ signature : {
64
+ Ethereum : `0x${ Buffer . from (
65
+ "10ee76e356d944d17bce552a4fd0d4554ccc97dc81213f470367bd3b99c441c51" ,
66
+ "utf8"
67
+ ) . toString ( "hex" ) } `,
68
+ } ,
69
+ } ,
70
+ } ,
71
+ } ;
72
+ const substrateValidationData = < LitentryValidationData > {
73
+ Web3Validation : {
74
+ Substrate : {
75
+ message : `0x${ Buffer . from ( "mock_message" , "utf8" ) . toString ( "hex" ) } ` ,
76
+ signature : {
77
+ Sr25519 : `0x${ Buffer . from (
78
+ "10ee76e356d944d17bce552a4fd0d4554ccc97dc81213f470367bd3b99c441c51" ,
79
+ "utf8"
80
+ ) . toString ( "hex" ) } `,
81
+ } ,
82
+ } ,
83
+ } ,
84
+ } ;
30
85
const discordIdentity = < LitentryIdentity > {
31
86
handle : {
32
87
PlainString : `0x${ Buffer . from ( "859641379851337798" , "utf8" ) . toString ( "hex" ) } ` ,
@@ -48,21 +103,26 @@ const discordValidationData = <LitentryValidationData>{
48
103
49
104
describeLitentry ( "Test Identity" , ( context ) => {
50
105
const aesKey = "0x22fc82db5b606998ad45099b7978b5b4f9dd4ea6017e57370ac56141caaabd12" ;
106
+ var signature_ethereum ;
107
+ var signature_substrate ;
51
108
52
109
step ( "set user shielding key" , async function ( ) {
53
- //get signature
54
- // const message = getMessage(context.defaultSigner.address, "polkadot-js");
55
- // const signature = await Sign(message, context.defaultSigner);
56
-
57
110
const who = await setUserShieldingKey ( context , context . defaultSigner , aesKey , true ) ;
58
111
assert . equal ( who , u8aToHex ( context . defaultSigner . addressRaw ) , "check caller error" ) ;
59
112
} ) ;
60
113
61
- step ( "create twitter identity" , async function ( ) {
62
- const r = await createIdentity ( context , context . defaultSigner , aesKey , true , twitterIdentity ) ;
63
- if ( r ) {
64
- const [ _who , challengeCode ] = r ;
65
- console . log ( "challengeCode: " , challengeCode ) ;
114
+ step ( "create identity" , async function ( ) {
115
+ //create twitter identity
116
+ const resp_twitter = await createIdentity (
117
+ context ,
118
+ context . defaultSigner ,
119
+ aesKey ,
120
+ true ,
121
+ twitterIdentity
122
+ ) ;
123
+ if ( resp_twitter ) {
124
+ const [ _who , challengeCode ] = resp_twitter ;
125
+ console . log ( "twitterIdentity challengeCode: " , challengeCode ) ;
66
126
const msg = generateVerificationMessage (
67
127
context ,
68
128
hexToU8a ( challengeCode ) ,
@@ -72,28 +132,133 @@ describeLitentry("Test Identity", (context) => {
72
132
console . log ( "post verification msg to twitter: " , msg ) ;
73
133
assert . isNotEmpty ( challengeCode , "challengeCode empty" ) ;
74
134
}
135
+ //create ethereum identity
136
+ const resp_ethereum = await createIdentity (
137
+ context ,
138
+ context . defaultSigner ,
139
+ aesKey ,
140
+ true ,
141
+ ethereumIdentity
142
+ ) ;
143
+ if ( resp_ethereum ) {
144
+ const [ _who , challengeCode ] = resp_ethereum ;
145
+ console . log ( "ethereumIdentity challengeCode: " , challengeCode ) ;
146
+ const msg = generateVerificationMessage (
147
+ context ,
148
+ hexToU8a ( challengeCode ) ,
149
+ context . defaultSigner . addressRaw ,
150
+ ethereumIdentity
151
+ ) ;
152
+ console . log ( "post verification msg to ethereum: " , msg ) ;
153
+ ethereumValidationData ! . Web3Validation ! . Evm ! . message = msg ;
154
+ const msgHash = ethers . utils . arrayify ( msg ) ;
155
+ signature_ethereum = await context . ethersWallet . alice . signMessage ( msgHash ) ;
156
+ ethereumValidationData ! . Web3Validation ! . Evm ! . signature ! . Ethereum = signature_ethereum ;
157
+ assert . isNotEmpty ( challengeCode , "challengeCode empty" ) ;
158
+ }
159
+ // create substrate identity
160
+ const resp_substrate = await createIdentity (
161
+ context ,
162
+ context . defaultSigner ,
163
+ aesKey ,
164
+ true ,
165
+ substrateIdentity
166
+ ) ;
167
+ if ( resp_substrate ) {
168
+ const [ _who , challengeCode ] = resp_substrate ;
169
+ console . log ( "substrateIdentity challengeCode: " , challengeCode ) ;
170
+ const msg = generateVerificationMessage (
171
+ context ,
172
+ hexToU8a ( challengeCode ) ,
173
+ context . defaultSigner . addressRaw ,
174
+ substrateIdentity
175
+ ) ;
176
+
177
+ console . log ( "post verification msg to substrate: " , msg ) ;
178
+ substrateValidationData ! . Web3Validation ! . Substrate ! . message = msg ;
179
+ signature_substrate = context . defaultSigner . sign ( msg ) ;
180
+ substrateValidationData ! . Web3Validation ! . Substrate ! . signature ! . Sr25519 =
181
+ u8aToHex ( signature_substrate ) ;
182
+ assert . isNotEmpty ( challengeCode , "challengeCode empty" ) ;
183
+ }
75
184
} ) ;
76
185
77
- step ( "verify twitter identity" , async function ( ) {
78
- const who = await verifyIdentity (
186
+ step ( "verify identity" , async function ( ) {
187
+ //verify twitter identity
188
+ const who_twitter = await verifyIdentity (
79
189
context ,
80
190
context . defaultSigner ,
81
191
aesKey ,
82
192
true ,
83
193
twitterIdentity ,
84
194
twitterValidationData
85
195
) ;
196
+ assert . equal ( who_twitter , u8aToHex ( context . defaultSigner . addressRaw ) , "check caller error" ) ;
197
+
198
+ // verify ethereum identity
199
+ const who_ethereum = await verifyIdentity (
200
+ context ,
201
+ context . defaultSigner ,
202
+ aesKey ,
203
+ true ,
204
+ ethereumIdentity ,
205
+ ethereumValidationData
206
+ ) ;
207
+ assert . equal (
208
+ who_ethereum ,
209
+ u8aToHex ( context . defaultSigner . addressRaw ) ,
210
+ "check caller error"
211
+ ) ;
212
+
213
+ //verify substrate identity
214
+ const who = await verifyIdentity (
215
+ context ,
216
+ context . defaultSigner ,
217
+ aesKey ,
218
+ true ,
219
+ substrateIdentity ,
220
+ substrateValidationData
221
+ ) ;
86
222
assert . equal ( who , u8aToHex ( context . defaultSigner . addressRaw ) , "check caller error" ) ;
87
223
} ) ;
88
224
89
225
step ( "remove identity" , async function ( ) {
90
- const who = await removeIdentity (
226
+ //remove twitter identity
227
+ const who_twitter = await removeIdentity (
91
228
context ,
92
229
context . defaultSigner ,
93
230
aesKey ,
94
231
true ,
95
232
twitterIdentity
96
233
) ;
97
- assert . equal ( who , u8aToHex ( context . defaultSigner . addressRaw ) , "check caller error" ) ;
234
+ assert . equal ( who_twitter , u8aToHex ( context . defaultSigner . addressRaw ) , "check caller error" ) ;
235
+
236
+ //remove ethereum identity
237
+ const who_ethereum = await removeIdentity (
238
+ context ,
239
+ context . defaultSigner ,
240
+ aesKey ,
241
+ true ,
242
+ ethereumIdentity
243
+ ) ;
244
+ assert . equal (
245
+ who_ethereum ,
246
+ u8aToHex ( context . defaultSigner . addressRaw ) ,
247
+ "check caller error"
248
+ ) ;
249
+
250
+ //remove substrate identity
251
+ const who_substrate = await removeIdentity (
252
+ context ,
253
+ context . defaultSigner ,
254
+ aesKey ,
255
+ true ,
256
+ substrateIdentity
257
+ ) ;
258
+ assert . equal (
259
+ who_substrate ,
260
+ u8aToHex ( context . defaultSigner . addressRaw ) ,
261
+ "check caller error"
262
+ ) ;
98
263
} ) ;
99
264
} ) ;
0 commit comments