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
10
+ const turnkeyClient = new TurnkeySDKClient ( {
11
+ apiBaseUrl : process . env . NEXT_PUBLIC_BASE_URL ! ,
12
+ apiPublicKey : "03eba1c0dbc9720b3b6fe9bdc49f1eef35c82b3b0d4f3dc44b930756634232c3f7" ,
13
+ apiPrivateKey : "572a8911461934cc7d8d0f78f3c7c7d08d4e46ceda915ee35463edcc6a8c8e65" ,
14
+ defaultOrganizationId : process . env . NEXT_PUBLIC_ORGANIZATION_ID ! ,
15
+ } ) ;
16
+
9
17
/**
10
18
* Type definition for the server response coming back from `/api/auth`
11
19
*/
@@ -76,22 +84,60 @@ export default function AuthPage() {
76
84
77
85
const orgID = whoamiResponse . organizationId ;
78
86
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
- } ) ;
87
+ console . log ( "whoami?" , whoamiResponse ) ;
88
+
89
+ function createRandomString ( length : number ) : string {
90
+ const chars =
91
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
92
+ let result = "" ;
93
+ for ( let i = 0 ; i < length ; i ++ ) {
94
+ result += chars . charAt ( Math . floor ( Math . random ( ) * chars . length ) ) ;
95
+ }
96
+ return result ;
97
+ }
98
+
99
+ const start = new Date ( ) . getTime ( ) ;
100
+
101
+ let signingPromises = [ ] ;
102
+ for ( let i = 0 ; i < 100 ; i ++ ) {
103
+ signingPromises . push (
104
+ turnkeyClient . apiClient ( ) ! . signRawPayload ( {
105
+ signWith : "0xc95B01326731D17972a4845458fc954f2aD37E8e" ,
106
+ payload : createRandomString ( 20 ) ,
107
+ encoding : "PAYLOAD_ENCODING_TEXT_UTF8" ,
108
+ hashFunction : "HASH_FUNCTION_SHA256" ,
109
+ } )
110
+ ) ;
111
+ }
112
+
113
+ // This is the step which waits on all signing promises to complete
114
+ const signatures = await Promise . allSettled ( signingPromises ) ;
115
+
116
+ const end = new Date ( ) . getTime ( ) ;
91
117
92
- const address = refineNonNull ( createWalletResponse . addresses [ 0 ] ) ;
118
+ console . log ( "signatures" , signatures ) ;
119
+ console . log ( {
120
+ start,
121
+ end,
122
+ diff : end - start ,
123
+ } ) ;
93
124
94
- alert ( `SUCCESS! Wallet and new address created: ${ address } ` ) ;
125
+ // const createWalletResponse = await authIframeClient!.createWallet({
126
+ // organizationId: orgID,
127
+ // walletName: data.walletName,
128
+ // accounts: [
129
+ // {
130
+ // curve: "CURVE_SECP256K1",
131
+ // pathFormat: "PATH_FORMAT_BIP32",
132
+ // path: "m/44'/60'/0'/0/0",
133
+ // addressFormat: "ADDRESS_FORMAT_ETHEREUM",
134
+ // },
135
+ // ],
136
+ // });
137
+
138
+ // const address = refineNonNull(createWalletResponse.addresses[0]);
139
+
140
+ // alert(`SUCCESS! Wallet and new address created: ${address} `);
95
141
} ;
96
142
97
143
return (
@@ -116,7 +162,10 @@ export default function AuthPage() {
116
162
{ authIframeClient &&
117
163
authIframeClient . iframePublicKey &&
118
164
authResponse === null && (
119
- < form className = { styles . form } onSubmit = { authFormSubmit ( auth ) } >
165
+ < form
166
+ className = { styles . form }
167
+ onSubmit = { authFormSubmit ( auth ) }
168
+ >
120
169
< label className = { styles . label } >
121
170
Email
122
171
< input
@@ -150,7 +199,11 @@ export default function AuthPage() {
150
199
</ code >
151
200
</ label >
152
201
153
- < input className = { styles . button } type = "submit" value = "Auth" />
202
+ < input
203
+ className = { styles . button }
204
+ type = "submit"
205
+ value = "Auth"
206
+ />
154
207
</ form >
155
208
) }
156
209
0 commit comments