@shelby-protocol/solana-kit 0.0.4 → 0.1.0
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/dist/node/index.cjs +91 -29
- package/dist/node/index.d.cts +11 -10
- package/dist/node/index.d.ts +11 -10
- package/dist/node/index.mjs +94 -32
- package/dist/react/index.d.ts +86 -0
- package/dist/react/index.mjs +180 -0
- package/package.json +15 -5
package/dist/node/index.cjs
CHANGED
|
@@ -1,34 +1,107 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/node/index.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/node/index.ts
|
|
2
|
+
var _node = require('@shelby-protocol/sdk/node'); _createStarExport(_node);
|
|
3
|
+
|
|
4
|
+
// src/common/constants.ts
|
|
2
5
|
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
6
|
+
var AUTH_FUNCTION = "0x1::solana_derivable_account::authenticate";
|
|
7
|
+
var Network = {
|
|
8
|
+
SHELBYNET: _tssdk.Network.SHELBYNET
|
|
9
|
+
};
|
|
3
10
|
|
|
4
|
-
// src/
|
|
5
|
-
var
|
|
11
|
+
// src/common/deriveAddress.ts
|
|
12
|
+
var _derivedwalletsolana = require('@aptos-labs/derived-wallet-solana');
|
|
13
|
+
|
|
14
|
+
// src/common/signTransaction.ts
|
|
15
|
+
var _derivedwalletbase = require('@aptos-labs/derived-wallet-base');
|
|
6
16
|
|
|
7
17
|
|
|
8
|
-
var _node = require('@shelby-protocol/sdk/node');
|
|
9
18
|
|
|
10
|
-
// src/node/storageAccount.ts
|
|
11
19
|
|
|
12
20
|
|
|
13
21
|
|
|
14
22
|
|
|
15
|
-
var _derivedwalletsolana = require('@aptos-labs/derived-wallet-solana');
|
|
16
23
|
|
|
17
24
|
|
|
18
25
|
|
|
19
26
|
var _walletstandardutil = require('@solana/wallet-standard-util');
|
|
27
|
+
|
|
28
|
+
// src/common/transactionStatement.ts
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
function createTransactionStatement(rawTransaction, domain) {
|
|
34
|
+
const entryFunctionName = _derivedwalletbase.getEntryFunctionName.call(void 0,
|
|
35
|
+
rawTransaction.rawTransaction.payload
|
|
36
|
+
);
|
|
37
|
+
const humanReadableEntryFunction = entryFunctionName ? ` ${entryFunctionName}` : "";
|
|
38
|
+
const chainId = rawTransaction.rawTransaction.chain_id.chainId;
|
|
39
|
+
const chainName = _derivedwalletbase.getChainName.call(void 0, chainId);
|
|
40
|
+
const onAptosChain = ` on Aptos blockchain (${chainName})`;
|
|
41
|
+
return `Please confirm you explicitly initiated this request from ${domain}. You are approving to execute transaction${humanReadableEntryFunction}${onAptosChain}.`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/common/signTransaction.ts
|
|
45
|
+
function createSiwsMessage(transaction, solanaAddress, domain) {
|
|
46
|
+
const signingMessage = _tssdk.generateSigningMessageForTransaction.call(void 0, transaction);
|
|
47
|
+
const aaMessage = _tssdk.AbstractedAccount.generateAccountAbstractionMessage(
|
|
48
|
+
signingMessage,
|
|
49
|
+
AUTH_FUNCTION
|
|
50
|
+
);
|
|
51
|
+
const signingMessageDigest = _tssdk.hashValues.call(void 0, [aaMessage]);
|
|
52
|
+
const siwsInput = {
|
|
53
|
+
address: solanaAddress,
|
|
54
|
+
domain,
|
|
55
|
+
nonce: _tssdk.Hex.fromHexInput(signingMessageDigest).toString(),
|
|
56
|
+
statement: createTransactionStatement(transaction, domain)
|
|
57
|
+
};
|
|
58
|
+
const messageToSign = _walletstandardutil.createSignInMessage.call(void 0, siwsInput);
|
|
59
|
+
return {
|
|
60
|
+
messageToSign,
|
|
61
|
+
signingMessageDigest
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function createAuthenticator(signatureBytes, solanaAddress, domain, signingMessageDigest) {
|
|
65
|
+
const signature = new (0, _tssdk.Ed25519Signature)(signatureBytes);
|
|
66
|
+
const serializer = new (0, _tssdk.Serializer)();
|
|
67
|
+
serializer.serializeU8(_derivedwalletsolana.SIGNATURE_TYPE);
|
|
68
|
+
serializer.serializeBytes(signature.toUint8Array());
|
|
69
|
+
const abstractSignature = serializer.toUint8Array();
|
|
70
|
+
const abstractPublicKey = new (0, _derivedwalletbase.DerivableAbstractPublicKey)(
|
|
71
|
+
solanaAddress,
|
|
72
|
+
domain
|
|
73
|
+
);
|
|
74
|
+
return new (0, _tssdk.AccountAuthenticatorAbstraction)(
|
|
75
|
+
AUTH_FUNCTION,
|
|
76
|
+
signingMessageDigest,
|
|
77
|
+
abstractSignature,
|
|
78
|
+
abstractPublicKey.bcsToBytes()
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/node/shelby.ts
|
|
83
|
+
var _gasstationclient = require('@aptos-labs/gas-station-client');
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
// src/node/storageAccount.ts
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
20
93
|
var _tweetnacl = require('tweetnacl'); var _tweetnacl2 = _interopRequireDefault(_tweetnacl);
|
|
21
94
|
var ShelbyStorageAccount = class extends _tssdk.AbstractedAccount {
|
|
22
95
|
constructor(params) {
|
|
23
|
-
const { solanaKeypair, domain
|
|
96
|
+
const { solanaKeypair, domain } = params;
|
|
24
97
|
const derivedPublicKey = new (0, _derivedwalletsolana.SolanaDerivedPublicKey)({
|
|
25
98
|
domain,
|
|
26
99
|
solanaPublicKey: solanaKeypair.publicKey,
|
|
27
|
-
authenticationFunction
|
|
100
|
+
authenticationFunction: AUTH_FUNCTION
|
|
28
101
|
});
|
|
29
102
|
super({
|
|
30
103
|
accountAddress: derivedPublicKey.authKey().derivedAddress(),
|
|
31
|
-
authenticationFunction,
|
|
104
|
+
authenticationFunction: AUTH_FUNCTION,
|
|
32
105
|
signer: (digest) => {
|
|
33
106
|
return _tweetnacl2.default.sign.detached(
|
|
34
107
|
digest,
|
|
@@ -44,22 +117,20 @@ var ShelbyStorageAccount = class extends _tssdk.AbstractedAccount {
|
|
|
44
117
|
* Override the transaction signing to use SIWS envelope format
|
|
45
118
|
*/
|
|
46
119
|
signTransactionWithAuthenticator(transaction) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const messageToSign = _walletstandardutil.createSignInMessage.call(void 0, siwsInput);
|
|
120
|
+
const solanaAddress = this.solanaKeypair.publicKey.toBase58();
|
|
121
|
+
const { messageToSign, signingMessageDigest } = createSiwsMessage(
|
|
122
|
+
transaction,
|
|
123
|
+
solanaAddress,
|
|
124
|
+
this.domain
|
|
125
|
+
);
|
|
54
126
|
const signatureBytes = _tweetnacl2.default.sign.detached(
|
|
55
127
|
messageToSign,
|
|
56
128
|
this.solanaKeypair.secretKey
|
|
57
129
|
);
|
|
58
|
-
return
|
|
130
|
+
return createAuthenticator(
|
|
59
131
|
signatureBytes,
|
|
60
|
-
|
|
132
|
+
solanaAddress,
|
|
61
133
|
this.domain,
|
|
62
|
-
this.authenticationFunction,
|
|
63
134
|
signingMessageDigest
|
|
64
135
|
);
|
|
65
136
|
}
|
|
@@ -98,19 +169,10 @@ var Shelby = class extends _node.ShelbyClient {
|
|
|
98
169
|
* ```
|
|
99
170
|
*/
|
|
100
171
|
createStorageAccount(solanaKeypair, domain) {
|
|
101
|
-
return new ShelbyStorageAccount({
|
|
102
|
-
solanaKeypair,
|
|
103
|
-
domain,
|
|
104
|
-
authenticationFunction: "0x1::solana_derivable_account::authenticate"
|
|
105
|
-
});
|
|
172
|
+
return new ShelbyStorageAccount({ solanaKeypair, domain });
|
|
106
173
|
}
|
|
107
174
|
};
|
|
108
175
|
|
|
109
|
-
// src/node/index.ts
|
|
110
|
-
var Network = {
|
|
111
|
-
SHELBYNET: _tssdk.Network.SHELBYNET
|
|
112
|
-
};
|
|
113
|
-
|
|
114
176
|
|
|
115
177
|
|
|
116
178
|
exports.Network = Network; exports.Shelby = Shelby;
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import { AbstractedAccount, AnyRawTransaction, AccountAuthenticatorAbstraction, Network as Network$1 } from '@aptos-labs/ts-sdk';
|
|
2
1
|
import { ShelbyNetwork, ShelbyClient } from '@shelby-protocol/sdk/node';
|
|
2
|
+
export * from '@shelby-protocol/sdk/node';
|
|
3
|
+
import { Network as Network$1, AbstractedAccount, AnyRawTransaction, AccountAuthenticatorAbstraction } from '@aptos-labs/ts-sdk';
|
|
3
4
|
import { Keypair, Connection } from '@solana/web3.js';
|
|
4
5
|
import { SolanaDerivedPublicKey } from '@aptos-labs/derived-wallet-solana';
|
|
5
6
|
|
|
7
|
+
declare const Network: {
|
|
8
|
+
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
9
|
+
};
|
|
10
|
+
type Network = (typeof Network)[keyof typeof Network];
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
|
-
* A Shelby storage account that can be used as a signer for transactions on the Shelby network
|
|
13
|
+
* A Shelby storage account that can be used as a signer for transactions on the Shelby network.
|
|
14
|
+
* Uses the standard Solana derivable account authentication function.
|
|
8
15
|
*
|
|
9
16
|
* @param params - The parameters for the Shelby storage account
|
|
10
17
|
* @param params.solanaKeypair - The Solana keypair
|
|
11
18
|
* @param params.domain - The domain of the storage account
|
|
12
|
-
* @param params.authenticationFunction - The authentication function
|
|
13
19
|
* @example
|
|
14
20
|
* ```typescript
|
|
21
|
+
* const storageAccount = ShelbyStorageAccount.create(solanaKeypair, "my-awesome-dapp.com");
|
|
22
|
+
* // or
|
|
15
23
|
* const storageAccount = new ShelbyStorageAccount({
|
|
16
24
|
* solanaKeypair: solanaKeypair,
|
|
17
25
|
* domain: "my-awesome-dapp.com",
|
|
18
|
-
* authenticationFunction: "0x1::solana_derivable_account::authenticate",
|
|
19
26
|
* });
|
|
20
27
|
* ```
|
|
21
28
|
*/
|
|
@@ -26,7 +33,6 @@ declare class ShelbyStorageAccount extends AbstractedAccount {
|
|
|
26
33
|
constructor(params: {
|
|
27
34
|
solanaKeypair: Keypair;
|
|
28
35
|
domain: string;
|
|
29
|
-
authenticationFunction: string;
|
|
30
36
|
});
|
|
31
37
|
/**
|
|
32
38
|
* Override the transaction signing to use SIWS envelope format
|
|
@@ -72,9 +78,4 @@ declare class Shelby extends ShelbyClient {
|
|
|
72
78
|
createStorageAccount(solanaKeypair: Keypair, domain: string): ShelbyStorageAccount;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
declare const Network: {
|
|
76
|
-
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
77
|
-
};
|
|
78
|
-
type Network = (typeof Network)[keyof typeof Network];
|
|
79
|
-
|
|
80
81
|
export { Network, Shelby, type ShelbyParams };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import { AbstractedAccount, AnyRawTransaction, AccountAuthenticatorAbstraction, Network as Network$1 } from '@aptos-labs/ts-sdk';
|
|
2
1
|
import { ShelbyNetwork, ShelbyClient } from '@shelby-protocol/sdk/node';
|
|
2
|
+
export * from '@shelby-protocol/sdk/node';
|
|
3
|
+
import { Network as Network$1, AbstractedAccount, AnyRawTransaction, AccountAuthenticatorAbstraction } from '@aptos-labs/ts-sdk';
|
|
3
4
|
import { Keypair, Connection } from '@solana/web3.js';
|
|
4
5
|
import { SolanaDerivedPublicKey } from '@aptos-labs/derived-wallet-solana';
|
|
5
6
|
|
|
7
|
+
declare const Network: {
|
|
8
|
+
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
9
|
+
};
|
|
10
|
+
type Network = (typeof Network)[keyof typeof Network];
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
|
-
* A Shelby storage account that can be used as a signer for transactions on the Shelby network
|
|
13
|
+
* A Shelby storage account that can be used as a signer for transactions on the Shelby network.
|
|
14
|
+
* Uses the standard Solana derivable account authentication function.
|
|
8
15
|
*
|
|
9
16
|
* @param params - The parameters for the Shelby storage account
|
|
10
17
|
* @param params.solanaKeypair - The Solana keypair
|
|
11
18
|
* @param params.domain - The domain of the storage account
|
|
12
|
-
* @param params.authenticationFunction - The authentication function
|
|
13
19
|
* @example
|
|
14
20
|
* ```typescript
|
|
21
|
+
* const storageAccount = ShelbyStorageAccount.create(solanaKeypair, "my-awesome-dapp.com");
|
|
22
|
+
* // or
|
|
15
23
|
* const storageAccount = new ShelbyStorageAccount({
|
|
16
24
|
* solanaKeypair: solanaKeypair,
|
|
17
25
|
* domain: "my-awesome-dapp.com",
|
|
18
|
-
* authenticationFunction: "0x1::solana_derivable_account::authenticate",
|
|
19
26
|
* });
|
|
20
27
|
* ```
|
|
21
28
|
*/
|
|
@@ -26,7 +33,6 @@ declare class ShelbyStorageAccount extends AbstractedAccount {
|
|
|
26
33
|
constructor(params: {
|
|
27
34
|
solanaKeypair: Keypair;
|
|
28
35
|
domain: string;
|
|
29
|
-
authenticationFunction: string;
|
|
30
36
|
});
|
|
31
37
|
/**
|
|
32
38
|
* Override the transaction signing to use SIWS envelope format
|
|
@@ -72,9 +78,4 @@ declare class Shelby extends ShelbyClient {
|
|
|
72
78
|
createStorageAccount(solanaKeypair: Keypair, domain: string): ShelbyStorageAccount;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
declare const Network: {
|
|
76
|
-
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
77
|
-
};
|
|
78
|
-
type Network = (typeof Network)[keyof typeof Network];
|
|
79
|
-
|
|
80
81
|
export { Network, Shelby, type ShelbyParams };
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
1
1
|
// src/node/index.ts
|
|
2
|
+
export * from "@shelby-protocol/sdk/node";
|
|
3
|
+
|
|
4
|
+
// src/common/constants.ts
|
|
2
5
|
import { Network as AptosNetwork } from "@aptos-labs/ts-sdk";
|
|
6
|
+
var AUTH_FUNCTION = "0x1::solana_derivable_account::authenticate";
|
|
7
|
+
var Network = {
|
|
8
|
+
SHELBYNET: AptosNetwork.SHELBYNET
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/common/deriveAddress.ts
|
|
12
|
+
import { SolanaDerivedPublicKey } from "@aptos-labs/derived-wallet-solana";
|
|
13
|
+
|
|
14
|
+
// src/common/signTransaction.ts
|
|
15
|
+
import { DerivableAbstractPublicKey } from "@aptos-labs/derived-wallet-base";
|
|
16
|
+
import { SIGNATURE_TYPE } from "@aptos-labs/derived-wallet-solana";
|
|
17
|
+
import {
|
|
18
|
+
AbstractedAccount,
|
|
19
|
+
AccountAuthenticatorAbstraction,
|
|
20
|
+
Ed25519Signature,
|
|
21
|
+
generateSigningMessageForTransaction,
|
|
22
|
+
Hex,
|
|
23
|
+
hashValues,
|
|
24
|
+
Serializer
|
|
25
|
+
} from "@aptos-labs/ts-sdk";
|
|
26
|
+
import { createSignInMessage } from "@solana/wallet-standard-util";
|
|
27
|
+
|
|
28
|
+
// src/common/transactionStatement.ts
|
|
29
|
+
import {
|
|
30
|
+
getChainName,
|
|
31
|
+
getEntryFunctionName
|
|
32
|
+
} from "@aptos-labs/derived-wallet-base";
|
|
33
|
+
function createTransactionStatement(rawTransaction, domain) {
|
|
34
|
+
const entryFunctionName = getEntryFunctionName(
|
|
35
|
+
rawTransaction.rawTransaction.payload
|
|
36
|
+
);
|
|
37
|
+
const humanReadableEntryFunction = entryFunctionName ? ` ${entryFunctionName}` : "";
|
|
38
|
+
const chainId = rawTransaction.rawTransaction.chain_id.chainId;
|
|
39
|
+
const chainName = getChainName(chainId);
|
|
40
|
+
const onAptosChain = ` on Aptos blockchain (${chainName})`;
|
|
41
|
+
return `Please confirm you explicitly initiated this request from ${domain}. You are approving to execute transaction${humanReadableEntryFunction}${onAptosChain}.`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/common/signTransaction.ts
|
|
45
|
+
function createSiwsMessage(transaction, solanaAddress, domain) {
|
|
46
|
+
const signingMessage = generateSigningMessageForTransaction(transaction);
|
|
47
|
+
const aaMessage = AbstractedAccount.generateAccountAbstractionMessage(
|
|
48
|
+
signingMessage,
|
|
49
|
+
AUTH_FUNCTION
|
|
50
|
+
);
|
|
51
|
+
const signingMessageDigest = hashValues([aaMessage]);
|
|
52
|
+
const siwsInput = {
|
|
53
|
+
address: solanaAddress,
|
|
54
|
+
domain,
|
|
55
|
+
nonce: Hex.fromHexInput(signingMessageDigest).toString(),
|
|
56
|
+
statement: createTransactionStatement(transaction, domain)
|
|
57
|
+
};
|
|
58
|
+
const messageToSign = createSignInMessage(siwsInput);
|
|
59
|
+
return {
|
|
60
|
+
messageToSign,
|
|
61
|
+
signingMessageDigest
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function createAuthenticator(signatureBytes, solanaAddress, domain, signingMessageDigest) {
|
|
65
|
+
const signature = new Ed25519Signature(signatureBytes);
|
|
66
|
+
const serializer = new Serializer();
|
|
67
|
+
serializer.serializeU8(SIGNATURE_TYPE);
|
|
68
|
+
serializer.serializeBytes(signature.toUint8Array());
|
|
69
|
+
const abstractSignature = serializer.toUint8Array();
|
|
70
|
+
const abstractPublicKey = new DerivableAbstractPublicKey(
|
|
71
|
+
solanaAddress,
|
|
72
|
+
domain
|
|
73
|
+
);
|
|
74
|
+
return new AccountAuthenticatorAbstraction(
|
|
75
|
+
AUTH_FUNCTION,
|
|
76
|
+
signingMessageDigest,
|
|
77
|
+
abstractSignature,
|
|
78
|
+
abstractPublicKey.bcsToBytes()
|
|
79
|
+
);
|
|
80
|
+
}
|
|
3
81
|
|
|
4
82
|
// src/node/shelby.ts
|
|
5
83
|
import { GasStationTransactionSubmitter } from "@aptos-labs/gas-station-client";
|
|
@@ -8,27 +86,22 @@ import {
|
|
|
8
86
|
} from "@shelby-protocol/sdk/node";
|
|
9
87
|
|
|
10
88
|
// src/node/storageAccount.ts
|
|
89
|
+
import { SolanaDerivedPublicKey as SolanaDerivedPublicKey2 } from "@aptos-labs/derived-wallet-solana";
|
|
11
90
|
import {
|
|
12
|
-
|
|
13
|
-
createMessageForSolanaTransaction,
|
|
14
|
-
SolanaDerivedPublicKey
|
|
15
|
-
} from "@aptos-labs/derived-wallet-solana";
|
|
16
|
-
import {
|
|
17
|
-
AbstractedAccount
|
|
91
|
+
AbstractedAccount as AbstractedAccount2
|
|
18
92
|
} from "@aptos-labs/ts-sdk";
|
|
19
|
-
import { createSignInMessage } from "@solana/wallet-standard-util";
|
|
20
93
|
import nacl from "tweetnacl";
|
|
21
|
-
var ShelbyStorageAccount = class extends
|
|
94
|
+
var ShelbyStorageAccount = class extends AbstractedAccount2 {
|
|
22
95
|
constructor(params) {
|
|
23
|
-
const { solanaKeypair, domain
|
|
24
|
-
const derivedPublicKey = new
|
|
96
|
+
const { solanaKeypair, domain } = params;
|
|
97
|
+
const derivedPublicKey = new SolanaDerivedPublicKey2({
|
|
25
98
|
domain,
|
|
26
99
|
solanaPublicKey: solanaKeypair.publicKey,
|
|
27
|
-
authenticationFunction
|
|
100
|
+
authenticationFunction: AUTH_FUNCTION
|
|
28
101
|
});
|
|
29
102
|
super({
|
|
30
103
|
accountAddress: derivedPublicKey.authKey().derivedAddress(),
|
|
31
|
-
authenticationFunction,
|
|
104
|
+
authenticationFunction: AUTH_FUNCTION,
|
|
32
105
|
signer: (digest) => {
|
|
33
106
|
return nacl.sign.detached(
|
|
34
107
|
digest,
|
|
@@ -44,22 +117,20 @@ var ShelbyStorageAccount = class extends AbstractedAccount {
|
|
|
44
117
|
* Override the transaction signing to use SIWS envelope format
|
|
45
118
|
*/
|
|
46
119
|
signTransactionWithAuthenticator(transaction) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const messageToSign = createSignInMessage(siwsInput);
|
|
120
|
+
const solanaAddress = this.solanaKeypair.publicKey.toBase58();
|
|
121
|
+
const { messageToSign, signingMessageDigest } = createSiwsMessage(
|
|
122
|
+
transaction,
|
|
123
|
+
solanaAddress,
|
|
124
|
+
this.domain
|
|
125
|
+
);
|
|
54
126
|
const signatureBytes = nacl.sign.detached(
|
|
55
127
|
messageToSign,
|
|
56
128
|
this.solanaKeypair.secretKey
|
|
57
129
|
);
|
|
58
|
-
return
|
|
130
|
+
return createAuthenticator(
|
|
59
131
|
signatureBytes,
|
|
60
|
-
|
|
132
|
+
solanaAddress,
|
|
61
133
|
this.domain,
|
|
62
|
-
this.authenticationFunction,
|
|
63
134
|
signingMessageDigest
|
|
64
135
|
);
|
|
65
136
|
}
|
|
@@ -98,18 +169,9 @@ var Shelby = class extends ShelbyClient {
|
|
|
98
169
|
* ```
|
|
99
170
|
*/
|
|
100
171
|
createStorageAccount(solanaKeypair, domain) {
|
|
101
|
-
return new ShelbyStorageAccount({
|
|
102
|
-
solanaKeypair,
|
|
103
|
-
domain,
|
|
104
|
-
authenticationFunction: "0x1::solana_derivable_account::authenticate"
|
|
105
|
-
});
|
|
172
|
+
return new ShelbyStorageAccount({ solanaKeypair, domain });
|
|
106
173
|
}
|
|
107
174
|
};
|
|
108
|
-
|
|
109
|
-
// src/node/index.ts
|
|
110
|
-
var Network = {
|
|
111
|
-
SHELBYNET: AptosNetwork.SHELBYNET
|
|
112
|
-
};
|
|
113
175
|
export {
|
|
114
176
|
Network,
|
|
115
177
|
Shelby
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Network as Network$1, AccountAddress, InputGenerateTransactionPayloadData, AccountAuthenticatorAbstraction, AnyRawTransaction, InputTransactionPluginData } from '@aptos-labs/ts-sdk';
|
|
2
|
+
import { ShelbyClient } from '@shelby-protocol/sdk/browser';
|
|
3
|
+
|
|
4
|
+
declare const Network: {
|
|
5
|
+
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
6
|
+
};
|
|
7
|
+
type Network = (typeof Network)[keyof typeof Network];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Function type for signing messages with a Solana wallet.
|
|
11
|
+
*/
|
|
12
|
+
type SignMessageFn = (message: Uint8Array) => Promise<Uint8Array>;
|
|
13
|
+
/**
|
|
14
|
+
* Input type for signing and submitting transactions with the Solana wallet.
|
|
15
|
+
*/
|
|
16
|
+
type SignAndSubmitTransactionInput = {
|
|
17
|
+
transactionPayload: {
|
|
18
|
+
data: InputGenerateTransactionPayloadData;
|
|
19
|
+
};
|
|
20
|
+
transactionSubmitter?: InputTransactionPluginData;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Input type for signing transactions with the Solana wallet.
|
|
24
|
+
*/
|
|
25
|
+
type SignTransactionInput = {
|
|
26
|
+
data: InputGenerateTransactionPayloadData;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Input type for submitting transactions with the Solana wallet.
|
|
30
|
+
*/
|
|
31
|
+
type SubmitTransactionInput = {
|
|
32
|
+
transaction: AnyRawTransaction;
|
|
33
|
+
authenticator: AccountAuthenticatorAbstraction;
|
|
34
|
+
transactionSubmitter?: InputTransactionPluginData;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Parameters type for the useStorageAccount hook.
|
|
38
|
+
*/
|
|
39
|
+
interface UseStorageAccountParams {
|
|
40
|
+
/** The Shelby client */
|
|
41
|
+
client: ShelbyClient;
|
|
42
|
+
/** The connected Solana wallet address (base58 string) */
|
|
43
|
+
solanaAddress?: string;
|
|
44
|
+
/** Function to sign messages with the Solana wallet */
|
|
45
|
+
signMessageFn?: SignMessageFn;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Result type for the useStorageAccount hook.
|
|
49
|
+
*/
|
|
50
|
+
interface UseStorageAccountResult {
|
|
51
|
+
/** The derived Shelby storage account address */
|
|
52
|
+
storageAccountAddress: AccountAddress | null;
|
|
53
|
+
/** Sign a transaction for Shelby using the connected Solana wallet */
|
|
54
|
+
signTransaction: (params: SignTransactionInput) => Promise<{
|
|
55
|
+
authenticator: AccountAuthenticatorAbstraction;
|
|
56
|
+
rawTransaction: AnyRawTransaction;
|
|
57
|
+
}>;
|
|
58
|
+
/** Submit a transaction to Shelby */
|
|
59
|
+
submitTransaction: (params: SubmitTransactionInput) => Promise<{
|
|
60
|
+
hash: string;
|
|
61
|
+
}>;
|
|
62
|
+
/** Sign and submit a transaction to Shelby */
|
|
63
|
+
signAndSubmitTransaction: (params: SignAndSubmitTransactionInput) => Promise<{
|
|
64
|
+
hash: string;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Hook to access Shelby storage functionality.
|
|
69
|
+
* Must be used within a ShelbyProvider.
|
|
70
|
+
*
|
|
71
|
+
* @param params - The Solana wallet address and signMessage function
|
|
72
|
+
* @returns Storage account address and transaction signing function
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* const { wallet } = useWalletConnection();
|
|
77
|
+
* const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount({
|
|
78
|
+
* client: shelbyClient,
|
|
79
|
+
* solanaAddress: wallet?.account.address.toString(),
|
|
80
|
+
* signMessageFn: wallet?.signMessage,
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function useStorageAccount(params: UseStorageAccountParams): UseStorageAccountResult;
|
|
85
|
+
|
|
86
|
+
export { Network, type SignMessageFn, type UseStorageAccountParams, type UseStorageAccountResult, useStorageAccount };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// src/common/constants.ts
|
|
2
|
+
import { Network as AptosNetwork } from "@aptos-labs/ts-sdk";
|
|
3
|
+
var AUTH_FUNCTION = "0x1::solana_derivable_account::authenticate";
|
|
4
|
+
var Network = {
|
|
5
|
+
SHELBYNET: AptosNetwork.SHELBYNET
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/common/deriveAddress.ts
|
|
9
|
+
import { SolanaDerivedPublicKey } from "@aptos-labs/derived-wallet-solana";
|
|
10
|
+
function deriveStorageAccountAddress(solanaPublicKey, domain) {
|
|
11
|
+
const derivedPublicKey = new SolanaDerivedPublicKey({
|
|
12
|
+
domain,
|
|
13
|
+
solanaPublicKey,
|
|
14
|
+
authenticationFunction: AUTH_FUNCTION
|
|
15
|
+
});
|
|
16
|
+
return derivedPublicKey.authKey().derivedAddress();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/common/signTransaction.ts
|
|
20
|
+
import { DerivableAbstractPublicKey } from "@aptos-labs/derived-wallet-base";
|
|
21
|
+
import { SIGNATURE_TYPE } from "@aptos-labs/derived-wallet-solana";
|
|
22
|
+
import {
|
|
23
|
+
AbstractedAccount,
|
|
24
|
+
AccountAuthenticatorAbstraction,
|
|
25
|
+
Ed25519Signature,
|
|
26
|
+
generateSigningMessageForTransaction,
|
|
27
|
+
Hex,
|
|
28
|
+
hashValues,
|
|
29
|
+
Serializer
|
|
30
|
+
} from "@aptos-labs/ts-sdk";
|
|
31
|
+
import { createSignInMessage } from "@solana/wallet-standard-util";
|
|
32
|
+
|
|
33
|
+
// src/common/transactionStatement.ts
|
|
34
|
+
import {
|
|
35
|
+
getChainName,
|
|
36
|
+
getEntryFunctionName
|
|
37
|
+
} from "@aptos-labs/derived-wallet-base";
|
|
38
|
+
function createTransactionStatement(rawTransaction, domain) {
|
|
39
|
+
const entryFunctionName = getEntryFunctionName(
|
|
40
|
+
rawTransaction.rawTransaction.payload
|
|
41
|
+
);
|
|
42
|
+
const humanReadableEntryFunction = entryFunctionName ? ` ${entryFunctionName}` : "";
|
|
43
|
+
const chainId = rawTransaction.rawTransaction.chain_id.chainId;
|
|
44
|
+
const chainName = getChainName(chainId);
|
|
45
|
+
const onAptosChain = ` on Aptos blockchain (${chainName})`;
|
|
46
|
+
return `Please confirm you explicitly initiated this request from ${domain}. You are approving to execute transaction${humanReadableEntryFunction}${onAptosChain}.`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/common/signTransaction.ts
|
|
50
|
+
function createSiwsMessage(transaction, solanaAddress, domain) {
|
|
51
|
+
const signingMessage = generateSigningMessageForTransaction(transaction);
|
|
52
|
+
const aaMessage = AbstractedAccount.generateAccountAbstractionMessage(
|
|
53
|
+
signingMessage,
|
|
54
|
+
AUTH_FUNCTION
|
|
55
|
+
);
|
|
56
|
+
const signingMessageDigest = hashValues([aaMessage]);
|
|
57
|
+
const siwsInput = {
|
|
58
|
+
address: solanaAddress,
|
|
59
|
+
domain,
|
|
60
|
+
nonce: Hex.fromHexInput(signingMessageDigest).toString(),
|
|
61
|
+
statement: createTransactionStatement(transaction, domain)
|
|
62
|
+
};
|
|
63
|
+
const messageToSign = createSignInMessage(siwsInput);
|
|
64
|
+
return {
|
|
65
|
+
messageToSign,
|
|
66
|
+
signingMessageDigest
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function createAuthenticator(signatureBytes, solanaAddress, domain, signingMessageDigest) {
|
|
70
|
+
const signature = new Ed25519Signature(signatureBytes);
|
|
71
|
+
const serializer = new Serializer();
|
|
72
|
+
serializer.serializeU8(SIGNATURE_TYPE);
|
|
73
|
+
serializer.serializeBytes(signature.toUint8Array());
|
|
74
|
+
const abstractSignature = serializer.toUint8Array();
|
|
75
|
+
const abstractPublicKey = new DerivableAbstractPublicKey(
|
|
76
|
+
solanaAddress,
|
|
77
|
+
domain
|
|
78
|
+
);
|
|
79
|
+
return new AccountAuthenticatorAbstraction(
|
|
80
|
+
AUTH_FUNCTION,
|
|
81
|
+
signingMessageDigest,
|
|
82
|
+
abstractSignature,
|
|
83
|
+
abstractPublicKey.bcsToBytes()
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/react/useStorageAccount.tsx
|
|
88
|
+
import {
|
|
89
|
+
AccountAddress
|
|
90
|
+
} from "@aptos-labs/ts-sdk";
|
|
91
|
+
import { PublicKey } from "@solana/web3.js";
|
|
92
|
+
import { useMemo } from "react";
|
|
93
|
+
function useStorageAccount(params) {
|
|
94
|
+
const { client } = params;
|
|
95
|
+
const { solanaAddress, signMessageFn } = params;
|
|
96
|
+
const domain = typeof window !== "undefined" ? window.location.host : "localhost";
|
|
97
|
+
const storageAccountAddress = useMemo(() => {
|
|
98
|
+
if (!solanaAddress) return null;
|
|
99
|
+
try {
|
|
100
|
+
const solanaPublicKey = new PublicKey(solanaAddress);
|
|
101
|
+
return deriveStorageAccountAddress(solanaPublicKey, domain);
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}, [solanaAddress, domain]);
|
|
106
|
+
const signTransaction = async (params2) => {
|
|
107
|
+
if (!solanaAddress) {
|
|
108
|
+
throw new Error("Wallet not connected");
|
|
109
|
+
}
|
|
110
|
+
if (!storageAccountAddress) {
|
|
111
|
+
throw new Error("Storage account address not found");
|
|
112
|
+
}
|
|
113
|
+
if (!signMessageFn) {
|
|
114
|
+
throw new Error("signMessage function not provided");
|
|
115
|
+
}
|
|
116
|
+
const rawTransaction = await client.aptos.transaction.build.simple({
|
|
117
|
+
sender: AccountAddress.from(storageAccountAddress),
|
|
118
|
+
data: params2.data
|
|
119
|
+
});
|
|
120
|
+
const { messageToSign, signingMessageDigest } = createSiwsMessage(
|
|
121
|
+
rawTransaction,
|
|
122
|
+
solanaAddress,
|
|
123
|
+
domain
|
|
124
|
+
);
|
|
125
|
+
const signatureBytes = await signMessageFn(messageToSign);
|
|
126
|
+
const authenticator = createAuthenticator(
|
|
127
|
+
signatureBytes,
|
|
128
|
+
solanaAddress,
|
|
129
|
+
domain,
|
|
130
|
+
signingMessageDigest
|
|
131
|
+
);
|
|
132
|
+
return { authenticator, rawTransaction };
|
|
133
|
+
};
|
|
134
|
+
const submitTransaction = async (params2) => {
|
|
135
|
+
if (!solanaAddress) {
|
|
136
|
+
throw new Error("Wallet not connected");
|
|
137
|
+
}
|
|
138
|
+
const { transaction, authenticator, transactionSubmitter } = params2;
|
|
139
|
+
const transactionSubmitted = await client.aptos.transaction.submit.simple({
|
|
140
|
+
transaction,
|
|
141
|
+
senderAuthenticator: authenticator,
|
|
142
|
+
transactionSubmitter: transactionSubmitter?.transactionSubmitter ?? null
|
|
143
|
+
});
|
|
144
|
+
const committedTransaction = await client.aptos.waitForTransaction({
|
|
145
|
+
transactionHash: transactionSubmitted.hash
|
|
146
|
+
});
|
|
147
|
+
return { hash: committedTransaction.hash };
|
|
148
|
+
};
|
|
149
|
+
const signAndSubmitTransaction = async (params2) => {
|
|
150
|
+
if (!solanaAddress) {
|
|
151
|
+
throw new Error("Wallet not connected");
|
|
152
|
+
}
|
|
153
|
+
if (!signMessageFn) {
|
|
154
|
+
throw new Error("signMessage function not provided");
|
|
155
|
+
}
|
|
156
|
+
if (!storageAccountAddress) {
|
|
157
|
+
throw new Error("Storage account address not found");
|
|
158
|
+
}
|
|
159
|
+
const { transactionPayload, transactionSubmitter } = params2;
|
|
160
|
+
const { authenticator, rawTransaction } = await signTransaction({
|
|
161
|
+
data: transactionPayload.data
|
|
162
|
+
});
|
|
163
|
+
const hash = await submitTransaction({
|
|
164
|
+
transaction: rawTransaction,
|
|
165
|
+
authenticator,
|
|
166
|
+
transactionSubmitter
|
|
167
|
+
});
|
|
168
|
+
return hash;
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
storageAccountAddress,
|
|
172
|
+
signTransaction,
|
|
173
|
+
submitTransaction,
|
|
174
|
+
signAndSubmitTransaction
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
Network,
|
|
179
|
+
useStorageAccount
|
|
180
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelby-protocol/solana-kit",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
"./node": {
|
|
14
14
|
"types": "./dist/node/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"require": "./dist/node/index.cjs",
|
|
16
|
+
"import": "./dist/node/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./react": {
|
|
19
|
+
"types": "./dist/react/index.d.ts",
|
|
20
|
+
"import": "./dist/react/index.mjs"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
@@ -22,10 +26,16 @@
|
|
|
22
26
|
"rimraf": "^6.0.1",
|
|
23
27
|
"tsup": "^8.4.0",
|
|
24
28
|
"typescript": "^5.8.3",
|
|
25
|
-
"vitest": "^3.1.2"
|
|
29
|
+
"vitest": "^3.1.2",
|
|
30
|
+
"@types/react": "19.2.1",
|
|
31
|
+
"@types/react-dom": "19.2.1",
|
|
32
|
+
"react": "19.2.1",
|
|
33
|
+
"react-dom": "19.2.1"
|
|
26
34
|
},
|
|
27
35
|
"peerDependencies": {
|
|
28
|
-
"@solana/web3.js": "^1.98.4"
|
|
36
|
+
"@solana/web3.js": "^1.98.4",
|
|
37
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
38
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
29
39
|
},
|
|
30
40
|
"dependencies": {
|
|
31
41
|
"@aptos-labs/derived-wallet-base": "^0.10.0",
|