@dynamic-labs/solana-extension 3.0.0-alpha.14

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dynamic Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # solana-extension
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ npm install @dynamic-labs/solana-extension
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```tsx
12
+ import { SolanaExtension } from '@dynamic-labs/solana-extension'
13
+ import { createClient } from '@dynamic-labs/client'
14
+ import { Connection } from '@solana/web3.js'
15
+
16
+ const dynamicClient = createClient({...}).extend(SolanaExtension())
17
+
18
+ const connection: Connection = dynamicClient.solana.getConnection();
19
+
20
+ const signer = dynamicClient.solana.getSigner({
21
+ wallet: dynamicClient.wallets.primary,
22
+ });
23
+
24
+ const signedMessage = await signer.signMessage(
25
+ new TextEncoder().encode('hello')
26
+ )
27
+ ```
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@dynamic-labs/solana-extension",
3
+ "version": "3.0.0-alpha.14",
4
+ "main": "./src/index.cjs",
5
+ "module": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.d.ts",
11
+ "import": "./src/index.js",
12
+ "require": "./src/index.cjs"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "dependencies": {
17
+ "@dynamic-labs/message-transport": "3.0.0-alpha.14"
18
+ },
19
+ "peerDependencies": {
20
+ "@solana/web3.js": "1.92.1",
21
+ "@dynamic-labs/client": "3.0.0-alpha.14",
22
+ "@dynamic-labs/solana-utils": "3.0.0-alpha.14",
23
+ "@dynamic-labs/types": "3.0.0-alpha.14"
24
+ }
25
+ }
package/src/index.cjs ADDED
@@ -0,0 +1,11 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var SolanaExtension = require('./lib/SolanaExtension.cjs');
7
+
8
+
9
+
10
+ exports.SolanaExtension = SolanaExtension.SolanaExtension;
11
+ exports.solanaExtensionName = SolanaExtension.solanaExtensionName;
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { SolanaExtension, solanaExtensionName, type ISolanaExtension, } from './lib/SolanaExtension';
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use client'
2
+ export { SolanaExtension, solanaExtensionName } from './lib/SolanaExtension.js';
@@ -0,0 +1,21 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var createConnection = require('./createConnection/createConnection.cjs');
7
+ var createSigner = require('./createSigner/createSigner.cjs');
8
+
9
+ const solanaExtensionName = 'solana';
10
+ const SolanaExtension = () => (client, core) => {
11
+ core.declaredExtensionNames.push(solanaExtensionName);
12
+ return {
13
+ solana: {
14
+ getConnection: () => createConnection.createConnection(client, core),
15
+ getSigner: ({ wallet }) => createSigner.createSigner({ core, wallet }),
16
+ },
17
+ };
18
+ };
19
+
20
+ exports.SolanaExtension = SolanaExtension;
21
+ exports.solanaExtensionName = solanaExtensionName;
@@ -0,0 +1,13 @@
1
+ import { Connection } from '@solana/web3.js';
2
+ import { type Extension, type Wallet } from '@dynamic-labs/client';
3
+ import { ISolanaSigner } from './types';
4
+ export declare const solanaExtensionName = "solana";
5
+ export type ISolanaExtension = {
6
+ solana: {
7
+ getConnection: () => Connection;
8
+ getSigner: (props: {
9
+ wallet: Wallet;
10
+ }) => ISolanaSigner;
11
+ };
12
+ };
13
+ export declare const SolanaExtension: () => Extension<ISolanaExtension>;
@@ -0,0 +1,16 @@
1
+ 'use client'
2
+ import { createConnection } from './createConnection/createConnection.js';
3
+ import { createSigner } from './createSigner/createSigner.js';
4
+
5
+ const solanaExtensionName = 'solana';
6
+ const SolanaExtension = () => (client, core) => {
7
+ core.declaredExtensionNames.push(solanaExtensionName);
8
+ return {
9
+ solana: {
10
+ getConnection: () => createConnection(client, core),
11
+ getSigner: ({ wallet }) => createSigner({ core, wallet }),
12
+ },
13
+ };
14
+ };
15
+
16
+ export { SolanaExtension, solanaExtensionName };
@@ -0,0 +1,20 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var web3_js = require('@solana/web3.js');
7
+ var client = require('@dynamic-labs/client');
8
+
9
+ const createConnection = (client$1, core) => {
10
+ if (!client.hasExtension(client$1, core, client.baseClientExtensionName)) {
11
+ throw new Error('Client does not have a network configuration');
12
+ }
13
+ const [rpcEndpoint] = client$1.networks.solana.map((network) => { var _a; return ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0]; });
14
+ if (!rpcEndpoint) {
15
+ throw new Error('Client does not have a network configuration');
16
+ }
17
+ return new web3_js.Connection(rpcEndpoint);
18
+ };
19
+
20
+ exports.createConnection = createConnection;
@@ -0,0 +1,3 @@
1
+ import { Connection } from '@solana/web3.js';
2
+ import { Extendable, Core } from '@dynamic-labs/client';
3
+ export declare const createConnection: (client: Extendable, core: Core) => Connection;
@@ -0,0 +1,16 @@
1
+ 'use client'
2
+ import { Connection } from '@solana/web3.js';
3
+ import { hasExtension, baseClientExtensionName } from '@dynamic-labs/client';
4
+
5
+ const createConnection = (client, core) => {
6
+ if (!hasExtension(client, core, baseClientExtensionName)) {
7
+ throw new Error('Client does not have a network configuration');
8
+ }
9
+ const [rpcEndpoint] = client.networks.solana.map((network) => { var _a; return ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0]; });
10
+ if (!rpcEndpoint) {
11
+ throw new Error('Client does not have a network configuration');
12
+ }
13
+ return new Connection(rpcEndpoint);
14
+ };
15
+
16
+ export { createConnection };
@@ -0,0 +1 @@
1
+ export { createConnection } from './createConnection';
@@ -0,0 +1,42 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var web3_js = require('@solana/web3.js');
7
+ var messageTransport = require('@dynamic-labs/message-transport');
8
+ var solanaUtils = require('@dynamic-labs/solana-utils');
9
+
10
+ const createSigner = ({ wallet, core, }) => {
11
+ const solanaRequestChannel = messageTransport.createRequestChannel(core.messageTransport);
12
+ return {
13
+ publicKey: new web3_js.PublicKey(wallet.address),
14
+ signAllTransactions: (transactions) => solanaRequestChannel
15
+ .request('solana_signAllTransactions', {
16
+ encodedTransactions: transactions.map(solanaUtils.encodeTransactionToBase64),
17
+ walletId: wallet.id,
18
+ })
19
+ .then(({ encodedTransactions }) => encodedTransactions.map(solanaUtils.decodeTransactionFromBase64)),
20
+ signAndSendTransaction: (transaction, options) => solanaRequestChannel.request('solana_signAndSendTransaction', {
21
+ encodedTransaction: solanaUtils.encodeTransactionToBase64(transaction),
22
+ options,
23
+ walletId: wallet.id,
24
+ }),
25
+ signMessage: (message) => solanaRequestChannel
26
+ .request('solana_signMessage', {
27
+ message: new TextDecoder().decode(message),
28
+ walletId: wallet.id,
29
+ })
30
+ .then(({ signature }) => ({
31
+ signature: new TextEncoder().encode(signature),
32
+ })),
33
+ signTransaction: (transaction) => solanaRequestChannel
34
+ .request('solana_signTransaction', {
35
+ encodedTransaction: solanaUtils.encodeTransactionToBase64(transaction),
36
+ walletId: wallet.id,
37
+ })
38
+ .then(({ encodedTransaction }) => solanaUtils.decodeTransactionFromBase64(encodedTransaction)),
39
+ };
40
+ };
41
+
42
+ exports.createSigner = createSigner;
@@ -0,0 +1,8 @@
1
+ import { Wallet, Core } from '@dynamic-labs/client';
2
+ import { ISolanaSigner } from '../types';
3
+ type CreateSignerProps = {
4
+ wallet: Wallet;
5
+ core: Core;
6
+ };
7
+ export declare const createSigner: ({ wallet, core, }: CreateSignerProps) => ISolanaSigner;
8
+ export {};
@@ -0,0 +1,38 @@
1
+ 'use client'
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { createRequestChannel } from '@dynamic-labs/message-transport';
4
+ import { encodeTransactionToBase64, decodeTransactionFromBase64 } from '@dynamic-labs/solana-utils';
5
+
6
+ const createSigner = ({ wallet, core, }) => {
7
+ const solanaRequestChannel = createRequestChannel(core.messageTransport);
8
+ return {
9
+ publicKey: new PublicKey(wallet.address),
10
+ signAllTransactions: (transactions) => solanaRequestChannel
11
+ .request('solana_signAllTransactions', {
12
+ encodedTransactions: transactions.map(encodeTransactionToBase64),
13
+ walletId: wallet.id,
14
+ })
15
+ .then(({ encodedTransactions }) => encodedTransactions.map(decodeTransactionFromBase64)),
16
+ signAndSendTransaction: (transaction, options) => solanaRequestChannel.request('solana_signAndSendTransaction', {
17
+ encodedTransaction: encodeTransactionToBase64(transaction),
18
+ options,
19
+ walletId: wallet.id,
20
+ }),
21
+ signMessage: (message) => solanaRequestChannel
22
+ .request('solana_signMessage', {
23
+ message: new TextDecoder().decode(message),
24
+ walletId: wallet.id,
25
+ })
26
+ .then(({ signature }) => ({
27
+ signature: new TextEncoder().encode(signature),
28
+ })),
29
+ signTransaction: (transaction) => solanaRequestChannel
30
+ .request('solana_signTransaction', {
31
+ encodedTransaction: encodeTransactionToBase64(transaction),
32
+ walletId: wallet.id,
33
+ })
34
+ .then(({ encodedTransaction }) => decodeTransactionFromBase64(encodedTransaction)),
35
+ };
36
+ };
37
+
38
+ export { createSigner };
@@ -0,0 +1 @@
1
+ export { createSigner } from './createSigner';
@@ -0,0 +1,13 @@
1
+ import { PublicKey, SendOptions, Transaction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
2
+ export type SignedMessage = {
3
+ signature: Uint8Array;
4
+ };
5
+ export type ISolanaSigner = {
6
+ publicKey: PublicKey;
7
+ signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
8
+ signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
9
+ signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<{
10
+ signature: TransactionSignature;
11
+ }>;
12
+ signMessage(message: Uint8Array, encoding?: string): Promise<SignedMessage>;
13
+ };