1
1
import Image from "next/image" ;
2
2
import styles from "./index.module.css" ;
3
3
import { useTurnkey } from "@turnkey/sdk-react" ;
4
+ import { Turnkey as TurnkeySDKClient } from "@turnkey/sdk-server" ;
4
5
import { useForm } from "react-hook-form" ;
5
6
import axios from "axios" ;
6
7
import * as React from "react" ;
7
8
import { useState } from "react" ;
8
-
9
9
/**
10
10
* Type definition for the server response coming back from `/api/auth`
11
11
*/
@@ -54,20 +54,24 @@ export default function AuthPage() {
54
54
} ;
55
55
56
56
const injectCredentials = async ( data : InjectCredentialsFormData ) => {
57
+ console . log ( "injecting" ) ;
58
+
57
59
if ( authIframeClient === null ) {
58
60
throw new Error ( "iframe client is null" ) ;
59
61
}
60
62
if ( authResponse === null ) {
61
63
throw new Error ( "authResponse is null" ) ;
62
64
}
63
65
try {
66
+ console . log ( "before inject" ) ;
64
67
await authIframeClient ! . injectCredentialBundle ( data . authBundle ) ;
65
68
} catch ( e ) {
66
69
const msg = `error while injecting bundle: ${ e } ` ;
67
70
console . error ( msg ) ;
68
71
alert ( msg ) ;
69
72
return ;
70
73
}
74
+ console . log ( "outside" ) ;
71
75
72
76
// get whoami for suborg
73
77
const whoamiResponse = await authIframeClient ! . getWhoami ( {
@@ -76,22 +80,60 @@ export default function AuthPage() {
76
80
77
81
const orgID = whoamiResponse . organizationId ;
78
82
79
- const createWalletResponse = await authIframeClient ! . createWallet ( {
80
- organizationId : orgID ,
81
- walletName : data . walletName ,
82
- accounts : [
83
- {
84
- curve : "CURVE_SECP256K1" ,
85
- pathFormat : "PATH_FORMAT_BIP32" ,
86
- path : "m/44'/60'/0'/0/0" ,
87
- addressFormat : "ADDRESS_FORMAT_ETHEREUM" ,
88
- } ,
89
- ] ,
90
- } ) ;
83
+ console . log ( "whoami?" , whoamiResponse ) ;
91
84
92
- const address = refineNonNull ( createWalletResponse . addresses [ 0 ] ) ;
85
+ function createRandomString ( length : number ) : string {
86
+ const chars =
87
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
88
+ let result = "" ;
89
+ for ( let i = 0 ; i < length ; i ++ ) {
90
+ result += chars . charAt ( Math . floor ( Math . random ( ) * chars . length ) ) ;
91
+ }
92
+ return result ;
93
+ }
93
94
94
- alert ( `SUCCESS! Wallet and new address created: ${ address } ` ) ;
95
+ const start = new Date ( ) . getTime ( ) ;
96
+
97
+ let signingPromises = [ ] ;
98
+ for ( let i = 0 ; i < 100 ; i ++ ) {
99
+ signingPromises . push (
100
+ authIframeClient ! . signRawPayload ( {
101
+ signWith : "0xc95B01326731D17972a4845458fc954f2aD37E8e" ,
102
+ payload : createRandomString ( 20 ) ,
103
+ encoding : "PAYLOAD_ENCODING_TEXT_UTF8" ,
104
+ hashFunction : "HASH_FUNCTION_SHA256" ,
105
+ } )
106
+ ) ;
107
+ }
108
+
109
+ // This is the step which waits on all signing promises to complete
110
+ const signatures = await Promise . allSettled ( signingPromises ) ;
111
+
112
+ const end = new Date ( ) . getTime ( ) ;
113
+
114
+ console . log ( "signatures" , signatures ) ;
115
+ console . log ( {
116
+ start,
117
+ end,
118
+ diff : end - start ,
119
+ } ) ;
120
+
121
+ // const createWalletResponse = await authIframeClient!.createWallet({
122
+ // organizationId: orgID,
123
+ // walletName: data.walletName,
124
+ // accounts: [
125
+ // {
126
+ // curve: "CURVE_SECP256K1",
127
+ // pathFormat: "PATH_FORMAT_BIP32",
128
+ // path: "m/44'/60'/0'/0/0",
129
+ // addressFormat: "ADDRESS_FORMAT_ETHEREUM",
130
+ // },
131
+ // ],
132
+ // });
133
+
134
+ // const address = refineNonNull(createWalletResponse.addresses[0]);
135
+
136
+ // alert(`SUCCESS! Wallet and new address created: ${address} `);
95
137
} ;
96
138
97
139
return (
@@ -116,7 +158,10 @@ export default function AuthPage() {
116
158
{ authIframeClient &&
117
159
authIframeClient . iframePublicKey &&
118
160
authResponse === null && (
119
- < form className = { styles . form } onSubmit = { authFormSubmit ( auth ) } >
161
+ < form
162
+ className = { styles . form }
163
+ onSubmit = { authFormSubmit ( auth ) }
164
+ >
120
165
< label className = { styles . label } >
121
166
Email
122
167
< input
@@ -150,7 +195,11 @@ export default function AuthPage() {
150
195
</ code >
151
196
</ label >
152
197
153
- < input className = { styles . button } type = "submit" value = "Auth" />
198
+ < input
199
+ className = { styles . button }
200
+ type = "submit"
201
+ value = "Auth"
202
+ />
154
203
</ form >
155
204
) }
156
205
0 commit comments