near-kit 0.0.0 → 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.
Files changed (128) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +371 -2
  3. package/dist/contracts/contract.d.ts +63 -0
  4. package/dist/contracts/contract.d.ts.map +1 -0
  5. package/dist/contracts/contract.js +42 -0
  6. package/dist/contracts/contract.js.map +1 -0
  7. package/dist/contracts/index.d.ts +5 -0
  8. package/dist/contracts/index.d.ts.map +1 -0
  9. package/dist/contracts/index.js +5 -0
  10. package/dist/contracts/index.js.map +1 -0
  11. package/dist/core/actions.d.ts +193 -0
  12. package/dist/core/actions.d.ts.map +1 -0
  13. package/dist/core/actions.js +195 -0
  14. package/dist/core/actions.js.map +1 -0
  15. package/dist/core/config-schemas.d.ts +179 -0
  16. package/dist/core/config-schemas.d.ts.map +1 -0
  17. package/dist/core/config-schemas.js +169 -0
  18. package/dist/core/config-schemas.js.map +1 -0
  19. package/dist/core/constants.d.ts +43 -0
  20. package/dist/core/constants.d.ts.map +1 -0
  21. package/dist/core/constants.js +49 -0
  22. package/dist/core/constants.js.map +1 -0
  23. package/dist/core/near.d.ts +301 -0
  24. package/dist/core/near.d.ts.map +1 -0
  25. package/dist/core/near.js +504 -0
  26. package/dist/core/near.js.map +1 -0
  27. package/dist/core/nonce-manager.d.ts +39 -0
  28. package/dist/core/nonce-manager.d.ts.map +1 -0
  29. package/dist/core/nonce-manager.js +73 -0
  30. package/dist/core/nonce-manager.js.map +1 -0
  31. package/dist/core/rpc/rpc-error-handler.d.ts +60 -0
  32. package/dist/core/rpc/rpc-error-handler.d.ts.map +1 -0
  33. package/dist/core/rpc/rpc-error-handler.js +324 -0
  34. package/dist/core/rpc/rpc-error-handler.js.map +1 -0
  35. package/dist/core/rpc/rpc-schemas.d.ts +1812 -0
  36. package/dist/core/rpc/rpc-schemas.d.ts.map +1 -0
  37. package/dist/core/rpc/rpc-schemas.js +424 -0
  38. package/dist/core/rpc/rpc-schemas.js.map +1 -0
  39. package/dist/core/rpc/rpc.d.ts +117 -0
  40. package/dist/core/rpc/rpc.d.ts.map +1 -0
  41. package/dist/core/rpc/rpc.js +325 -0
  42. package/dist/core/rpc/rpc.js.map +1 -0
  43. package/dist/core/schema.d.ts +1188 -0
  44. package/dist/core/schema.d.ts.map +1 -0
  45. package/dist/core/schema.js +396 -0
  46. package/dist/core/schema.js.map +1 -0
  47. package/dist/core/transaction.d.ts +390 -0
  48. package/dist/core/transaction.d.ts.map +1 -0
  49. package/dist/core/transaction.js +649 -0
  50. package/dist/core/transaction.js.map +1 -0
  51. package/dist/core/types.d.ts +271 -0
  52. package/dist/core/types.d.ts.map +1 -0
  53. package/dist/core/types.js +9 -0
  54. package/dist/core/types.js.map +1 -0
  55. package/dist/errors/index.d.ts +226 -0
  56. package/dist/errors/index.d.ts.map +1 -0
  57. package/dist/errors/index.js +366 -0
  58. package/dist/errors/index.js.map +1 -0
  59. package/dist/index.d.ts +16 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +23 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/keys/credential-schemas.d.ts +98 -0
  64. package/dist/keys/credential-schemas.d.ts.map +1 -0
  65. package/dist/keys/credential-schemas.js +128 -0
  66. package/dist/keys/credential-schemas.js.map +1 -0
  67. package/dist/keys/file-keystore.d.ts +130 -0
  68. package/dist/keys/file-keystore.d.ts.map +1 -0
  69. package/dist/keys/file-keystore.js +266 -0
  70. package/dist/keys/file-keystore.js.map +1 -0
  71. package/dist/keys/in-memory-keystore.d.ts +71 -0
  72. package/dist/keys/in-memory-keystore.d.ts.map +1 -0
  73. package/dist/keys/in-memory-keystore.js +85 -0
  74. package/dist/keys/in-memory-keystore.js.map +1 -0
  75. package/dist/keys/index.d.ts +12 -0
  76. package/dist/keys/index.d.ts.map +1 -0
  77. package/dist/keys/index.js +18 -0
  78. package/dist/keys/index.js.map +1 -0
  79. package/dist/keys/native-keystore.d.ts +111 -0
  80. package/dist/keys/native-keystore.d.ts.map +1 -0
  81. package/dist/keys/native-keystore.js +167 -0
  82. package/dist/keys/native-keystore.js.map +1 -0
  83. package/dist/sandbox/index.d.ts +6 -0
  84. package/dist/sandbox/index.d.ts.map +1 -0
  85. package/dist/sandbox/index.js +5 -0
  86. package/dist/sandbox/index.js.map +1 -0
  87. package/dist/sandbox/sandbox.d.ts +55 -0
  88. package/dist/sandbox/sandbox.d.ts.map +1 -0
  89. package/dist/sandbox/sandbox.js +341 -0
  90. package/dist/sandbox/sandbox.js.map +1 -0
  91. package/dist/utils/amount.d.ts +76 -0
  92. package/dist/utils/amount.d.ts.map +1 -0
  93. package/dist/utils/amount.js +137 -0
  94. package/dist/utils/amount.js.map +1 -0
  95. package/dist/utils/gas.d.ts +69 -0
  96. package/dist/utils/gas.d.ts.map +1 -0
  97. package/dist/utils/gas.js +92 -0
  98. package/dist/utils/gas.js.map +1 -0
  99. package/dist/utils/index.d.ts +14 -0
  100. package/dist/utils/index.d.ts.map +1 -0
  101. package/dist/utils/index.js +14 -0
  102. package/dist/utils/index.js.map +1 -0
  103. package/dist/utils/key.d.ts +117 -0
  104. package/dist/utils/key.d.ts.map +1 -0
  105. package/dist/utils/key.js +270 -0
  106. package/dist/utils/key.js.map +1 -0
  107. package/dist/utils/nep413.d.ts +97 -0
  108. package/dist/utils/nep413.d.ts.map +1 -0
  109. package/dist/utils/nep413.js +154 -0
  110. package/dist/utils/nep413.js.map +1 -0
  111. package/dist/utils/validation.d.ts +114 -0
  112. package/dist/utils/validation.d.ts.map +1 -0
  113. package/dist/utils/validation.js +150 -0
  114. package/dist/utils/validation.js.map +1 -0
  115. package/dist/wallets/adapters.d.ts +119 -0
  116. package/dist/wallets/adapters.d.ts.map +1 -0
  117. package/dist/wallets/adapters.js +267 -0
  118. package/dist/wallets/adapters.js.map +1 -0
  119. package/dist/wallets/index.d.ts +11 -0
  120. package/dist/wallets/index.d.ts.map +1 -0
  121. package/dist/wallets/index.js +2 -0
  122. package/dist/wallets/index.js.map +1 -0
  123. package/dist/wallets/types.d.ts +99 -0
  124. package/dist/wallets/types.d.ts.map +1 -0
  125. package/dist/wallets/types.js +10 -0
  126. package/dist/wallets/types.js.map +1 -0
  127. package/package.json +78 -7
  128. package/index.js +0 -1
@@ -0,0 +1,130 @@
1
+ /**
2
+ * File-based key store implementation compatible with NEAR CLI.
3
+ */
4
+ import type { KeyPair, KeyStore } from "../core/types.js";
5
+ import { type Network } from "./credential-schemas.js";
6
+ /**
7
+ * File-based key store compatible with NEAR CLI format.
8
+ *
9
+ * This keystore is fully compatible with the NEAR CLI credential format,
10
+ * storing keys in `~/.near-credentials/` with network subdirectories.
11
+ *
12
+ * ## Directory Structure
13
+ * ```
14
+ * ~/.near-credentials/
15
+ * ├── mainnet/
16
+ * │ └── account.near.json
17
+ * ├── testnet/
18
+ * │ ├── account.testnet.json
19
+ * │ └── account.testnet/ # Multi-key format (read-only)
20
+ * │ └── ed25519_PublicKey.json
21
+ * └── implicit/
22
+ * └── accountId.json
23
+ * ```
24
+ *
25
+ * ## Features
26
+ * - Compatible with near-cli and near-cli-rs
27
+ * - Supports network subdirectories (mainnet, testnet, etc.)
28
+ * - Reads multi-key format (account.near/ed25519_*.json)
29
+ * - Writes simple format (account.near.json)
30
+ * - Preserves optional seed phrase fields
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Default: ~/.near-credentials/testnet/
35
+ * const keyStore = new FileKeyStore("~/.near-credentials", "testnet")
36
+ *
37
+ * // Custom path
38
+ * const keyStore = new FileKeyStore("/path/to/keys", "mainnet")
39
+ *
40
+ * // Add a key
41
+ * await keyStore.add("example.testnet", keyPair)
42
+ * ```
43
+ */
44
+ export declare class FileKeyStore implements KeyStore {
45
+ private readonly basePath;
46
+ private readonly network;
47
+ /**
48
+ * Create a new file-based keystore.
49
+ *
50
+ * @param basePath - Base directory path (default: `"~/.near-credentials"`).
51
+ * @param network - Network subdirectory (e.g., `"testnet"`, `"mainnet"`).
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // Store in ~/.near-credentials/testnet/
56
+ * const keyStore = new FileKeyStore("~/.near-credentials", "testnet")
57
+ *
58
+ * // Store in custom directory without network subdirectory
59
+ * const keyStore = new FileKeyStore("/my/keys")
60
+ * ```
61
+ */
62
+ constructor(basePath?: string, network?: Network);
63
+ /**
64
+ * Get the directory path for storing keys.
65
+ * Includes network subdirectory if specified.
66
+ * @internal
67
+ */
68
+ private getNetworkPath;
69
+ /**
70
+ * Get the file path for a specific account.
71
+ * Uses simple format: `{network}/{accountId}.json`.
72
+ * @internal
73
+ */
74
+ private getKeyFilePath;
75
+ /**
76
+ * Get the multi-key directory path for an account.
77
+ * Format: `{network}/{accountId}/`.
78
+ * @internal
79
+ */
80
+ private getMultiKeyDirPath;
81
+ /**
82
+ * Add a key to the keystore
83
+ *
84
+ * Stores in NEAR CLI format with network subdirectory.
85
+ * Uses simple format (one file per account).
86
+ *
87
+ * @param accountId - NEAR account ID
88
+ * @param key - Key pair to store
89
+ * @param options - Optional metadata (seed phrase, derivation path)
90
+ */
91
+ add(accountId: string, key: KeyPair, options?: {
92
+ seedPhrase?: string;
93
+ derivationPath?: string;
94
+ implicitAccountId?: string;
95
+ }): Promise<void>;
96
+ /**
97
+ * Get a key from the keystore
98
+ *
99
+ * Attempts to read in this order:
100
+ * 1. Simple format: {network}/{accountId}.json
101
+ * 2. Multi-key format: {network}/{accountId}/ed25519_*.json (first match)
102
+ *
103
+ * @param accountId - NEAR account ID
104
+ * @returns Key pair if found, null otherwise
105
+ */
106
+ get(accountId: string): Promise<KeyPair | null>;
107
+ /**
108
+ * Try to read from multi-key directory format.
109
+ * Format: `{network}/{accountId}/ed25519_*.json`.
110
+ * @internal
111
+ */
112
+ private getFromMultiKeyDir;
113
+ /**
114
+ * Remove a key from the keystore
115
+ *
116
+ * Removes both simple format file and multi-key directory if they exist
117
+ *
118
+ * @param accountId - NEAR account ID
119
+ */
120
+ remove(accountId: string): Promise<void>;
121
+ /**
122
+ * List all account IDs in the keystore
123
+ *
124
+ * Returns account IDs from both simple format files and multi-key directories
125
+ *
126
+ * @returns Array of account IDs
127
+ */
128
+ list(): Promise<string[]>;
129
+ }
130
+ //# sourceMappingURL=file-keystore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-keystore.d.ts","sourceRoot":"","sources":["../../src/keys/file-keystore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEzD,OAAO,EAEL,KAAK,OAAO,EAEb,MAAM,yBAAyB,CAAA;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,YAAa,YAAW,QAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C;;;;;;;;;;;;;;OAcG;gBACS,QAAQ,SAAwB,EAAE,OAAO,CAAC,EAAE,OAAO;IAS/D;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAItB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAItB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;;;;;;;OASG;IACG,GAAG,CACP,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,OAAO,EACZ,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAC3B,GACA,OAAO,CAAC,IAAI,CAAC;IA6BhB;;;;;;;;;OASG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IA0BrD;;;;OAIG;YACW,kBAAkB;IAkChC;;;;;;OAMG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B9C;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAwChC"}
@@ -0,0 +1,266 @@
1
+ import { parseKey } from "../utils/key.js";
2
+ import { parseCredentialFile, } from "./credential-schemas.js";
3
+ /**
4
+ * File-based key store compatible with NEAR CLI format.
5
+ *
6
+ * This keystore is fully compatible with the NEAR CLI credential format,
7
+ * storing keys in `~/.near-credentials/` with network subdirectories.
8
+ *
9
+ * ## Directory Structure
10
+ * ```
11
+ * ~/.near-credentials/
12
+ * ├── mainnet/
13
+ * │ └── account.near.json
14
+ * ├── testnet/
15
+ * │ ├── account.testnet.json
16
+ * │ └── account.testnet/ # Multi-key format (read-only)
17
+ * │ └── ed25519_PublicKey.json
18
+ * └── implicit/
19
+ * └── accountId.json
20
+ * ```
21
+ *
22
+ * ## Features
23
+ * - Compatible with near-cli and near-cli-rs
24
+ * - Supports network subdirectories (mainnet, testnet, etc.)
25
+ * - Reads multi-key format (account.near/ed25519_*.json)
26
+ * - Writes simple format (account.near.json)
27
+ * - Preserves optional seed phrase fields
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Default: ~/.near-credentials/testnet/
32
+ * const keyStore = new FileKeyStore("~/.near-credentials", "testnet")
33
+ *
34
+ * // Custom path
35
+ * const keyStore = new FileKeyStore("/path/to/keys", "mainnet")
36
+ *
37
+ * // Add a key
38
+ * await keyStore.add("example.testnet", keyPair)
39
+ * ```
40
+ */
41
+ export class FileKeyStore {
42
+ /**
43
+ * Create a new file-based keystore.
44
+ *
45
+ * @param basePath - Base directory path (default: `"~/.near-credentials"`).
46
+ * @param network - Network subdirectory (e.g., `"testnet"`, `"mainnet"`).
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Store in ~/.near-credentials/testnet/
51
+ * const keyStore = new FileKeyStore("~/.near-credentials", "testnet")
52
+ *
53
+ * // Store in custom directory without network subdirectory
54
+ * const keyStore = new FileKeyStore("/my/keys")
55
+ * ```
56
+ */
57
+ constructor(basePath = "~/.near-credentials", network) {
58
+ // Expand home directory
59
+ this.basePath = basePath.replace(/^~/, process.env["HOME"] || process.env["USERPROFILE"] || "");
60
+ this.network = network;
61
+ }
62
+ /**
63
+ * Get the directory path for storing keys.
64
+ * Includes network subdirectory if specified.
65
+ * @internal
66
+ */
67
+ getNetworkPath() {
68
+ return this.network ? `${this.basePath}/${this.network}` : this.basePath;
69
+ }
70
+ /**
71
+ * Get the file path for a specific account.
72
+ * Uses simple format: `{network}/{accountId}.json`.
73
+ * @internal
74
+ */
75
+ getKeyFilePath(accountId) {
76
+ return `${this.getNetworkPath()}/${accountId}.json`;
77
+ }
78
+ /**
79
+ * Get the multi-key directory path for an account.
80
+ * Format: `{network}/{accountId}/`.
81
+ * @internal
82
+ */
83
+ getMultiKeyDirPath(accountId) {
84
+ return `${this.getNetworkPath()}/${accountId}`;
85
+ }
86
+ /**
87
+ * Add a key to the keystore
88
+ *
89
+ * Stores in NEAR CLI format with network subdirectory.
90
+ * Uses simple format (one file per account).
91
+ *
92
+ * @param accountId - NEAR account ID
93
+ * @param key - Key pair to store
94
+ * @param options - Optional metadata (seed phrase, derivation path)
95
+ */
96
+ async add(accountId, key, options) {
97
+ const fs = await import("node:fs/promises");
98
+ // Ensure directory exists
99
+ const networkPath = this.getNetworkPath();
100
+ await fs.mkdir(networkPath, { recursive: true });
101
+ // Create credential data in NEAR CLI format
102
+ const keyData = {
103
+ account_id: accountId,
104
+ public_key: key.publicKey.toString(),
105
+ private_key: key.secretKey, // Use private_key (not secret_key)
106
+ };
107
+ // Add optional fields if provided
108
+ if (options?.seedPhrase) {
109
+ keyData.master_seed_phrase = options.seedPhrase;
110
+ }
111
+ if (options?.derivationPath) {
112
+ keyData.seed_phrase_hd_path = options.derivationPath;
113
+ }
114
+ if (options?.implicitAccountId) {
115
+ keyData.implicit_account_id = options.implicitAccountId;
116
+ }
117
+ const filePath = this.getKeyFilePath(accountId);
118
+ await fs.writeFile(filePath, JSON.stringify(keyData, null, 2));
119
+ }
120
+ /**
121
+ * Get a key from the keystore
122
+ *
123
+ * Attempts to read in this order:
124
+ * 1. Simple format: {network}/{accountId}.json
125
+ * 2. Multi-key format: {network}/{accountId}/ed25519_*.json (first match)
126
+ *
127
+ * @param accountId - NEAR account ID
128
+ * @returns Key pair if found, null otherwise
129
+ */
130
+ async get(accountId) {
131
+ try {
132
+ const fs = await import("node:fs/promises");
133
+ // Try simple format first
134
+ const filePath = this.getKeyFilePath(accountId);
135
+ try {
136
+ const content = await fs.readFile(filePath, "utf-8");
137
+ const keyData = parseCredentialFile(JSON.parse(content));
138
+ return parseKey(keyData.private_key);
139
+ }
140
+ catch (error) {
141
+ // If simple format fails, try multi-key format
142
+ if (error.code === "ENOENT") {
143
+ return await this.getFromMultiKeyDir(accountId);
144
+ }
145
+ throw error;
146
+ }
147
+ }
148
+ catch (error) {
149
+ // File doesn't exist or can't be read
150
+ if (error.code === "ENOENT") {
151
+ return null;
152
+ }
153
+ throw error;
154
+ }
155
+ }
156
+ /**
157
+ * Try to read from multi-key directory format.
158
+ * Format: `{network}/{accountId}/ed25519_*.json`.
159
+ * @internal
160
+ */
161
+ async getFromMultiKeyDir(accountId) {
162
+ try {
163
+ const fs = await import("node:fs/promises");
164
+ const multiKeyDir = this.getMultiKeyDirPath(accountId);
165
+ // Check if directory exists
166
+ const stat = await fs.stat(multiKeyDir);
167
+ if (!stat.isDirectory()) {
168
+ return null;
169
+ }
170
+ // Read all files in the directory
171
+ const files = await fs.readdir(multiKeyDir);
172
+ // Find first ed25519 key file
173
+ const keyFile = files.find((file) => file.startsWith("ed25519_") && file.endsWith(".json"));
174
+ if (!keyFile) {
175
+ return null;
176
+ }
177
+ // Read and parse the key file
178
+ const content = await fs.readFile(`${multiKeyDir}/${keyFile}`, "utf-8");
179
+ const keyData = parseCredentialFile(JSON.parse(content));
180
+ return parseKey(keyData.private_key);
181
+ }
182
+ catch (error) {
183
+ if (error.code === "ENOENT") {
184
+ return null;
185
+ }
186
+ throw error;
187
+ }
188
+ }
189
+ /**
190
+ * Remove a key from the keystore
191
+ *
192
+ * Removes both simple format file and multi-key directory if they exist
193
+ *
194
+ * @param accountId - NEAR account ID
195
+ */
196
+ async remove(accountId) {
197
+ const fs = await import("node:fs/promises");
198
+ // Remove simple format file
199
+ const filePath = this.getKeyFilePath(accountId);
200
+ try {
201
+ await fs.unlink(filePath);
202
+ }
203
+ catch (error) {
204
+ // Ignore if file doesn't exist
205
+ if (error.code !== "ENOENT") {
206
+ throw error;
207
+ }
208
+ }
209
+ // Remove multi-key directory if it exists
210
+ const multiKeyDir = this.getMultiKeyDirPath(accountId);
211
+ try {
212
+ await fs.rm(multiKeyDir, { recursive: true, force: true });
213
+ }
214
+ catch (error) {
215
+ // Ignore if directory doesn't exist
216
+ if (error.code !== "ENOENT") {
217
+ throw error;
218
+ }
219
+ }
220
+ }
221
+ /**
222
+ * List all account IDs in the keystore
223
+ *
224
+ * Returns account IDs from both simple format files and multi-key directories
225
+ *
226
+ * @returns Array of account IDs
227
+ */
228
+ async list() {
229
+ try {
230
+ const fs = await import("node:fs/promises");
231
+ const networkPath = this.getNetworkPath();
232
+ const entries = await fs.readdir(networkPath, { withFileTypes: true });
233
+ const accountIds = new Set();
234
+ for (const entry of entries) {
235
+ if (entry.isFile() && entry.name.endsWith(".json")) {
236
+ // Simple format: account.json
237
+ accountIds.add(entry.name.replace(".json", ""));
238
+ }
239
+ else if (entry.isDirectory()) {
240
+ // Multi-key format: account/
241
+ // Check if directory contains key files
242
+ const dirPath = `${networkPath}/${entry.name}`;
243
+ try {
244
+ const files = await fs.readdir(dirPath);
245
+ const hasKeyFiles = files.some((file) => file.startsWith("ed25519_") && file.endsWith(".json"));
246
+ if (hasKeyFiles) {
247
+ accountIds.add(entry.name);
248
+ }
249
+ }
250
+ catch {
251
+ // Ignore errors reading subdirectories
252
+ }
253
+ }
254
+ }
255
+ return Array.from(accountIds).sort();
256
+ }
257
+ catch (error) {
258
+ // Directory doesn't exist
259
+ if (error.code === "ENOENT") {
260
+ return [];
261
+ }
262
+ throw error;
263
+ }
264
+ }
265
+ }
266
+ //# sourceMappingURL=file-keystore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-keystore.js","sourceRoot":"","sources":["../../src/keys/file-keystore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAGL,mBAAmB,GACpB,MAAM,yBAAyB,CAAA;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,YAAY;IAIvB;;;;;;;;;;;;;;OAcG;IACH,YAAY,QAAQ,GAAG,qBAAqB,EAAE,OAAiB;QAC7D,wBAAwB;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAC9B,IAAI,EACJ,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CACxD,CAAA;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACK,cAAc;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAA;IAC1E,CAAC;IAED;;;;OAIG;IACK,cAAc,CAAC,SAAiB;QACtC,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,SAAS,OAAO,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACK,kBAAkB,CAAC,SAAiB;QAC1C,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,SAAS,EAAE,CAAA;IAChD,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,GAAG,CACP,SAAiB,EACjB,GAAY,EACZ,OAIC;QAED,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAA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AC;oBAAC,MAAM,CAAC;wBACP,uCAAuC;oBACzC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,0BAA0B;YAC1B,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvD,OAAO,EAAE,CAAA;YACX,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * In-memory key store implementation.
3
+ */
4
+ import type { KeyPair, KeyStore } from "../core/types.js";
5
+ /**
6
+ * In-memory key store.
7
+ *
8
+ * Keys are stored in memory and lost when the process exits.
9
+ * Useful for testing, development, and temporary key storage.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Empty keystore
14
+ * const keyStore = new InMemoryKeyStore()
15
+ *
16
+ * // Pre-populate with keys
17
+ * const keyStore = new InMemoryKeyStore({
18
+ * "alice.near": "ed25519:...",
19
+ * "bob.near": "ed25519:..."
20
+ * })
21
+ * ```
22
+ */
23
+ export declare class InMemoryKeyStore implements KeyStore {
24
+ private keys;
25
+ /**
26
+ * Create a new in-memory keystore.
27
+ *
28
+ * @param initialKeys - Optional initial keys to populate the store
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const keyStore = new InMemoryKeyStore({
33
+ * "test.near": "ed25519:3D4c2v8K5x..."
34
+ * })
35
+ * ```
36
+ */
37
+ constructor(initialKeys?: Record<string, string>);
38
+ /**
39
+ * Add a key to the keystore
40
+ *
41
+ * @param accountId - NEAR account ID
42
+ * @param key - Key pair to store
43
+ */
44
+ add(accountId: string, key: KeyPair): Promise<void>;
45
+ /**
46
+ * Get a key from the keystore
47
+ *
48
+ * @param accountId - NEAR account ID
49
+ * @returns Key pair if found, null otherwise
50
+ */
51
+ get(accountId: string): Promise<KeyPair | null>;
52
+ /**
53
+ * Remove a key from the keystore
54
+ *
55
+ * @param accountId - NEAR account ID
56
+ */
57
+ remove(accountId: string): Promise<void>;
58
+ /**
59
+ * List all account IDs in the keystore
60
+ *
61
+ * @returns Array of account IDs
62
+ */
63
+ list(): Promise<string[]>;
64
+ /**
65
+ * Clear all keys from the keystore
66
+ *
67
+ * Useful for testing cleanup.
68
+ */
69
+ clear(): void;
70
+ }
71
+ //# sourceMappingURL=in-memory-keystore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-keystore.d.ts","sourceRoot":"","sources":["../../src/keys/in-memory-keystore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAGzD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,OAAO,CAAC,IAAI,CAAsB;IAElC;;;;;;;;;;;OAWG;gBACS,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWhD;;;;;OAKG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;;OAKG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAIrD;;;;OAIG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI/B;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,85 @@
1
+ import { parseKey } from "../utils/key.js";
2
+ /**
3
+ * In-memory key store.
4
+ *
5
+ * Keys are stored in memory and lost when the process exits.
6
+ * Useful for testing, development, and temporary key storage.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Empty keystore
11
+ * const keyStore = new InMemoryKeyStore()
12
+ *
13
+ * // Pre-populate with keys
14
+ * const keyStore = new InMemoryKeyStore({
15
+ * "alice.near": "ed25519:...",
16
+ * "bob.near": "ed25519:..."
17
+ * })
18
+ * ```
19
+ */
20
+ export class InMemoryKeyStore {
21
+ /**
22
+ * Create a new in-memory keystore.
23
+ *
24
+ * @param initialKeys - Optional initial keys to populate the store
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const keyStore = new InMemoryKeyStore({
29
+ * "test.near": "ed25519:3D4c2v8K5x..."
30
+ * })
31
+ * ```
32
+ */
33
+ constructor(initialKeys) {
34
+ this.keys = new Map();
35
+ if (initialKeys) {
36
+ for (const [accountId, keyString] of Object.entries(initialKeys)) {
37
+ const keyPair = parseKey(keyString);
38
+ this.keys.set(accountId, keyPair);
39
+ }
40
+ }
41
+ }
42
+ /**
43
+ * Add a key to the keystore
44
+ *
45
+ * @param accountId - NEAR account ID
46
+ * @param key - Key pair to store
47
+ */
48
+ async add(accountId, key) {
49
+ this.keys.set(accountId, key);
50
+ }
51
+ /**
52
+ * Get a key from the keystore
53
+ *
54
+ * @param accountId - NEAR account ID
55
+ * @returns Key pair if found, null otherwise
56
+ */
57
+ async get(accountId) {
58
+ return this.keys.get(accountId) ?? null;
59
+ }
60
+ /**
61
+ * Remove a key from the keystore
62
+ *
63
+ * @param accountId - NEAR account ID
64
+ */
65
+ async remove(accountId) {
66
+ this.keys.delete(accountId);
67
+ }
68
+ /**
69
+ * List all account IDs in the keystore
70
+ *
71
+ * @returns Array of account IDs
72
+ */
73
+ async list() {
74
+ return Array.from(this.keys.keys());
75
+ }
76
+ /**
77
+ * Clear all keys from the keystore
78
+ *
79
+ * Useful for testing cleanup.
80
+ */
81
+ clear() {
82
+ this.keys.clear();
83
+ }
84
+ }
85
+ //# sourceMappingURL=in-memory-keystore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-keystore.js","sourceRoot":"","sources":["../../src/keys/in-memory-keystore.ts"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link InMemoryKeyStore} for ephemeral keys, {@link FileKeyStore}
6
+ * for NEAR-CLI compatible disk storage, and credential schemas for working
7
+ * with existing NEAR tooling.
8
+ */
9
+ export * from "./credential-schemas.js";
10
+ export * from "./file-keystore.js";
11
+ export * from "./in-memory-keystore.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Key management module.
3
+ *
4
+ * @remarks
5
+ * Includes {@link InMemoryKeyStore} for ephemeral keys, {@link FileKeyStore}
6
+ * for NEAR-CLI compatible disk storage, and credential schemas for working
7
+ * with existing NEAR tooling.
8
+ */
9
+ export * from "./credential-schemas.js";
10
+ export * from "./file-keystore.js";
11
+ export * from "./in-memory-keystore.js";
12
+ // NativeKeyStore contains native Node.js dependencies and cannot be bundled for browsers
13
+ // For Node.js/Bun environments, import directly:
14
+ // import { NativeKeyStore } from "near-kit/dist/keys/native-keystore.js"
15
+ //
16
+ // For browser environments, use InMemoryKeyStore instead
17
+ // export * from "./native-keystore.js"
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AAEvC,yFAAyF;AACzF,iDAAiD;AACjD,yEAAyE;AACzE,EAAE;AACF,yDAAyD;AACzD,uCAAuC"}