ryt-sdk 1.0.8 → 1.0.10
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/config.d.ts +82 -19
- package/dist/config.js +83 -17
- package/dist/contract.d.ts +18 -7
- package/dist/contract.js +38 -30
- package/dist/index.d.ts +58 -19
- package/dist/index.js +62 -19
- package/dist/provider.d.ts +56 -23
- package/dist/provider.js +76 -25
- package/dist/utils/ryt.d.ts +69 -0
- package/dist/utils/ryt.js +64 -0
- package/dist/utils/units.d.ts +20 -0
- package/dist/utils/units.js +25 -0
- package/dist/wallet.d.ts +60 -29
- package/dist/wallet.js +90 -42
- package/package.json +2 -9
package/dist/wallet.js
CHANGED
|
@@ -1,81 +1,129 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Unified wallet abstraction for RYT SDK.
|
|
4
|
+
*
|
|
5
|
+
* Supports:
|
|
6
|
+
* - Private key wallets (Node.js / backend)
|
|
7
|
+
* - Browser injected wallets (MetaMask, Rabby, etc.)
|
|
8
|
+
*
|
|
9
|
+
* Automatically adapts behavior based on runtime environment.
|
|
4
10
|
*/
|
|
5
11
|
export default class RYTWallet {
|
|
6
12
|
/**
|
|
7
|
-
* Create a new
|
|
13
|
+
* Create a new wallet instance.
|
|
8
14
|
*
|
|
9
|
-
*
|
|
10
|
-
* @param provider - Optional RYTProvider instance for network access
|
|
15
|
+
* The wallet can operate in two modes:
|
|
11
16
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
17
|
+
* 1. Backend mode (private key provided)
|
|
18
|
+
* - Full signing capability
|
|
19
|
+
* - Used in Node.js scripts, servers, bots
|
|
20
|
+
*
|
|
21
|
+
* 2. Browser mode (injected wallet)
|
|
22
|
+
* - Uses connected wallet (MetaMask, etc.)
|
|
23
|
+
* - No private key required or allowed
|
|
24
|
+
*
|
|
25
|
+
* @param signerOrPrivateKey
|
|
26
|
+
* - string → private key (backend mode)
|
|
27
|
+
* - signer → injected browser signer
|
|
28
|
+
*
|
|
29
|
+
* @param provider Optional provider instance for network access
|
|
30
|
+
*
|
|
31
|
+
* @throws Error if invalid input is provided
|
|
32
|
+
*
|
|
33
|
+
* @example Backend:
|
|
14
34
|
* const wallet = new RYTWallet(PRIVATE_KEY, provider);
|
|
15
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* @example Browser:
|
|
37
|
+
* const wallet = new RYTWallet(signer);
|
|
16
38
|
*/
|
|
17
|
-
constructor(
|
|
18
|
-
if (!
|
|
19
|
-
throw new Error("
|
|
39
|
+
constructor(signerOrPrivateKey, provider) {
|
|
40
|
+
if (!signerOrPrivateKey) {
|
|
41
|
+
throw new Error("Wallet signer or private key is required");
|
|
20
42
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
/**
|
|
44
|
+
* -----------------------------
|
|
45
|
+
* Backend mode (private key)
|
|
46
|
+
* -----------------------------
|
|
47
|
+
*/
|
|
48
|
+
if (typeof signerOrPrivateKey === "string") {
|
|
49
|
+
if (!signerOrPrivateKey.startsWith("0x")) {
|
|
50
|
+
throw new Error("Invalid private key format (must start with 0x)");
|
|
51
|
+
}
|
|
52
|
+
const rpcProvider = provider?.getProvider();
|
|
53
|
+
this.signer = rpcProvider
|
|
54
|
+
? new ethers.Wallet(signerOrPrivateKey, rpcProvider)
|
|
55
|
+
: new ethers.Wallet(signerOrPrivateKey);
|
|
56
|
+
return;
|
|
24
57
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
58
|
+
/**
|
|
59
|
+
* -----------------------------
|
|
60
|
+
* Browser mode (injected signer)
|
|
61
|
+
* -----------------------------
|
|
62
|
+
*/
|
|
63
|
+
this.signer = signerOrPrivateKey;
|
|
29
64
|
}
|
|
30
65
|
/**
|
|
31
|
-
*
|
|
66
|
+
* Get wallet address.
|
|
32
67
|
*
|
|
33
68
|
* @returns Wallet public address
|
|
34
69
|
*
|
|
35
70
|
* @example
|
|
36
|
-
*
|
|
37
|
-
* const address = wallet.getAddress();
|
|
38
|
-
* ```
|
|
71
|
+
* const address = await wallet.getAddress();
|
|
39
72
|
*/
|
|
40
|
-
getAddress() {
|
|
41
|
-
return this.
|
|
73
|
+
async getAddress() {
|
|
74
|
+
return await this.signer.getAddress();
|
|
42
75
|
}
|
|
43
76
|
/**
|
|
44
|
-
* Get wallet balance in wei
|
|
77
|
+
* Get wallet balance in wei.
|
|
45
78
|
*
|
|
46
|
-
*
|
|
79
|
+
* Requires connected provider (RPC or injected).
|
|
47
80
|
*
|
|
48
|
-
* @
|
|
81
|
+
* @returns Balance in wei
|
|
49
82
|
*
|
|
50
|
-
* @
|
|
51
|
-
* ```ts
|
|
52
|
-
* const balance = await wallet.getBalance();
|
|
53
|
-
* ```
|
|
83
|
+
* @throws Error if provider is not available
|
|
54
84
|
*/
|
|
55
85
|
async getBalance() {
|
|
56
|
-
if (!this.
|
|
57
|
-
throw new Error("
|
|
86
|
+
if (!this.signer.provider) {
|
|
87
|
+
throw new Error("No provider available. Connect wallet or attach provider.");
|
|
58
88
|
}
|
|
59
|
-
return await this.
|
|
89
|
+
return await this.signer.provider.getBalance(await this.signer.getAddress());
|
|
60
90
|
}
|
|
61
91
|
/**
|
|
62
|
-
* Send a
|
|
92
|
+
* Send a blockchain transaction.
|
|
93
|
+
*
|
|
94
|
+
* Works in both:
|
|
95
|
+
* - Backend (signed via private key)
|
|
96
|
+
* - Browser (signed via MetaMask / injected wallet)
|
|
63
97
|
*
|
|
64
|
-
* @param tx
|
|
65
|
-
* @returns
|
|
98
|
+
* @param tx Transaction request object
|
|
99
|
+
* @returns Transaction response
|
|
66
100
|
*
|
|
67
101
|
* @example
|
|
68
|
-
* ```ts
|
|
69
102
|
* await wallet.sendTransaction({
|
|
70
|
-
* to: "
|
|
71
|
-
* value:
|
|
103
|
+
* to: "0x...",
|
|
104
|
+
* value: "0.01"
|
|
72
105
|
* });
|
|
73
|
-
* ```
|
|
74
106
|
*/
|
|
75
107
|
async sendTransaction(tx) {
|
|
76
|
-
if (!this.
|
|
108
|
+
if (!this.signer) {
|
|
77
109
|
throw new Error("Wallet not initialized");
|
|
78
110
|
}
|
|
79
|
-
return await this.
|
|
111
|
+
return await this.signer.sendTransaction(tx);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if wallet is connected to a provider.
|
|
115
|
+
*
|
|
116
|
+
* @returns true if provider is available
|
|
117
|
+
*/
|
|
118
|
+
isConnected() {
|
|
119
|
+
return !!this.signer.provider;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get underlying signer instance.
|
|
123
|
+
*
|
|
124
|
+
* Useful for advanced contract interactions.
|
|
125
|
+
*/
|
|
126
|
+
getSigner() {
|
|
127
|
+
return this.signer;
|
|
80
128
|
}
|
|
81
129
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ryt-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.10",
|
|
5
5
|
"description": "RYT blockchain SDK for provider, wallet, and smart contract interactions",
|
|
6
6
|
"author": "Muhammad Hammad Mubeen",
|
|
7
7
|
"license": "MIT",
|
|
@@ -59,12 +59,5 @@
|
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
|
-
"
|
|
63
|
-
"type": "git",
|
|
64
|
-
"url": "https://github.com/Hammad-Mubeen/ryt-sdk.git"
|
|
65
|
-
},
|
|
66
|
-
"homepage": "https://ryt-docs.vercel.app",
|
|
67
|
-
"bugs": {
|
|
68
|
-
"url": "https://github.com/Hammad-Mubeen/ryt-sdk/issues"
|
|
69
|
-
}
|
|
62
|
+
"homepage": "https://ryt-docs.vercel.app"
|
|
70
63
|
}
|