@verified-network/verified-custody 0.2.0 → 0.2.2

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 ADDED
@@ -0,0 +1,437 @@
1
+ # Verified Custody
2
+
3
+ Verified Custody is a react submodule for Custody of digital assets. This react module allows users to create blockchain wallets where private keys are sharded and stored on the blockchain itself in encrypted form. Users do not have to remember mnemonics or back up private keys. Verified Custody requires co-signers to be added by a wallet user and co-signers can be requested to re-generate the sharded and stored keys.
4
+
5
+ ### Installation:
6
+
7
+ ```
8
+ npm install @verified-network/verified-custody
9
+ ```
10
+
11
+ ```jsx
12
+ import React from "react";
13
+
14
+ import { VerifiedCustody } from "@verified-network/verified-custody";
15
+
16
+ function App() {
17
+ return (
18
+ <div>
19
+ <VerifiedCustody />
20
+ </div>
21
+ );
22
+ }
23
+ ```
24
+
25
+ ### Build:
26
+
27
+ - This module is built with typescript and work for both javascript and typescript react/vite projects.
28
+ - All the components of the module is compiled and available under the dist/ directory.
29
+
30
+ The react module exports react components and helper functions which will be useful when changing UI based on a user's state or any business logic
31
+
32
+ \***\*< VerifiedCustody />\*\*** component is the completed workflow of the custody module, it handles full workflow for new and existing users in steps; it consists of:
33
+
34
+ # First Time Users
35
+
36
+ \***\*< FTUPage />\*\*** component which handles full workflow for First Time Users. This consists of:
37
+
38
+ \***\*< ContactPage />\*\*** component which is the starting point for all users, where they are required to input their phone number or email. And they receive an OTP(one time password).
39
+
40
+ \***\*< OTPPage />\*\*** component which is where new/existing users verify and resend OTP.
41
+
42
+ \***\*< CreatePinPage />\*\*** component which is where all users either;
43
+
44
+ 1. create 4 digit pin to secure their account.
45
+ 2. Input their existing pin and get redirected to another page.
46
+ In this component new users accounts are created as they had verified their Phone number/Email from previous components.
47
+
48
+ \***\*< AddCoSignersPage />\*\*** component which is where all new users gets to add coSigners to their account and decide the rule of signing. Users can add up to 5 Co-signers with 2 as minimum required signers.
49
+
50
+ # Returning Users
51
+
52
+ \***\*< EnterPinPage />\*\*** component which is where existing/returning users gets to input their account pin to perform various actions like;
53
+
54
+ 1. connect their account/wallet to an application.
55
+ 2. Accept/Reject Co-signers invitation.
56
+ 3. Recover their lost account/wallet keys
57
+ 4. Sign account recovery transaction for users
58
+ 5. Sign regular transactions. e.t.c
59
+
60
+ ## Usage:
61
+
62
+ Note: To implement this module in your project there are some important component props required.
63
+
64
+ # Components Props Type:
65
+
66
+ ```jsx
67
+ export interface VerifiedCustodyProps {
68
+ action?: VerifiedWalletAction;
69
+ actionText?: string;
70
+ origin?: string;
71
+ title?: string;
72
+ chainId?: number;
73
+ vaultData?: VerifiedWalletVault;
74
+ txData?: VerifiedWalletTx;
75
+ reqVaultData?: VerifiedWalletVault;
76
+ delayPageElement?: React.JSX.Element;
77
+ delayPageStyle?: React.CSSProperties;
78
+ helperFunctions?: VerifiedCustodyHelpers;
79
+ }
80
+
81
+ export type VerifiedWalletAction =
82
+ | "connect_wallet"
83
+ | "getPk"
84
+ | "invitation"
85
+ | "signRecovery"
86
+ | "completeRecovery";
87
+
88
+ export type VerifiedWalletVault = {
89
+ vaultId: string,
90
+ hashedVaultId?: string,
91
+ hashedVaultPin?: string,
92
+ CoSignerId?: string,
93
+ vId?: string,
94
+ vPh?: string,
95
+ cId?: string,
96
+ address?: string,
97
+ channel?: "sms" | "email",
98
+ pk?: string,
99
+ };
100
+
101
+ export type VerifiedWalletTx = {
102
+ id: string,
103
+ };
104
+
105
+ export interface VerifiedCustodyHelpers {
106
+ sendCoSignerInvitation: (
107
+ channel: "sms" | "email",
108
+ cosigerId: string,
109
+ cretorId: string,
110
+ hashedCretorPin: string
111
+ ) => Promise<boolean>;
112
+
113
+ sendCreatorConfirmation: (
114
+ channel: "sms" | "email",
115
+ cretorId: string,
116
+ cosigersList: [],
117
+ requiredSigners: number
118
+ ) => Promise<boolean>;
119
+
120
+ sendCreatorInitiation: (
121
+ channel: "sms" | "email",
122
+ cretorId: string,
123
+ hashedCretorPin: string,
124
+ txId: number,
125
+ requiredSigners: number
126
+ ) => Promise<boolean>;
127
+
128
+ sendCreatorSigned: (
129
+ channel: "sms" | "email",
130
+ cretorId: string,
131
+ coSignerId: string
132
+ ) => Promise<boolean>;
133
+
134
+ sendCreatorCompleted: (
135
+ channel: "sms" | "email",
136
+ cretorId: string,
137
+ txId: number
138
+ ) => Promise<boolean>;
139
+
140
+ sendCreatorAcceptance: (
141
+ channel: "sms" | "email",
142
+ creatorId: string,
143
+ coSignerId: string
144
+ ) => Promise<boolean>;
145
+
146
+ sendCreatorRejection: (
147
+ channel: "sms" | "email",
148
+ creatorId: string,
149
+ coSignerId: string
150
+ ) => Promise<boolean>;
151
+ }
152
+ ```
153
+
154
+ 1. action: which can be either "connect_wallet" or "getPk" or "invitation" or "signRecovery" or "completeRecovery". if action is not passed in the props it will create account for new users or login for an existing users.
155
+ 2. helperFunctions:
156
+ For Example: sendCoSignerInvitation: this is required to send messages to cosigners using their email or phone number. it must take 4 parameters: ` jsx
157
+ channel: "sms" | "email",
158
+ cosigerId: string, //email or phone number of the cosigner added. note: phone number must be ``+${countryPhoneCode}${10DigitsPhoneNumber} `` for example: +10987654321 where 1 is the countryCode and 0987654321 is the phone number.
159
+ cretorId: string, //email or phone number of the account creator. note: phone number must be ``+${countryPhoneCode}${10DigitsPhoneNumber} `` for example: +10987654321 where 1 is the countryCode and 0987654321 is the phone number.
160
+ hashedCretorPin: string `
161
+ and return `true or false` true when message sends without error and false incase of any error.
162
+
163
+ Check the code Below for better explaination of how all helper functions work.
164
+
165
+ ### Full workflow with one component(handle First time users, existing user and all type of actions)
166
+
167
+ ```jsx
168
+ import React from 'react';
169
+
170
+ import { VerifiedCustody} from '@verified-network/verified-custody';
171
+
172
+ function App(){
173
+
174
+ const myCustomSendCoSignerInvitation = async(
175
+ channel: "sms" | "email",
176
+ cosigerId: string,
177
+ cretorId: string,
178
+ hashedCretorPin: string
179
+ ) => Promise<boolean> {
180
+ try {
181
+ //sends email/messages depending on the channel
182
+ if(channel === "sms") {
183
+ //send message to cosigerId phone number using creatorId and hashedCretorPin in message
184
+ return true
185
+ }else if(channel === "email") {
186
+ //send message to cosigerId email using creatorId and hashedCretorPin in message
187
+ return true
188
+ }else {
189
+ return false
190
+ }
191
+ }catch(err) {
192
+ //handles error
193
+ return false
194
+ }
195
+ }
196
+
197
+ const myCustomSendCreatorConfirmation = async(
198
+ channel: "sms" | "email",
199
+ cretorId: string,
200
+ cosigersList: [],
201
+ requiredSigners: number
202
+ ) => Promise<boolean> {
203
+ try {
204
+ //sends email/messages depending on the channel
205
+ if(channel === "sms") {
206
+ //send message to cretorId phone number showing creator his coSigners list and rule of signer using requiredSigners and totalNumber of coSignersList
207
+ return true
208
+ }else if(channel === "email") {
209
+ //send message to cretorId email showing creator his coSigners list and rule of signer using requiredSigners and totalNumber of coSignersList
210
+ return true
211
+ }else {
212
+ return false
213
+ }
214
+ }catch(err) {
215
+ //handles error
216
+ return false
217
+ }
218
+ }
219
+
220
+ // no action/ create account for new user or login existing user.
221
+ return (
222
+ <div>
223
+ <VerifiedCustody helperFunctions={
224
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
225
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
226
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
227
+ sendCreatorSigned: myCustomSendCreatorSigned,
228
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
229
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
230
+ sendCreatorRejection: myCustomSendCreatorRejection
231
+ } />
232
+ </div>
233
+ );
234
+
235
+ // connect existing user account
236
+ return (
237
+ <div>
238
+ <VerifiedCustody action="connect_wallet" actionText="CustomActionTextToDisplay like: Connect Your Account" origin="websiteToConnectToUrl" title="websiteToConnectToTitle" helperFunctions={
239
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
240
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
241
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
242
+ sendCreatorSigned: myCustomSendCreatorSigned,
243
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
244
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
245
+ sendCreatorRejection: myCustomSendCreatorRejection
246
+ } />
247
+ </div>
248
+ );
249
+
250
+ //accept or reject coSigner invitation
251
+ return (
252
+ <div>
253
+ <VerifiedCustody action="invitation" origin="websiteUrl" title="websiteTitle" helperFunctions={
254
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
255
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
256
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
257
+ sendCreatorSigned: myCustomSendCreatorSigned,
258
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
259
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
260
+ sendCreatorRejection: myCustomSendCreatorRejection
261
+ } />
262
+ </div>
263
+ );
264
+
265
+ //sign account recovery for an existing account as their cosigner
266
+ return (
267
+ <div>
268
+ <VerifiedCustody action="signRecovery" origin="websiteUrl" title="websiteTitle" helperFunctions={
269
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
270
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
271
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
272
+ sendCreatorSigned: myCustomSendCreatorSigned,
273
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
274
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
275
+ sendCreatorRejection: myCustomSendCreatorRejection
276
+ } />
277
+ </div>
278
+ );
279
+
280
+ //complete account recovery for an existing account
281
+ return (
282
+ <div>
283
+ <VerifiedCustody action="completeRecovery" origin="websiteUrl" title="websiteTitle" helperFunctions={
284
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
285
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
286
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
287
+ sendCreatorSigned: myCustomSendCreatorSigned,
288
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
289
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
290
+ sendCreatorRejection: myCustomSendCreatorRejection
291
+ } />
292
+ </div>
293
+ );
294
+ }
295
+ ```
296
+
297
+ ### First time users
298
+
299
+ ```jsx
300
+ import React from 'react';
301
+
302
+ import { FTUPage} from '@verified-network/verified-custody';
303
+
304
+ function App(){
305
+
306
+ const myCustomSendCoSignerInvitation = async(
307
+ channel: "sms" | "email",
308
+ cosigerId: string,
309
+ cretorId: string,
310
+ hashedCretorPin: string
311
+ ) => Promise<boolean> {
312
+ try {
313
+ //sends email/messages depending on the channel
314
+ if(channel === "sms") {
315
+ //send message to cosigerId phone number using creatorId and hashedCretorPin in message
316
+ return true
317
+ }else if(channel === "email") {
318
+ //send message to cosigerId email using creatorId and hashedCretorPin in message
319
+ return true
320
+ }else {
321
+ return false
322
+ }
323
+ }catch(err) {
324
+ //handles error
325
+ return false
326
+ }
327
+ }
328
+
329
+ const myCustomSendCreatorConfirmation = async(
330
+ channel: "sms" | "email",
331
+ cretorId: string,
332
+ cosigersList: [],
333
+ requiredSigners: number
334
+ ) => Promise<boolean> {
335
+ try {
336
+ //sends email/messages depending on the channel
337
+ if(channel === "sms") {
338
+ //send message to cretorId phone number showing creator his coSigners list and rule of signer using requiredSigners and totalNumber of coSignersList
339
+ return true
340
+ }else if(channel === "email") {
341
+ //send message to cretorId email showing creator his coSigners list and rule of signer using requiredSigners and totalNumber of coSignersList
342
+ return true
343
+ }else {
344
+ return false
345
+ }
346
+ }catch(err) {
347
+ //handles error
348
+ return false
349
+ }
350
+ }
351
+
352
+ return (
353
+ <div>
354
+ <FTUPage helperFunctions={
355
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
356
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
357
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
358
+ sendCreatorSigned: myCustomSendCreatorSigned,
359
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
360
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
361
+ sendCreatorRejection: myCustomSendCreatorRejection
362
+ } />
363
+ </div>
364
+ );
365
+ }
366
+ ```
367
+
368
+ ### Existing/Returning Users
369
+
370
+ ```jsx
371
+ import React from 'react';
372
+
373
+ import { EnterPinPage} from '@verified-network/verified-custody';
374
+
375
+ function App(){
376
+
377
+ const myCustomSendCoSignerInvitation = async(
378
+ channel: "sms" | "email",
379
+ cosigerId: string,
380
+ cretorId: string,
381
+ hashedCretorPin: string
382
+ ) => Promise<boolean> {
383
+ try {
384
+ //sends email/messages depending on the channel
385
+ if(channel === "sms") {
386
+ //send message to cosigerId phone number using creatorId and hashedCretorPin in message
387
+ return true
388
+ }else if(channel === "email") {
389
+ //send message to cosigerId email using creatorId and hashedCretorPin in message
390
+ return true
391
+ }else {
392
+ return false
393
+ }
394
+ }catch(err) {
395
+ //handles error
396
+ return false
397
+ }
398
+ }
399
+
400
+ const myCustomSendCreatorConfirmation = async(
401
+ channel: "sms" | "email",
402
+ cretorId: string,
403
+ cosigersList: [],
404
+ requiredSigners: number
405
+ ) => Promise<boolean> {
406
+ try {
407
+ //sends email/messages depending on the channel
408
+ if(channel === "sms") {
409
+ //send message to cretorId phone number showing creator his coSigners list and rule of signer using requiredSigners and totalNumber of coSignersList
410
+ return true
411
+ }else if(channel === "email") {
412
+ //send message to cretorId email showing creator his coSigners list and rule of signer using requiredSigners and totalNumber of coSignersList
413
+ return true
414
+ }else {
415
+ return false
416
+ }
417
+ }catch(err) {
418
+ //handles error
419
+ return false
420
+ }
421
+ }
422
+
423
+ return (
424
+ <div>
425
+ <EnterPinPage helperFunctions={
426
+ sendCoSignerInvitation: myCustomSendCoSignerInvitation,
427
+ sendCreatorConfirmation: myCustomSendCreatorConfirmation,
428
+ sendCreatorInitiation: myCustomsendCreatorInitiation,
429
+ sendCreatorSigned: myCustomSendCreatorSigned,
430
+ sendCreatorCompleted: myCustomSendCreatorCompleted,
431
+ sendCreatorAcceptance: myCustomSendCreatorAcceptance,
432
+ sendCreatorRejection: myCustomSendCreatorRejection
433
+ } />
434
+ </div>
435
+ );
436
+ }
437
+ ```
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import React$1 from 'react';
2
2
 
3
- type VerifiedWalletAction = "connect_wallet" | "getPk" | "invitation" | "signRecovery" | "completeRecovery";
3
+ type VerifiedWalletAction = "connect_wallet" | "getPk" | "invitation" | "signRecovery" | "completeRecovery" | null;
4
4
  type VerifiedWalletVault = {
5
5
  vaultId: string;
6
6
  hashedVaultId?: string;
7
7
  hashedVaultPin?: string;
8
- CoSignerId?: string;
8
+ coSignerId?: string;
9
9
  vId?: string;
10
10
  vPh?: string;
11
11
  cId?: string;
@@ -28,6 +28,15 @@ interface VerifiedCustodyProps {
28
28
  delayPageElement?: React.JSX.Element;
29
29
  delayPageStyle?: React.CSSProperties;
30
30
  helperFunctions?: VerifiedCustodyHelpers;
31
+ popupView?: boolean;
32
+ defaultCountry?: {
33
+ area: string;
34
+ flag: string;
35
+ name: string;
36
+ };
37
+ showLogoPage?: boolean;
38
+ logoPageElement?: React.JSX.Element;
39
+ logoTimeoutTime?: number;
31
40
  }
32
41
  interface VerifiedCustodyHelpers {
33
42
  sendCoSignerInvitation: (channel: "sms" | "email", cosigerId: string, cretorId: string, hashedCretorPin: string) => Promise<boolean>;
@@ -60,6 +69,7 @@ declare const FTUPage: (props: {
60
69
  startupPageElement?: React$1.JSX.Element;
61
70
  setisOnboard?: (isOnboard: boolean) => void;
62
71
  helperFunctions?: VerifiedCustodyHelpers;
72
+ setIsLoading?: (isLoading: boolean) => void;
63
73
  }) => React$1.JSX.Element;
64
74
 
65
75
  declare const EnterPinPage: (props: {
@@ -162,4 +172,4 @@ declare const hashTheString: (text: string) => string;
162
172
  declare const encryptString: (text: string, secretKey: string) => string;
163
173
  declare const decryptString: (encryptedText: string, secretKey: string) => string;
164
174
 
165
- export { AddCosignersPage as AddCoSignersPage, ContactPage, CreatePinPage, EnterPinPage, FTUPage, OTPPage, VerifiedCustody, decryptString, encryptString, hashTheString };
175
+ export { AddCosignersPage as AddCoSignersPage, ContactPage, CreatePinPage, EnterPinPage, FTUPage, OTPPage, VerifiedCustody, type VerifiedCustodyHelpers, type VerifiedCustodyProps, type VerifiedWalletAction, type VerifiedWalletTx, type VerifiedWalletVault, decryptString, encryptString, hashTheString };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import React$1 from 'react';
2
2
 
3
- type VerifiedWalletAction = "connect_wallet" | "getPk" | "invitation" | "signRecovery" | "completeRecovery";
3
+ type VerifiedWalletAction = "connect_wallet" | "getPk" | "invitation" | "signRecovery" | "completeRecovery" | null;
4
4
  type VerifiedWalletVault = {
5
5
  vaultId: string;
6
6
  hashedVaultId?: string;
7
7
  hashedVaultPin?: string;
8
- CoSignerId?: string;
8
+ coSignerId?: string;
9
9
  vId?: string;
10
10
  vPh?: string;
11
11
  cId?: string;
@@ -28,6 +28,15 @@ interface VerifiedCustodyProps {
28
28
  delayPageElement?: React.JSX.Element;
29
29
  delayPageStyle?: React.CSSProperties;
30
30
  helperFunctions?: VerifiedCustodyHelpers;
31
+ popupView?: boolean;
32
+ defaultCountry?: {
33
+ area: string;
34
+ flag: string;
35
+ name: string;
36
+ };
37
+ showLogoPage?: boolean;
38
+ logoPageElement?: React.JSX.Element;
39
+ logoTimeoutTime?: number;
31
40
  }
32
41
  interface VerifiedCustodyHelpers {
33
42
  sendCoSignerInvitation: (channel: "sms" | "email", cosigerId: string, cretorId: string, hashedCretorPin: string) => Promise<boolean>;
@@ -60,6 +69,7 @@ declare const FTUPage: (props: {
60
69
  startupPageElement?: React$1.JSX.Element;
61
70
  setisOnboard?: (isOnboard: boolean) => void;
62
71
  helperFunctions?: VerifiedCustodyHelpers;
72
+ setIsLoading?: (isLoading: boolean) => void;
63
73
  }) => React$1.JSX.Element;
64
74
 
65
75
  declare const EnterPinPage: (props: {
@@ -162,4 +172,4 @@ declare const hashTheString: (text: string) => string;
162
172
  declare const encryptString: (text: string, secretKey: string) => string;
163
173
  declare const decryptString: (encryptedText: string, secretKey: string) => string;
164
174
 
165
- export { AddCosignersPage as AddCoSignersPage, ContactPage, CreatePinPage, EnterPinPage, FTUPage, OTPPage, VerifiedCustody, decryptString, encryptString, hashTheString };
175
+ export { AddCosignersPage as AddCoSignersPage, ContactPage, CreatePinPage, EnterPinPage, FTUPage, OTPPage, VerifiedCustody, type VerifiedCustodyHelpers, type VerifiedCustodyProps, type VerifiedWalletAction, type VerifiedWalletTx, type VerifiedWalletVault, decryptString, encryptString, hashTheString };