Skip to content

Commit c1cb353

Browse files
committed
feature: sign message
1 parent b00ff30 commit c1cb353

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed

README.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ yarn add @dialectlabs/blinks @dialectlabs/blinks-react-native
1515
## Adding the Blink Component
1616

1717
The following imports need to be made to simplify the blink integration:
18-
- `useAction` hook and `ActionAdapter` type from `@dialectlabs/blinks-core`
18+
- `useAction` hook and `ActionAdapter` type from `@dialectlabs/blinks-react-native`
1919
- `Blink` component from `@dialectlabs/blinks-react-native`
2020

2121
A `getWalletAdapter` function has to be defined to generate an adapter of type `ActionAdapter` for interactions with user wallets like wallet connect and signing transactions through the React Native dApp.
@@ -33,52 +33,59 @@ An [example](/example/src/Example.tsx) of this is:
3333
Blink,
3434
BlockchainIds,
3535
useAction,
36+
createSignMessageText,
3637
type ActionAdapter,
3738
} from '@dialectlabs/blinks-react-native';
3839
import { PublicKey } from '@solana/web3.js';
3940
import type React from 'react';
4041

4142
function getWalletAdapter(): ActionAdapter {
42-
return {
43+
return {
4344
connect: async (_context) => {
44-
console.log('connect');
45-
return PublicKey.default.toString();
45+
console.log('connect');
46+
return PublicKey.default.toString();
4647
},
4748
signTransaction: async (_tx, _context) => {
48-
console.log('signTransaction');
49-
return {
49+
console.log('signTransaction');
50+
return {
5051
signature: 'signature',
51-
};
52+
};
5253
},
5354
confirmTransaction: async (_signature, _context) => {
54-
console.log('confirmTransaction');
55+
console.log('confirmTransaction');
56+
},
57+
signMessage: async (message: string | SignMessageData, _context) => {
58+
const messageToSign =
59+
typeof message === 'string' ? message : createSignMessageText(message);
60+
console.log('signMessage', messageToSign);
61+
return { signature: 'signature' };
5562
},
5663
metadata: { supportedBlockchainIds: [BlockchainIds.SOLANA_MAINNET] },
57-
};
64+
};
5865
}
5966

6067
export const BlinkInTheWalletIntegrationExample: React.FC<{
61-
url: string; // could be action api or website url
68+
url: string; // could be action api or website url
6269
}> = ({ url }) => {
63-
const adapter = getWalletAdapter();
64-
const { action } = useAction({ url, adapter });
70+
const adapter = getWalletAdapter();
71+
const { action } = useAction({ url, adapter });
6572

66-
if (!action) {
73+
if (!action) {
6774
// return placeholder component
68-
}
69-
const actionUrl = new URL(url);
70-
return (
71-
<Blink
72-
theme={{
73-
'--blink-button': '#1D9BF0',
74-
'--blink-border-radius-rounded-button': 9999,
75-
// and any other custom styles
76-
}}
77-
action={action}
78-
websiteUrl={actionUrl.href}
79-
websiteText={actionUrl.hostname}
80-
/>
81-
);
75+
}
76+
const actionUrl = new URL(url);
77+
return (
78+
<Blink
79+
theme={{
80+
'--blink-button': '#1D9BF0',
81+
'--blink-border-radius-rounded-button': 9999,
82+
// and any other custom styles
83+
}}
84+
action={action}
85+
websiteUrl={actionUrl.href}
86+
websiteText={actionUrl.hostname}
87+
/>
88+
);
8289
};
8390
```
8491

example/src/Example.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
Blink,
33
BlockchainIds,
4+
createSignMessageText,
45
Miniblink,
56
useAction,
67
type ActionAdapter,
8+
type SignMessageData,
79
} from '@dialectlabs/blinks-react-native';
810
import { PublicKey } from '@solana/web3.js';
911
import type React from 'react';
@@ -21,6 +23,12 @@ function getWalletAdapter(): ActionAdapter {
2123
signature: 'signature',
2224
};
2325
},
26+
signMessage: async (message: string | SignMessageData, _context) => {
27+
const messageToSign =
28+
typeof message === 'string' ? message : createSignMessageText(message);
29+
console.log('signMessage', messageToSign);
30+
return { signature: 'signature' };
31+
},
2432
confirmTransaction: async (_signature, _context) => {
2533
console.log('confirmTransaction');
2634
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"devDependencies": {
6363
"@react-native/eslint-config": "^0.74.85",
64-
"@solana/actions-spec": "~2.3.0",
64+
"@solana/actions-spec": "~2.4.0",
6565
"@types/jest": "^29.5.5",
6666
"@types/react": "^18.2.44",
6767
"del-cli": "^5.1.0",
@@ -153,7 +153,7 @@
153153
"version": "0.38.2"
154154
},
155155
"dependencies": {
156-
"@dialectlabs/blinks-core": "^0.12.1",
156+
"@dialectlabs/blinks-core": "^0.13.1",
157157
"@react-native-community/datetimepicker": "^8.2.0",
158158
"@react-native-picker/picker": "^2.7.7",
159159
"@shopify/restyle": "^2.4.4",

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,15 +1764,15 @@ __metadata:
17641764
languageName: node
17651765
linkType: hard
17661766

1767-
"@dialectlabs/blinks-core@npm:^0.12.1":
1768-
version: 0.12.1
1769-
resolution: "@dialectlabs/blinks-core@npm:0.12.1"
1767+
"@dialectlabs/blinks-core@npm:^0.13.1":
1768+
version: 0.13.1
1769+
resolution: "@dialectlabs/blinks-core@npm:0.13.1"
17701770
dependencies:
17711771
"@solana/web3.js": ^1.95.1
17721772
nanoid: ^5.0.7
17731773
peerDependencies:
17741774
react: ">=18"
1775-
checksum: 298c88d3ad3c73ac99f1b263c1b5be59f88174bc3563e72f08ac22a01caebad07d2490fac2bb6b6125617c64cd6450326a480b14e861e2b1827a1bf1ee041022
1775+
checksum: fb2b1d062c688089f8f51a683b3e152cd40926145715338449b35fd72631f68797967c60c54bc1d31b78aff701c6a44105300201eaf42c5885981923b7fc1c54
17761776
languageName: node
17771777
linkType: hard
17781778

@@ -1798,12 +1798,12 @@ __metadata:
17981798
version: 0.0.0-use.local
17991799
resolution: "@dialectlabs/blinks-react-native@workspace:."
18001800
dependencies:
1801-
"@dialectlabs/blinks-core": ^0.12.1
1801+
"@dialectlabs/blinks-core": ^0.13.1
18021802
"@react-native-community/datetimepicker": ^8.2.0
18031803
"@react-native-picker/picker": ^2.7.7
18041804
"@react-native/eslint-config": ^0.74.85
18051805
"@shopify/restyle": ^2.4.4
1806-
"@solana/actions-spec": ~2.3.0
1806+
"@solana/actions-spec": ~2.4.0
18071807
"@types/jest": ^29.5.5
18081808
"@types/react": ^18.2.44
18091809
del-cli: ^5.1.0
@@ -3450,10 +3450,10 @@ __metadata:
34503450
languageName: node
34513451
linkType: hard
34523452

3453-
"@solana/actions-spec@npm:~2.3.0":
3454-
version: 2.3.0
3455-
resolution: "@solana/actions-spec@npm:2.3.0"
3456-
checksum: e2a32a2932f404331a9f5336cc2c45fa2ce0c6ed6c5ae31f8c3e6568dcc845a2d3af412ae5cb5d1ba77cd0268ef68773dc3d2444a34b1ebee7c23fca99457e2b
3453+
"@solana/actions-spec@npm:~2.4.0":
3454+
version: 2.4.1
3455+
resolution: "@solana/actions-spec@npm:2.4.1"
3456+
checksum: 18ebf8f622a7d96601da448dab94f54bd01cf0fb00436b2408148a927e27d5b1224230bb1d5fcc86c1b7a0e3c902e46c861ebe58512c100864d3a4714125e75e
34573457
languageName: node
34583458
linkType: hard
34593459

0 commit comments

Comments
 (0)