-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
100 lines (95 loc) · 2.97 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, {useState} from 'react';
import {SafeAreaView, StyleSheet, TouchableOpacity, Text} from 'react-native';
import {
Passkeys,
connect,
signMessage,
signTransaction,
} from '@passkeys/react-native';
export default function App() {
const [_, setAddresses] = useState();
const [credentialId, setCredentialId] = useState();
return (
<SafeAreaView style={styles.container}>
{!credentialId && (
<TouchableOpacity
onPress={async () => {
try {
const {addresses, credentialId: id} = await connect();
setAddresses(addresses);
setCredentialId(id);
console.log('addresses', addresses);
} catch (error) {
console.error(error);
}
}}>
<Text>Connect</Text>
</TouchableOpacity>
)}
{credentialId && (
<TouchableOpacity
onPress={async () => {
try {
const signedMessageResponse = await signMessage({
message: {
rawMessage: Buffer.from('Hello World!'),
},
baseAssetName: 'ethereum',
credentialId,
metadata: {title: 'Sign Message'},
});
console.log('signedMessageResponse', signedMessageResponse);
} catch (error) {
console.error(error);
}
}}>
<Text>Sign Message</Text>
</TouchableOpacity>
)}
{credentialId && (
<TouchableOpacity
onPress={async () => {
try {
const signTransactionResponse = await signTransaction({
transaction: {
txData: {
transactionBuffer: Buffer.from(
'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDlQMu5tnOGTuT6craZOCkndrjA9o2EJb1rBw/ohlcpypy8Z7Z8rsF8SRaO8FE7vKMoIjCMnrsYrINFR5JNNf2tAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCppgV9A6KWVpt6hEMng2GqzikT9gsGmsvUzYWZIQ6KoPcBAgMBAQAJA0BCDwAAAAAA',
'base64',
),
},
txMeta: Object.create(null),
},
baseAssetName: 'solana',
credentialId,
metadata: {title: 'Sign Transaction'},
});
console.log('signTransactionResponse', signTransactionResponse);
} catch (error) {
console.error(error);
}
}}>
<Text>Sign Transaction</Text>
</TouchableOpacity>
)}
<Passkeys appId="test" url="https://relay-d.passkeys.network" style={styles.passkeys} />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: '100%',
height: '100%',
marginVertical: 20,
},
passkeys: {
width: 1,
height: 1,
opacity: 0,
},
});