@shelby-protocol/ethereum-kit 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/README.md +115 -0
- package/dist/node/index.cjs +61 -0
- package/dist/node/index.d.cts +76 -0
- package/dist/node/index.d.ts +76 -0
- package/dist/node/index.mjs +61 -0
- package/dist/react/index.d.ts +95 -0
- package/dist/react/index.mjs +87 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Ethereum Kit for the Shelby Protocol
|
|
2
|
+
|
|
3
|
+
> Note: The SDK is currently an alpha version; therefore, you can expect breaking changes.
|
|
4
|
+
|
|
5
|
+
Shelby is a high-performance decentralized blob storage system designed for demanding read-heavy workloads. Read more about Shelby, its capabilities, and components [here](https://docs.shelby.xyz/protocol).
|
|
6
|
+
|
|
7
|
+
The Ethereum Kit SDK was built to facilitate the development of Ethereum applications that use the Shelby Protocol.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install with your favorite package manager such as npm, yarn, or pnpm:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm install @shelby-protocol/ethereum-kit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Entry Points
|
|
18
|
+
|
|
19
|
+
The package provides two entry points for different use cases:
|
|
20
|
+
|
|
21
|
+
| Entry Point | Import Path | Use Case |
|
|
22
|
+
|-------------|-------------|----------|
|
|
23
|
+
| **Node.js** | `@shelby-protocol/ethereum-kit/node` | Server-side applications, scripts, CLIs |
|
|
24
|
+
| **React** | `@shelby-protocol/ethereum-kit/react` | Browser applications with wallet connections (wagmi) |
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Node.js / Server-side
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { Shelby, Network } from "@shelby-protocol/ethereum-kit/node";
|
|
32
|
+
import { Wallet } from "ethers";
|
|
33
|
+
|
|
34
|
+
const shelbyClient = new Shelby({
|
|
35
|
+
network: Network.SHELBYNET,
|
|
36
|
+
apiKey: "AG-***",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const ethereumWallet = new Wallet("0x...");
|
|
40
|
+
const storageAccount = shelbyClient.createStorageAccount(
|
|
41
|
+
ethereumWallet,
|
|
42
|
+
"my-dapp.com"
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
See [Node.js README](./src/node/README.md) for detailed usage.
|
|
47
|
+
|
|
48
|
+
### React / Browser (with wagmi)
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { useStorageAccount, Network } from "@shelby-protocol/ethereum-kit/react";
|
|
52
|
+
import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
53
|
+
import { useWalletClient } from "wagmi";
|
|
54
|
+
|
|
55
|
+
function MyComponent() {
|
|
56
|
+
const { data: wallet } = useWalletClient();
|
|
57
|
+
const shelbyClient = new ShelbyClient({ network: Network.SHELBYNET, apiKey: "AG-***" });
|
|
58
|
+
|
|
59
|
+
const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount({
|
|
60
|
+
client: shelbyClient,
|
|
61
|
+
wallet,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Storage account is automatically derived from the connected wallet
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
See [React README](./src/react/README.md) for detailed usage.
|
|
69
|
+
|
|
70
|
+
## Key Concepts
|
|
71
|
+
|
|
72
|
+
### Shelby Storage Account
|
|
73
|
+
|
|
74
|
+
Shelby uses the Aptos blockchain as a coordination and settlement layer. To allow an Ethereum identity to own data in Shelby, the protocol leverages [Aptos Derivable Account Abstraction](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-113.md) to create a **Shelby Storage Account**.
|
|
75
|
+
|
|
76
|
+
This enables cross-chain signatures (SIWE - Sign-In with Ethereum) to be managed flexibly and securely on the Aptos network. Read more about it [here](https://aptos.dev/build/sdks/wallet-adapter/x-chain-accounts).
|
|
77
|
+
|
|
78
|
+
**Ownership hierarchy:**
|
|
79
|
+
|
|
80
|
+
- Ethereum wallet controls the Storage Account
|
|
81
|
+
- Storage Account owns the blobs on Shelby
|
|
82
|
+
|
|
83
|
+
**Address derivation:**
|
|
84
|
+
|
|
85
|
+
The storage account address is deterministically derived from:
|
|
86
|
+
1. The Ethereum address
|
|
87
|
+
2. The dApp domain (e.g., `my-dapp.com`)
|
|
88
|
+
|
|
89
|
+
This means the same Ethereum wallet will have different storage accounts on different dApps, providing application-level isolation.
|
|
90
|
+
|
|
91
|
+
### Acquire a Shelby API Key
|
|
92
|
+
|
|
93
|
+
API keys authenticate your app and manage rate limits when using Shelby services. Without one, your client runs in "anonymous" mode with much lower limits.
|
|
94
|
+
|
|
95
|
+
Follow [this guide](https://docs.shelby.xyz/sdks/typescript/acquire-api-keys#acquiring-api-keys) to acquire an API Key.
|
|
96
|
+
|
|
97
|
+
## Retrieving Files
|
|
98
|
+
|
|
99
|
+
### Through Shelby Explorer
|
|
100
|
+
|
|
101
|
+
Once a blob has been uploaded to Shelby, it is viewable through the [Shelby Explorer](https://explorer.shelby.xyz/shelbynet). Search for the storage account address to view the blobs owned by that account.
|
|
102
|
+
|
|
103
|
+
### Via HTTP Request
|
|
104
|
+
|
|
105
|
+
Download files directly using a GET request to the Shelby RPC endpoint:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
curl -X GET "https://api.shelbynet.shelby.xyz/shelby/v1/blobs/{account_address}/{blob_name}"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Documentation
|
|
112
|
+
|
|
113
|
+
- [Node.js Usage](./src/node/README.md) - Server-side applications
|
|
114
|
+
- [React Usage](./src/react/README.md) - Browser applications (wagmi)
|
|
115
|
+
- [Full Documentation](https://docs.shelby.xyz/sdks/ethereum-kit)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
|
|
5
|
+
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
6
|
+
var Network = {
|
|
7
|
+
SHELBYNET: _tssdk.Network.SHELBYNET
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/node/shelby.ts
|
|
11
|
+
var _gasstationclient = require('@aptos-labs/gas-station-client');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// src/node/storageAccount.ts
|
|
17
|
+
var _derivedwalletethereum = require('@aptos-labs/derived-wallet-ethereum');
|
|
18
|
+
var ShelbyStorageAccount = class extends _derivedwalletethereum.EIP1193DerivedAccount {
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/node/shelby.ts
|
|
22
|
+
var Shelby = class extends _node.ShelbyClient {
|
|
23
|
+
constructor(params) {
|
|
24
|
+
const shelbyClientConfig = {
|
|
25
|
+
network: params.network,
|
|
26
|
+
apiKey: params.apiKey
|
|
27
|
+
};
|
|
28
|
+
if (params.gasStationApiKey) {
|
|
29
|
+
shelbyClientConfig.aptos = {
|
|
30
|
+
pluginSettings: {
|
|
31
|
+
TRANSACTION_SUBMITTER: new (0, _gasstationclient.GasStationTransactionSubmitter)({
|
|
32
|
+
network: params.network,
|
|
33
|
+
apiKey: params.gasStationApiKey
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
super(shelbyClientConfig);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a Shelby storage account from an Ethereum wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param ethereumWallet - The ethers Wallet instance (with private key)
|
|
44
|
+
* @param domain - The domain of the storage account
|
|
45
|
+
* @param scheme - The URI scheme (defaults to "https")
|
|
46
|
+
* @returns The Shelby storage account
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const storageAccount = shelbyClient.createStorageAccount(ethereumWallet, "my-dapp.com");
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
createStorageAccount(ethereumWallet, domain, scheme) {
|
|
54
|
+
return new ShelbyStorageAccount({ ethereumWallet, domain, scheme });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
exports.Network = Network; exports.Shelby = Shelby; exports.ShelbyStorageAccount = ShelbyStorageAccount;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ShelbyNetwork, ShelbyClient } from '@shelby-protocol/sdk/node';
|
|
2
|
+
export * from '@shelby-protocol/sdk/node';
|
|
3
|
+
import { Network as Network$1 } from '@aptos-labs/ts-sdk';
|
|
4
|
+
import { Wallet } from 'ethers';
|
|
5
|
+
import { EIP1193DerivedAccount } from '@aptos-labs/derived-wallet-ethereum';
|
|
6
|
+
|
|
7
|
+
declare const Network: {
|
|
8
|
+
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
9
|
+
};
|
|
10
|
+
type Network = (typeof Network)[keyof typeof Network];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A Shelby storage account that can be used as a signer for transactions on the Shelby network.
|
|
14
|
+
* Uses the standard Ethereum derivable account authentication function.
|
|
15
|
+
*
|
|
16
|
+
* Extends EIP1193DerivedAccount from @aptos-labs/derived-wallet-ethereum.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { Wallet } from "ethers";
|
|
21
|
+
*
|
|
22
|
+
* const ethereumWallet = new Wallet("0x...");
|
|
23
|
+
* const storageAccount = new ShelbyStorageAccount({
|
|
24
|
+
* ethereumWallet,
|
|
25
|
+
* domain: "my-awesome-dapp.com",
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare class ShelbyStorageAccount extends EIP1193DerivedAccount {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface ShelbyParams {
|
|
33
|
+
/** The Shelby network to connect with */
|
|
34
|
+
network: ShelbyNetwork;
|
|
35
|
+
/** The Shelby API key */
|
|
36
|
+
apiKey: string;
|
|
37
|
+
/** The Gas Station API key (optional, for sponsored transactions) */
|
|
38
|
+
gasStationApiKey?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The Shelby client for the Ethereum ecosystem.
|
|
42
|
+
*
|
|
43
|
+
* @param params - The parameters for the Shelby client
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { Wallet } from "ethers";
|
|
48
|
+
*
|
|
49
|
+
* const shelbyClient = new Shelby({
|
|
50
|
+
* network: Network.SHELBYNET,
|
|
51
|
+
* apiKey: "AG-***",
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const ethereumWallet = new Wallet("0x...");
|
|
55
|
+
* const storageAccount = shelbyClient.createStorageAccount(ethereumWallet, "my-dapp.com");
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare class Shelby extends ShelbyClient {
|
|
59
|
+
constructor(params: ShelbyParams);
|
|
60
|
+
/**
|
|
61
|
+
* Create a Shelby storage account from an Ethereum wallet.
|
|
62
|
+
*
|
|
63
|
+
* @param ethereumWallet - The ethers Wallet instance (with private key)
|
|
64
|
+
* @param domain - The domain of the storage account
|
|
65
|
+
* @param scheme - The URI scheme (defaults to "https")
|
|
66
|
+
* @returns The Shelby storage account
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const storageAccount = shelbyClient.createStorageAccount(ethereumWallet, "my-dapp.com");
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
createStorageAccount(ethereumWallet: Wallet, domain: string, scheme?: string): ShelbyStorageAccount;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { Network, Shelby, type ShelbyParams, ShelbyStorageAccount };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ShelbyNetwork, ShelbyClient } from '@shelby-protocol/sdk/node';
|
|
2
|
+
export * from '@shelby-protocol/sdk/node';
|
|
3
|
+
import { Network as Network$1 } from '@aptos-labs/ts-sdk';
|
|
4
|
+
import { Wallet } from 'ethers';
|
|
5
|
+
import { EIP1193DerivedAccount } from '@aptos-labs/derived-wallet-ethereum';
|
|
6
|
+
|
|
7
|
+
declare const Network: {
|
|
8
|
+
readonly SHELBYNET: Network$1.SHELBYNET;
|
|
9
|
+
};
|
|
10
|
+
type Network = (typeof Network)[keyof typeof Network];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A Shelby storage account that can be used as a signer for transactions on the Shelby network.
|
|
14
|
+
* Uses the standard Ethereum derivable account authentication function.
|
|
15
|
+
*
|
|
16
|
+
* Extends EIP1193DerivedAccount from @aptos-labs/derived-wallet-ethereum.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { Wallet } from "ethers";
|
|
21
|
+
*
|
|
22
|
+
* const ethereumWallet = new Wallet("0x...");
|
|
23
|
+
* const storageAccount = new ShelbyStorageAccount({
|
|
24
|
+
* ethereumWallet,
|
|
25
|
+
* domain: "my-awesome-dapp.com",
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare class ShelbyStorageAccount extends EIP1193DerivedAccount {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface ShelbyParams {
|
|
33
|
+
/** The Shelby network to connect with */
|
|
34
|
+
network: ShelbyNetwork;
|
|
35
|
+
/** The Shelby API key */
|
|
36
|
+
apiKey: string;
|
|
37
|
+
/** The Gas Station API key (optional, for sponsored transactions) */
|
|
38
|
+
gasStationApiKey?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The Shelby client for the Ethereum ecosystem.
|
|
42
|
+
*
|
|
43
|
+
* @param params - The parameters for the Shelby client
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { Wallet } from "ethers";
|
|
48
|
+
*
|
|
49
|
+
* const shelbyClient = new Shelby({
|
|
50
|
+
* network: Network.SHELBYNET,
|
|
51
|
+
* apiKey: "AG-***",
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const ethereumWallet = new Wallet("0x...");
|
|
55
|
+
* const storageAccount = shelbyClient.createStorageAccount(ethereumWallet, "my-dapp.com");
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare class Shelby extends ShelbyClient {
|
|
59
|
+
constructor(params: ShelbyParams);
|
|
60
|
+
/**
|
|
61
|
+
* Create a Shelby storage account from an Ethereum wallet.
|
|
62
|
+
*
|
|
63
|
+
* @param ethereumWallet - The ethers Wallet instance (with private key)
|
|
64
|
+
* @param domain - The domain of the storage account
|
|
65
|
+
* @param scheme - The URI scheme (defaults to "https")
|
|
66
|
+
* @returns The Shelby storage account
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const storageAccount = shelbyClient.createStorageAccount(ethereumWallet, "my-dapp.com");
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
createStorageAccount(ethereumWallet: Wallet, domain: string, scheme?: string): ShelbyStorageAccount;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { Network, Shelby, type ShelbyParams, ShelbyStorageAccount };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/node/index.ts
|
|
2
|
+
export * from "@shelby-protocol/sdk/node";
|
|
3
|
+
|
|
4
|
+
// src/common/constants.ts
|
|
5
|
+
import { Network as AptosNetwork } from "@aptos-labs/ts-sdk";
|
|
6
|
+
var Network = {
|
|
7
|
+
SHELBYNET: AptosNetwork.SHELBYNET
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/node/shelby.ts
|
|
11
|
+
import { GasStationTransactionSubmitter } from "@aptos-labs/gas-station-client";
|
|
12
|
+
import {
|
|
13
|
+
ShelbyClient
|
|
14
|
+
} from "@shelby-protocol/sdk/node";
|
|
15
|
+
|
|
16
|
+
// src/node/storageAccount.ts
|
|
17
|
+
import { EIP1193DerivedAccount } from "@aptos-labs/derived-wallet-ethereum";
|
|
18
|
+
var ShelbyStorageAccount = class extends EIP1193DerivedAccount {
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/node/shelby.ts
|
|
22
|
+
var Shelby = class extends ShelbyClient {
|
|
23
|
+
constructor(params) {
|
|
24
|
+
const shelbyClientConfig = {
|
|
25
|
+
network: params.network,
|
|
26
|
+
apiKey: params.apiKey
|
|
27
|
+
};
|
|
28
|
+
if (params.gasStationApiKey) {
|
|
29
|
+
shelbyClientConfig.aptos = {
|
|
30
|
+
pluginSettings: {
|
|
31
|
+
TRANSACTION_SUBMITTER: new GasStationTransactionSubmitter({
|
|
32
|
+
network: params.network,
|
|
33
|
+
apiKey: params.gasStationApiKey
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
super(shelbyClientConfig);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a Shelby storage account from an Ethereum wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param ethereumWallet - The ethers Wallet instance (with private key)
|
|
44
|
+
* @param domain - The domain of the storage account
|
|
45
|
+
* @param scheme - The URI scheme (defaults to "https")
|
|
46
|
+
* @returns The Shelby storage account
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const storageAccount = shelbyClient.createStorageAccount(ethereumWallet, "my-dapp.com");
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
createStorageAccount(ethereumWallet, domain, scheme) {
|
|
54
|
+
return new ShelbyStorageAccount({ ethereumWallet, domain, scheme });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
Network,
|
|
59
|
+
Shelby,
|
|
60
|
+
ShelbyStorageAccount
|
|
61
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Network as Network$1, InputEntryFunctionData, InputTransactionPluginData, AnyRawTransaction, AccountAuthenticatorAbstraction, AccountAddress } 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
|
+
* Wallet interface compatible with wagmi's useWalletClient().
|
|
11
|
+
* Works with RainbowKit, Web3Modal, ConnectKit, etc.
|
|
12
|
+
*/
|
|
13
|
+
interface EthereumWallet {
|
|
14
|
+
account: {
|
|
15
|
+
address: `0x${string}`;
|
|
16
|
+
};
|
|
17
|
+
/** EIP-1193 request method - available on wagmi WalletClient */
|
|
18
|
+
request: (args: {
|
|
19
|
+
method: string;
|
|
20
|
+
params?: unknown[];
|
|
21
|
+
}) => Promise<unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Input type for signing transactions with the Ethereum wallet.
|
|
25
|
+
*/
|
|
26
|
+
type SignTransactionInput = {
|
|
27
|
+
data: InputEntryFunctionData;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Input type for submitting transactions with the Ethereum wallet.
|
|
31
|
+
*/
|
|
32
|
+
type SubmitTransactionInput = {
|
|
33
|
+
transaction: AnyRawTransaction;
|
|
34
|
+
senderAuthenticator: AccountAuthenticatorAbstraction;
|
|
35
|
+
} & InputTransactionPluginData;
|
|
36
|
+
/**
|
|
37
|
+
* Input type for signing and submitting transactions with the Ethereum wallet.
|
|
38
|
+
*/
|
|
39
|
+
type SignAndSubmitTransactionInput = {
|
|
40
|
+
data: InputEntryFunctionData;
|
|
41
|
+
} & InputTransactionPluginData;
|
|
42
|
+
/**
|
|
43
|
+
* Parameters type for the useStorageAccount hook.
|
|
44
|
+
*/
|
|
45
|
+
interface UseStorageAccountParams {
|
|
46
|
+
/** The Shelby client */
|
|
47
|
+
client: ShelbyClient;
|
|
48
|
+
/** The connected Ethereum wallet from wagmi's useWalletClient() */
|
|
49
|
+
wallet: EthereumWallet | null | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Result type for the useStorageAccount hook.
|
|
53
|
+
*/
|
|
54
|
+
interface UseStorageAccountResult {
|
|
55
|
+
/** The derived Shelby storage account address */
|
|
56
|
+
storageAccountAddress: AccountAddress | null;
|
|
57
|
+
/** Sign a transaction for Shelby using the connected Ethereum wallet */
|
|
58
|
+
signTransaction: (params: SignTransactionInput) => Promise<{
|
|
59
|
+
authenticator: AccountAuthenticatorAbstraction;
|
|
60
|
+
rawTransaction: AnyRawTransaction;
|
|
61
|
+
}>;
|
|
62
|
+
/** Submit a transaction to Shelby */
|
|
63
|
+
submitTransaction: (params: SubmitTransactionInput) => Promise<{
|
|
64
|
+
hash: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** Sign and submit a transaction to Shelby */
|
|
67
|
+
signAndSubmitTransaction: (params: SignAndSubmitTransactionInput) => Promise<{
|
|
68
|
+
hash: string;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Hook to access Shelby storage functionality with Ethereum wallets.
|
|
73
|
+
*
|
|
74
|
+
* @param params - The Shelby client and connected wallet
|
|
75
|
+
* @returns Storage account address and transaction signing functions
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* import { useWalletClient } from "wagmi";
|
|
80
|
+
*
|
|
81
|
+
* function MyComponent() {
|
|
82
|
+
* const { data: wallet } = useWalletClient();
|
|
83
|
+
*
|
|
84
|
+
* const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount({
|
|
85
|
+
* client: shelbyClient,
|
|
86
|
+
* wallet,
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* // Use storageAccountAddress and signAndSubmitTransaction...
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare function useStorageAccount(params: UseStorageAccountParams): UseStorageAccountResult;
|
|
94
|
+
|
|
95
|
+
export { type EthereumWallet, Network, type SignAndSubmitTransactionInput, type SignTransactionInput, type SubmitTransactionInput, type UseStorageAccountParams, type UseStorageAccountResult, useStorageAccount };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/common/constants.ts
|
|
2
|
+
import { Network as AptosNetwork } from "@aptos-labs/ts-sdk";
|
|
3
|
+
var Network = {
|
|
4
|
+
SHELBYNET: AptosNetwork.SHELBYNET
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/react/useStorageAccount.tsx
|
|
8
|
+
import {
|
|
9
|
+
defaultEthereumAuthenticationFunction,
|
|
10
|
+
EIP1193DerivedPublicKey,
|
|
11
|
+
signAptosTransactionWithEthereum
|
|
12
|
+
} from "@aptos-labs/derived-wallet-ethereum";
|
|
13
|
+
import { UserResponseStatus } from "@aptos-labs/wallet-standard";
|
|
14
|
+
import { useMemo } from "react";
|
|
15
|
+
function useStorageAccount(params) {
|
|
16
|
+
const { client, wallet } = params;
|
|
17
|
+
const domain = typeof window !== "undefined" ? window.location.host : void 0;
|
|
18
|
+
const ethereumAddress = wallet?.account?.address ?? null;
|
|
19
|
+
const derivedPublicKey = useMemo(() => {
|
|
20
|
+
if (!ethereumAddress || !domain) return null;
|
|
21
|
+
return new EIP1193DerivedPublicKey({
|
|
22
|
+
domain,
|
|
23
|
+
ethereumAddress,
|
|
24
|
+
authenticationFunction: defaultEthereumAuthenticationFunction
|
|
25
|
+
});
|
|
26
|
+
}, [ethereumAddress, domain]);
|
|
27
|
+
const storageAccountAddress = useMemo(
|
|
28
|
+
() => derivedPublicKey?.authKey().derivedAddress() ?? null,
|
|
29
|
+
[derivedPublicKey]
|
|
30
|
+
);
|
|
31
|
+
const signTransaction = async (params2) => {
|
|
32
|
+
if (!storageAccountAddress) {
|
|
33
|
+
throw new Error("Storage account address not found");
|
|
34
|
+
}
|
|
35
|
+
if (!ethereumAddress) {
|
|
36
|
+
throw new Error("Wallet not connected");
|
|
37
|
+
}
|
|
38
|
+
const rawTransaction = await client.aptos.transaction.build.simple({
|
|
39
|
+
sender: storageAccountAddress,
|
|
40
|
+
data: params2.data
|
|
41
|
+
});
|
|
42
|
+
const response = await signAptosTransactionWithEthereum({
|
|
43
|
+
eip1193Provider: wallet,
|
|
44
|
+
ethereumAddress,
|
|
45
|
+
authenticationFunction: defaultEthereumAuthenticationFunction,
|
|
46
|
+
rawTransaction
|
|
47
|
+
});
|
|
48
|
+
if (response.status !== UserResponseStatus.APPROVED || !("args" in response)) {
|
|
49
|
+
throw new Error("User rejected the request.");
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
authenticator: response.args,
|
|
53
|
+
rawTransaction
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const submitTransaction = async (params2) => {
|
|
57
|
+
const { transaction, senderAuthenticator, transactionSubmitter } = params2;
|
|
58
|
+
const submitted = await client.aptos.transaction.submit.simple({
|
|
59
|
+
transaction,
|
|
60
|
+
senderAuthenticator,
|
|
61
|
+
transactionSubmitter: transactionSubmitter ?? null
|
|
62
|
+
});
|
|
63
|
+
const committed = await client.aptos.waitForTransaction({
|
|
64
|
+
transactionHash: submitted.hash
|
|
65
|
+
});
|
|
66
|
+
return { hash: committed.hash };
|
|
67
|
+
};
|
|
68
|
+
const signAndSubmitTransaction = async (params2) => {
|
|
69
|
+
const { data, transactionSubmitter } = params2;
|
|
70
|
+
const { authenticator, rawTransaction } = await signTransaction({ data });
|
|
71
|
+
return submitTransaction({
|
|
72
|
+
transaction: rawTransaction,
|
|
73
|
+
senderAuthenticator: authenticator,
|
|
74
|
+
transactionSubmitter
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
storageAccountAddress,
|
|
79
|
+
signTransaction,
|
|
80
|
+
submitTransaction,
|
|
81
|
+
signAndSubmitTransaction
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
Network,
|
|
86
|
+
useStorageAccount
|
|
87
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shelby-protocol/ethereum-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./node": {
|
|
14
|
+
"types": "./dist/node/index.d.ts",
|
|
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"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@biomejs/biome": "2.0.6",
|
|
25
|
+
"@testing-library/dom": "^10.4.0",
|
|
26
|
+
"@testing-library/react": "^16.3.0",
|
|
27
|
+
"@types/react": "19.2.1",
|
|
28
|
+
"@types/react-dom": "19.2.1",
|
|
29
|
+
"happy-dom": "^20.0.10",
|
|
30
|
+
"react": "19.2.1",
|
|
31
|
+
"react-dom": "19.2.1",
|
|
32
|
+
"rimraf": "^6.0.1",
|
|
33
|
+
"tsup": "^8.4.0",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"vitest": "^3.1.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
39
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"react": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"react-dom": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@aptos-labs/derived-wallet-ethereum": "^0.9.0",
|
|
51
|
+
"@aptos-labs/gas-station-client": "^2.0.3",
|
|
52
|
+
"@aptos-labs/ts-sdk": "^5.1.1",
|
|
53
|
+
"@aptos-labs/wallet-standard": "^0.5.2",
|
|
54
|
+
"ethers": "^6.13.5",
|
|
55
|
+
"@shelby-protocol/sdk": "0.0.9"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"lint": "biome check .",
|
|
59
|
+
"fmt": "biome check . --write",
|
|
60
|
+
"build": "tsc --noEmit && (rimraf dist; tsup)",
|
|
61
|
+
"test": "vitest dev",
|
|
62
|
+
"test:once": "vitest run"
|
|
63
|
+
}
|
|
64
|
+
}
|