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.
- package/LICENSE +21 -0
- package/README.md +371 -2
- package/dist/contracts/contract.d.ts +63 -0
- package/dist/contracts/contract.d.ts.map +1 -0
- package/dist/contracts/contract.js +42 -0
- package/dist/contracts/contract.js.map +1 -0
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +5 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/core/actions.d.ts +193 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +195 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/config-schemas.d.ts +179 -0
- package/dist/core/config-schemas.d.ts.map +1 -0
- package/dist/core/config-schemas.js +169 -0
- package/dist/core/config-schemas.js.map +1 -0
- package/dist/core/constants.d.ts +43 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +49 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/near.d.ts +301 -0
- package/dist/core/near.d.ts.map +1 -0
- package/dist/core/near.js +504 -0
- package/dist/core/near.js.map +1 -0
- package/dist/core/nonce-manager.d.ts +39 -0
- package/dist/core/nonce-manager.d.ts.map +1 -0
- package/dist/core/nonce-manager.js +73 -0
- package/dist/core/nonce-manager.js.map +1 -0
- package/dist/core/rpc/rpc-error-handler.d.ts +60 -0
- package/dist/core/rpc/rpc-error-handler.d.ts.map +1 -0
- package/dist/core/rpc/rpc-error-handler.js +324 -0
- package/dist/core/rpc/rpc-error-handler.js.map +1 -0
- package/dist/core/rpc/rpc-schemas.d.ts +1812 -0
- package/dist/core/rpc/rpc-schemas.d.ts.map +1 -0
- package/dist/core/rpc/rpc-schemas.js +424 -0
- package/dist/core/rpc/rpc-schemas.js.map +1 -0
- package/dist/core/rpc/rpc.d.ts +117 -0
- package/dist/core/rpc/rpc.d.ts.map +1 -0
- package/dist/core/rpc/rpc.js +325 -0
- package/dist/core/rpc/rpc.js.map +1 -0
- package/dist/core/schema.d.ts +1188 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +396 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/transaction.d.ts +390 -0
- package/dist/core/transaction.d.ts.map +1 -0
- package/dist/core/transaction.js +649 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/core/types.d.ts +271 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +9 -0
- package/dist/core/types.js.map +1 -0
- package/dist/errors/index.d.ts +226 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +366 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/credential-schemas.d.ts +98 -0
- package/dist/keys/credential-schemas.d.ts.map +1 -0
- package/dist/keys/credential-schemas.js +128 -0
- package/dist/keys/credential-schemas.js.map +1 -0
- package/dist/keys/file-keystore.d.ts +130 -0
- package/dist/keys/file-keystore.d.ts.map +1 -0
- package/dist/keys/file-keystore.js +266 -0
- package/dist/keys/file-keystore.js.map +1 -0
- package/dist/keys/in-memory-keystore.d.ts +71 -0
- package/dist/keys/in-memory-keystore.d.ts.map +1 -0
- package/dist/keys/in-memory-keystore.js +85 -0
- package/dist/keys/in-memory-keystore.js.map +1 -0
- package/dist/keys/index.d.ts +12 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +18 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/keys/native-keystore.d.ts +111 -0
- package/dist/keys/native-keystore.d.ts.map +1 -0
- package/dist/keys/native-keystore.js +167 -0
- package/dist/keys/native-keystore.js.map +1 -0
- package/dist/sandbox/index.d.ts +6 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/sandbox.d.ts +55 -0
- package/dist/sandbox/sandbox.d.ts.map +1 -0
- package/dist/sandbox/sandbox.js +341 -0
- package/dist/sandbox/sandbox.js.map +1 -0
- package/dist/utils/amount.d.ts +76 -0
- package/dist/utils/amount.d.ts.map +1 -0
- package/dist/utils/amount.js +137 -0
- package/dist/utils/amount.js.map +1 -0
- package/dist/utils/gas.d.ts +69 -0
- package/dist/utils/gas.d.ts.map +1 -0
- package/dist/utils/gas.js +92 -0
- package/dist/utils/gas.js.map +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/key.d.ts +117 -0
- package/dist/utils/key.d.ts.map +1 -0
- package/dist/utils/key.js +270 -0
- package/dist/utils/key.js.map +1 -0
- package/dist/utils/nep413.d.ts +97 -0
- package/dist/utils/nep413.d.ts.map +1 -0
- package/dist/utils/nep413.js +154 -0
- package/dist/utils/nep413.js.map +1 -0
- package/dist/utils/validation.d.ts +114 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +150 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/wallets/adapters.d.ts +119 -0
- package/dist/wallets/adapters.d.ts.map +1 -0
- package/dist/wallets/adapters.js +267 -0
- package/dist/wallets/adapters.js.map +1 -0
- package/dist/wallets/index.d.ts +11 -0
- package/dist/wallets/index.d.ts.map +1 -0
- package/dist/wallets/index.js +2 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/wallets/types.d.ts +99 -0
- package/dist/wallets/types.d.ts.map +1 -0
- package/dist/wallets/types.js +10 -0
- package/dist/wallets/types.js.map +1 -0
- package/package.json +78 -7
- package/index.js +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NEP-413: Message signing utilities
|
|
3
|
+
*
|
|
4
|
+
* NEP-413 enables off-chain message signing for authentication and ownership verification
|
|
5
|
+
* without gas fees or blockchain transactions.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/near/NEPs/blob/master/neps/nep-0413.md
|
|
8
|
+
*/
|
|
9
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
10
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
11
|
+
import { base58, base64 } from "@scure/base";
|
|
12
|
+
import { b } from "@zorsh/zorsh";
|
|
13
|
+
import { parsePublicKey } from "./key.js";
|
|
14
|
+
/**
|
|
15
|
+
* NEP-413 tag prefix: 2^31 + 413 = 2147484061
|
|
16
|
+
*
|
|
17
|
+
* This prefix ensures that signed messages cannot be confused with valid transactions.
|
|
18
|
+
* The tag makes the message too long to be a valid signer account ID.
|
|
19
|
+
*/
|
|
20
|
+
export const NEP413_TAG = 2147484061;
|
|
21
|
+
/**
|
|
22
|
+
* NEP-413 message payload schema
|
|
23
|
+
*
|
|
24
|
+
* Fields are serialized in this order:
|
|
25
|
+
* 1. message: string - The message to sign
|
|
26
|
+
* 2. nonce: [u8; 32] - 32-byte nonce for replay protection
|
|
27
|
+
* 3. recipient: string - Recipient identifier (e.g., "alice.near" or "myapp.com")
|
|
28
|
+
* 4. callbackUrl: Option<string> - Optional callback URL for web wallets
|
|
29
|
+
*/
|
|
30
|
+
export const Nep413PayloadSchema = b.struct({
|
|
31
|
+
message: b.string(),
|
|
32
|
+
nonce: b.array(b.u8(), 32),
|
|
33
|
+
recipient: b.string(),
|
|
34
|
+
callbackUrl: b.option(b.string()),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Serialize NEP-413 message parameters for signing
|
|
38
|
+
*
|
|
39
|
+
* Serialization steps:
|
|
40
|
+
* 1. Serialize the tag (2147484061) as u32
|
|
41
|
+
* 2. Serialize the payload (message, nonce, recipient, callbackUrl)
|
|
42
|
+
* 3. Concatenate: tag_bytes + payload_bytes
|
|
43
|
+
* 4. Hash with SHA256
|
|
44
|
+
*
|
|
45
|
+
* @param params - Message signing parameters
|
|
46
|
+
* @returns Serialized and hashed message ready for signing
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const nonce = crypto.getRandomValues(new Uint8Array(32))
|
|
51
|
+
* const hash = serializeNep413Message({
|
|
52
|
+
* message: "Login to MyApp",
|
|
53
|
+
* recipient: "myapp.near",
|
|
54
|
+
* nonce,
|
|
55
|
+
* })
|
|
56
|
+
* const signature = keyPair.sign(hash)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function serializeNep413Message(params) {
|
|
60
|
+
if (params.nonce.length !== 32) {
|
|
61
|
+
throw new Error("Nonce must be exactly 32 bytes");
|
|
62
|
+
}
|
|
63
|
+
// Serialize tag as u32
|
|
64
|
+
const tagBytes = b.u32().serialize(NEP413_TAG);
|
|
65
|
+
// Serialize payload
|
|
66
|
+
const payloadBytes = Nep413PayloadSchema.serialize({
|
|
67
|
+
message: params.message,
|
|
68
|
+
nonce: Array.from(params.nonce),
|
|
69
|
+
recipient: params.recipient,
|
|
70
|
+
callbackUrl: null, // Optional, not typically used in direct signing
|
|
71
|
+
});
|
|
72
|
+
// Concatenate tag + payload
|
|
73
|
+
const combined = new Uint8Array(tagBytes.length + payloadBytes.length);
|
|
74
|
+
combined.set(tagBytes, 0);
|
|
75
|
+
combined.set(payloadBytes, tagBytes.length);
|
|
76
|
+
// Hash the combined bytes
|
|
77
|
+
return sha256(combined);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Verify a NEP-413 signed message
|
|
81
|
+
*
|
|
82
|
+
* Verification steps:
|
|
83
|
+
* 1. Reconstruct the payload from parameters
|
|
84
|
+
* 2. Serialize and hash (tag + payload)
|
|
85
|
+
* 3. Verify the signature against the hash using the public key
|
|
86
|
+
*
|
|
87
|
+
* @param signedMessage - The signed message to verify
|
|
88
|
+
* @param params - Original message parameters (must match what was signed)
|
|
89
|
+
* @returns true if signature is valid, false otherwise
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const isValid = verifyNep413Signature(signedMessage, {
|
|
94
|
+
* message: "Login to MyApp",
|
|
95
|
+
* recipient: "myapp.near",
|
|
96
|
+
* nonce,
|
|
97
|
+
* })
|
|
98
|
+
* if (isValid) {
|
|
99
|
+
* console.log("Signature verified!")
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export function verifyNep413Signature(signedMessage, params) {
|
|
104
|
+
try {
|
|
105
|
+
// Parse the public key
|
|
106
|
+
const publicKey = parsePublicKey(signedMessage.publicKey);
|
|
107
|
+
// Only Ed25519 is currently supported
|
|
108
|
+
if (publicKey.keyType !== 0) {
|
|
109
|
+
throw new Error("Only Ed25519 keys are supported for NEP-413");
|
|
110
|
+
}
|
|
111
|
+
// Reconstruct the hashed payload
|
|
112
|
+
const hash = serializeNep413Message(params);
|
|
113
|
+
// Decode the signature
|
|
114
|
+
// Try base64 first (most common), fallback to base58
|
|
115
|
+
let signatureBytes;
|
|
116
|
+
try {
|
|
117
|
+
signatureBytes = base64.decode(signedMessage.signature);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
try {
|
|
121
|
+
// Remove ed25519: prefix if present
|
|
122
|
+
const sig = signedMessage.signature.replace("ed25519:", "");
|
|
123
|
+
signatureBytes = base58.decode(sig);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Verify the signature
|
|
130
|
+
return ed25519.verify(signatureBytes, hash, publicKey.data);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Generate a random nonce for NEP-413 message signing
|
|
138
|
+
*
|
|
139
|
+
* @returns 32-byte random nonce
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const nonce = generateNep413Nonce()
|
|
144
|
+
* const signedMessage = await near.signMessage({
|
|
145
|
+
* message: "Login to MyApp",
|
|
146
|
+
* recipient: "myapp.near",
|
|
147
|
+
* nonce,
|
|
148
|
+
* })
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export function generateNep413Nonce() {
|
|
152
|
+
return crypto.getRandomValues(new Uint8Array(32));
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=nep413.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nep413.js","sourceRoot":"","sources":["../../src/utils/nep413.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAA;AAEpC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;IAC1B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAClC,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAyB;IAC9D,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,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,CAAC,SAAS,CAAC,CAAA;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC;gBACH,oCAAoC;gBACpC,MAAM,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;gBAC3D,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YACrC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QAED,uBAAuB;QACvB,OAAO,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod validation schemas and helpers for NEAR types.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These schemas power runtime validation for account IDs, public/private keys,
|
|
6
|
+
* amounts, and gas while keeping the developer-facing API ergonomic via
|
|
7
|
+
* helpers like {@link validateAccountId} and {@link normalizeAmount}.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* Schema for validating NEAR account IDs.
|
|
12
|
+
*
|
|
13
|
+
* Rules:
|
|
14
|
+
* - Length: 2-64 characters
|
|
15
|
+
* - Characters: lowercase alphanumeric, hyphens, underscores, and dots
|
|
16
|
+
* - Pattern: subdomain-like structure (e.g., alice.near, contract.mainnet)
|
|
17
|
+
*/
|
|
18
|
+
export declare const AccountIdSchema: z.ZodString;
|
|
19
|
+
export type AccountId = z.infer<typeof AccountIdSchema>;
|
|
20
|
+
/**
|
|
21
|
+
* Schema for validating NEAR public keys.
|
|
22
|
+
*
|
|
23
|
+
* Supports:
|
|
24
|
+
* - Ed25519: "ed25519:..." (base58 encoded)
|
|
25
|
+
* - Secp256k1: "secp256k1:..." (base58 encoded)
|
|
26
|
+
*/
|
|
27
|
+
export declare const PublicKeySchema: z.ZodString;
|
|
28
|
+
export type PublicKeyString = z.infer<typeof PublicKeySchema>;
|
|
29
|
+
/**
|
|
30
|
+
* Type-safe private key string using template literal types.
|
|
31
|
+
*
|
|
32
|
+
* Provides compile-time type safety for private keys.
|
|
33
|
+
* Supports both ed25519 and secp256k1 keys.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const key: PrivateKey = 'ed25519:...' // ✅ Valid
|
|
38
|
+
* const key: PrivateKey = 'secp256k1:...' // ✅ Valid
|
|
39
|
+
* const key: PrivateKey = 'alice.near' // ❌ Type error at compile time
|
|
40
|
+
*
|
|
41
|
+
* // Function signature ensures type safety
|
|
42
|
+
* function signWith(key: PrivateKey) { ... }
|
|
43
|
+
* signWith('ed25519:abc') // ✅ Valid
|
|
44
|
+
* signWith('secp256k1:abc') // ✅ Valid
|
|
45
|
+
* signWith('alice.near') // ❌ Type error
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type PrivateKey = `ed25519:${string}` | `secp256k1:${string}`;
|
|
49
|
+
/**
|
|
50
|
+
* Schema for validating NEAR private keys.
|
|
51
|
+
*
|
|
52
|
+
* Supports:
|
|
53
|
+
* - Ed25519: "ed25519:..." (base58 encoded, 64 bytes)
|
|
54
|
+
* - Secp256k1: "secp256k1:..." (base58 encoded, 96 bytes)
|
|
55
|
+
*/
|
|
56
|
+
export declare const PrivateKeySchema: z.ZodString;
|
|
57
|
+
export type PrivateKeyString = z.infer<typeof PrivateKeySchema>;
|
|
58
|
+
/**
|
|
59
|
+
* Schema for NEAR amounts with explicit units.
|
|
60
|
+
*
|
|
61
|
+
* Accepts:
|
|
62
|
+
* - String with unit: "10 NEAR", "1000000 yocto"
|
|
63
|
+
* - Created via Amount.NEAR(10) or Amount.yocto(1000000n)
|
|
64
|
+
* - Raw bigint: 1000000n (treated as yoctoNEAR)
|
|
65
|
+
*
|
|
66
|
+
* Rejects bare numbers to prevent unit confusion.
|
|
67
|
+
* Normalizes to yoctoNEAR string.
|
|
68
|
+
*/
|
|
69
|
+
export declare const AmountSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodBigInt]>, z.ZodTransform<string, string | bigint>>;
|
|
70
|
+
export type Amount = z.input<typeof AmountSchema>;
|
|
71
|
+
/**
|
|
72
|
+
* Schema for gas amounts.
|
|
73
|
+
*
|
|
74
|
+
* Accepts:
|
|
75
|
+
* - String with unit: "30 Tgas", Gas.Tgas(30)
|
|
76
|
+
* - Raw gas number strings for advanced use
|
|
77
|
+
*
|
|
78
|
+
* Normalizes to raw gas string.
|
|
79
|
+
*/
|
|
80
|
+
export declare const GasSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
81
|
+
export type Gas = z.input<typeof GasSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* Validate account ID (throws on invalid).
|
|
84
|
+
*/
|
|
85
|
+
export declare function validateAccountId(accountId: string): string;
|
|
86
|
+
/**
|
|
87
|
+
* Check if account ID is valid (boolean).
|
|
88
|
+
*/
|
|
89
|
+
export declare function isValidAccountId(accountId: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Validate public key (throws on invalid).
|
|
92
|
+
*/
|
|
93
|
+
export declare function validatePublicKey(key: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Check if public key is valid (boolean).
|
|
96
|
+
*/
|
|
97
|
+
export declare function isValidPublicKey(key: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Validate private key (throws on invalid).
|
|
100
|
+
*/
|
|
101
|
+
export declare function validatePrivateKey(key: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Check if private key is valid (boolean).
|
|
104
|
+
*/
|
|
105
|
+
export declare function isPrivateKey(key: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Normalize amount to yoctoNEAR string.
|
|
108
|
+
*/
|
|
109
|
+
export declare function normalizeAmount(amount: Amount): string;
|
|
110
|
+
/**
|
|
111
|
+
* Normalize gas to gas string.
|
|
112
|
+
*/
|
|
113
|
+
export declare function normalizeGas(gas: Gas): string;
|
|
114
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAyBvB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAazB,CAAA;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAIvD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,aAaoB,CAAA;AAEhD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAI7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,MAAM,EAAE,GAAG,aAAa,MAAM,EAAE,CAAA;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,aAaoB,CAAA;AAEjD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAI/D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,qGAIrB,CAAA;AAEJ,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAIjD;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,wDAEpB,CAAA;AAEF,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAA;AAI3C;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod validation schemas and helpers for NEAR types.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These schemas power runtime validation for account IDs, public/private keys,
|
|
6
|
+
* amounts, and gas while keeping the developer-facing API ergonomic via
|
|
7
|
+
* helpers like {@link validateAccountId} and {@link normalizeAmount}.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { ACCOUNT_ID_REGEX, ED25519_KEY_PREFIX, MAX_ACCOUNT_ID_LENGTH, MIN_ACCOUNT_ID_LENGTH, SECP256K1_KEY_PREFIX, } from "../core/constants.js";
|
|
11
|
+
import { parseAmount } from "./amount.js";
|
|
12
|
+
import { parseGas } from "./gas.js";
|
|
13
|
+
// ==================== Base58 Validation ====================
|
|
14
|
+
/**
|
|
15
|
+
* Check if a string is valid base58 encoding.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function isValidBase58(str) {
|
|
19
|
+
const base58Regex = /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/;
|
|
20
|
+
return base58Regex.test(str);
|
|
21
|
+
}
|
|
22
|
+
// ==================== Account ID Schema ====================
|
|
23
|
+
/**
|
|
24
|
+
* Schema for validating NEAR account IDs.
|
|
25
|
+
*
|
|
26
|
+
* Rules:
|
|
27
|
+
* - Length: 2-64 characters
|
|
28
|
+
* - Characters: lowercase alphanumeric, hyphens, underscores, and dots
|
|
29
|
+
* - Pattern: subdomain-like structure (e.g., alice.near, contract.mainnet)
|
|
30
|
+
*/
|
|
31
|
+
export const AccountIdSchema = z
|
|
32
|
+
.string()
|
|
33
|
+
.min(MIN_ACCOUNT_ID_LENGTH, `Account ID must be at least ${MIN_ACCOUNT_ID_LENGTH} characters`)
|
|
34
|
+
.max(MAX_ACCOUNT_ID_LENGTH, `Account ID must be at most ${MAX_ACCOUNT_ID_LENGTH} characters`)
|
|
35
|
+
.regex(ACCOUNT_ID_REGEX, "Account ID must contain only lowercase alphanumeric characters, hyphens, underscores, and dots");
|
|
36
|
+
// ==================== Public Key Schema ====================
|
|
37
|
+
/**
|
|
38
|
+
* Schema for validating NEAR public keys.
|
|
39
|
+
*
|
|
40
|
+
* Supports:
|
|
41
|
+
* - Ed25519: "ed25519:..." (base58 encoded)
|
|
42
|
+
* - Secp256k1: "secp256k1:..." (base58 encoded)
|
|
43
|
+
*/
|
|
44
|
+
export const PublicKeySchema = z
|
|
45
|
+
.string()
|
|
46
|
+
.refine((key) => key.startsWith(ED25519_KEY_PREFIX) ||
|
|
47
|
+
key.startsWith(SECP256K1_KEY_PREFIX), "Public key must start with 'ed25519:' or 'secp256k1:'")
|
|
48
|
+
.refine((key) => {
|
|
49
|
+
const keyData = key.startsWith(ED25519_KEY_PREFIX)
|
|
50
|
+
? key.slice(ED25519_KEY_PREFIX.length)
|
|
51
|
+
: key.slice(SECP256K1_KEY_PREFIX.length);
|
|
52
|
+
return isValidBase58(keyData);
|
|
53
|
+
}, "Public key must be valid base58 encoding");
|
|
54
|
+
/**
|
|
55
|
+
* Schema for validating NEAR private keys.
|
|
56
|
+
*
|
|
57
|
+
* Supports:
|
|
58
|
+
* - Ed25519: "ed25519:..." (base58 encoded, 64 bytes)
|
|
59
|
+
* - Secp256k1: "secp256k1:..." (base58 encoded, 96 bytes)
|
|
60
|
+
*/
|
|
61
|
+
export const PrivateKeySchema = z
|
|
62
|
+
.string()
|
|
63
|
+
.refine((key) => key.startsWith(ED25519_KEY_PREFIX) ||
|
|
64
|
+
key.startsWith(SECP256K1_KEY_PREFIX), "Private key must start with 'ed25519:' or 'secp256k1:'")
|
|
65
|
+
.refine((key) => {
|
|
66
|
+
const keyData = key.startsWith(ED25519_KEY_PREFIX)
|
|
67
|
+
? key.slice(ED25519_KEY_PREFIX.length)
|
|
68
|
+
: key.slice(SECP256K1_KEY_PREFIX.length);
|
|
69
|
+
return keyData.length > 0 && isValidBase58(keyData);
|
|
70
|
+
}, "Private key must be valid base58 encoding");
|
|
71
|
+
// ==================== Amount Schema ====================
|
|
72
|
+
/**
|
|
73
|
+
* Schema for NEAR amounts with explicit units.
|
|
74
|
+
*
|
|
75
|
+
* Accepts:
|
|
76
|
+
* - String with unit: "10 NEAR", "1000000 yocto"
|
|
77
|
+
* - Created via Amount.NEAR(10) or Amount.yocto(1000000n)
|
|
78
|
+
* - Raw bigint: 1000000n (treated as yoctoNEAR)
|
|
79
|
+
*
|
|
80
|
+
* Rejects bare numbers to prevent unit confusion.
|
|
81
|
+
* Normalizes to yoctoNEAR string.
|
|
82
|
+
*/
|
|
83
|
+
export const AmountSchema = z
|
|
84
|
+
.union([z.string(), z.bigint()])
|
|
85
|
+
.transform((amount) => {
|
|
86
|
+
return parseAmount(amount);
|
|
87
|
+
});
|
|
88
|
+
// ==================== Gas Schema ====================
|
|
89
|
+
/**
|
|
90
|
+
* Schema for gas amounts.
|
|
91
|
+
*
|
|
92
|
+
* Accepts:
|
|
93
|
+
* - String with unit: "30 Tgas", Gas.Tgas(30)
|
|
94
|
+
* - Raw gas number strings for advanced use
|
|
95
|
+
*
|
|
96
|
+
* Normalizes to raw gas string.
|
|
97
|
+
*/
|
|
98
|
+
export const GasSchema = z.string().transform((gas) => {
|
|
99
|
+
return parseGas(gas);
|
|
100
|
+
});
|
|
101
|
+
// ==================== Helper Functions ====================
|
|
102
|
+
/**
|
|
103
|
+
* Validate account ID (throws on invalid).
|
|
104
|
+
*/
|
|
105
|
+
export function validateAccountId(accountId) {
|
|
106
|
+
return AccountIdSchema.parse(accountId);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if account ID is valid (boolean).
|
|
110
|
+
*/
|
|
111
|
+
export function isValidAccountId(accountId) {
|
|
112
|
+
return AccountIdSchema.safeParse(accountId).success;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validate public key (throws on invalid).
|
|
116
|
+
*/
|
|
117
|
+
export function validatePublicKey(key) {
|
|
118
|
+
return PublicKeySchema.parse(key);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if public key is valid (boolean).
|
|
122
|
+
*/
|
|
123
|
+
export function isValidPublicKey(key) {
|
|
124
|
+
return PublicKeySchema.safeParse(key).success;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Validate private key (throws on invalid).
|
|
128
|
+
*/
|
|
129
|
+
export function validatePrivateKey(key) {
|
|
130
|
+
return PrivateKeySchema.parse(key);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if private key is valid (boolean).
|
|
134
|
+
*/
|
|
135
|
+
export function isPrivateKey(key) {
|
|
136
|
+
return PrivateKeySchema.safeParse(key).success;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Normalize amount to yoctoNEAR string.
|
|
140
|
+
*/
|
|
141
|
+
export function normalizeAmount(amount) {
|
|
142
|
+
return AmountSchema.parse(amount);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Normalize gas to gas string.
|
|
146
|
+
*/
|
|
147
|
+
export function normalizeGas(gas) {
|
|
148
|
+
return GasSchema.parse(gas);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,8DAA8D;AAE9D;;;GAGG;AACH,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,WAAW,GACf,iEAAiE,CAAA;IACnE,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9B,CAAC;AAED,8DAA8D;AAE9D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,EAAE;KACR,GAAG,CACF,qBAAqB,EACrB,+BAA+B,qBAAqB,aAAa,CAClE;KACA,GAAG,CACF,qBAAqB,EACrB,8BAA8B,qBAAqB,aAAa,CACjE;KACA,KAAK,CACJ,gBAAgB,EAChB,gGAAgG,CACjG,CAAA;AAIH,8DAA8D;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,EAAE;KACR,MAAM,CACL,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,CAAC,UAAU,CAAC,kBAAkB,CAAC;IAClC,GAAG,CAAC,UAAU,CAAC,oBAAoB,CAAC,EACtC,uDAAuD,CACxD;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ters for NEAR wallet integrations.
|
|
3
|
+
*
|
|
4
|
+
* Provides adapter functions to integrate with popular NEAR wallets:
|
|
5
|
+
* - `@near-wallet-selector/core`
|
|
6
|
+
* - `@hot-labs/near-connect`
|
|
7
|
+
*
|
|
8
|
+
* These adapters use duck typing / structural compatibility to work with
|
|
9
|
+
* wallet interfaces. While the actual wallet packages use `@near-js` types
|
|
10
|
+
* (which are classes), our types (plain objects) are structurally compatible
|
|
11
|
+
* and work correctly at runtime. See `tests/wallets/type-compatibility.test.ts`
|
|
12
|
+
* for verification.
|
|
13
|
+
*/
|
|
14
|
+
import type { WalletConnection } from "../core/types.js";
|
|
15
|
+
import type { HotConnectConnector } from "./types.js";
|
|
16
|
+
type WalletSelectorWallet = {
|
|
17
|
+
getAccounts(): Promise<Array<{
|
|
18
|
+
accountId: string;
|
|
19
|
+
publicKey?: string;
|
|
20
|
+
}>>;
|
|
21
|
+
signAndSendTransaction(params: {
|
|
22
|
+
signerId?: string;
|
|
23
|
+
receiverId?: string;
|
|
24
|
+
actions: unknown[];
|
|
25
|
+
}): Promise<unknown>;
|
|
26
|
+
signMessage?(params: {
|
|
27
|
+
message: string;
|
|
28
|
+
recipient: string;
|
|
29
|
+
nonce: Buffer;
|
|
30
|
+
callbackUrl?: string;
|
|
31
|
+
state?: string;
|
|
32
|
+
}): Promise<unknown>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Adapter for @near-wallet-selector/core
|
|
36
|
+
*
|
|
37
|
+
* Converts a wallet-selector Wallet instance to the WalletConnection interface.
|
|
38
|
+
*
|
|
39
|
+
* @param wallet - Wallet instance from wallet-selector
|
|
40
|
+
* @returns WalletConnection interface compatible with near-ts
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { Near } from 'near-ts'
|
|
45
|
+
* import { setupWalletSelector } from '@near-wallet-selector/core'
|
|
46
|
+
* import { fromWalletSelector } from 'near-ts/wallets'
|
|
47
|
+
*
|
|
48
|
+
* const selector = await setupWalletSelector({
|
|
49
|
+
* network: 'mainnet',
|
|
50
|
+
* modules: [...]
|
|
51
|
+
* })
|
|
52
|
+
* const wallet = await selector.wallet()
|
|
53
|
+
*
|
|
54
|
+
* const near = new Near({
|
|
55
|
+
* network: 'mainnet',
|
|
56
|
+
* wallet: fromWalletSelector(wallet)
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function fromWalletSelector(wallet: WalletSelectorWallet): WalletConnection;
|
|
61
|
+
/**
|
|
62
|
+
* Adapter for @hot-labs/near-connect (HOT Connect)
|
|
63
|
+
*
|
|
64
|
+
* Converts a HOT Connect NearConnector instance to the WalletConnection interface.
|
|
65
|
+
*
|
|
66
|
+
* @param connector - NearConnector instance from HOT Connect
|
|
67
|
+
* @returns WalletConnection interface compatible with near-ts
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { Near } from 'near-ts'
|
|
72
|
+
* import { NearConnector } from '@hot-labs/near-connect'
|
|
73
|
+
* import { fromHotConnect } from 'near-ts/wallets'
|
|
74
|
+
*
|
|
75
|
+
* const connector = new NearConnector({ network: 'mainnet' })
|
|
76
|
+
*
|
|
77
|
+
* // Wait for user to connect their wallet
|
|
78
|
+
* connector.on('wallet:signIn', async () => {
|
|
79
|
+
* const near = new Near({
|
|
80
|
+
* network: 'mainnet',
|
|
81
|
+
* wallet: fromHotConnect(connector)
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* // Use near-ts with the connected wallet
|
|
85
|
+
* await near.call('contract.near', 'method', { arg: 'value' })
|
|
86
|
+
* })
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Adapter for @hot-labs/near-connect (HOT Connect)
|
|
91
|
+
*
|
|
92
|
+
* Converts a HOT Connect NearConnector instance to the WalletConnection interface.
|
|
93
|
+
*
|
|
94
|
+
* @param connector - NearConnector instance from HOT Connect
|
|
95
|
+
* @returns WalletConnection interface compatible with near-kit
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { Near } from 'near-kit'
|
|
100
|
+
* import { NearConnector } from '@hot-labs/near-connect'
|
|
101
|
+
* import { fromHotConnect } from 'near-kit/wallets'
|
|
102
|
+
*
|
|
103
|
+
* const connector = new NearConnector({ network: 'mainnet' })
|
|
104
|
+
*
|
|
105
|
+
* // Wait for user to connect their wallet
|
|
106
|
+
* connector.on('wallet:signIn', async () => {
|
|
107
|
+
* const near = new Near({
|
|
108
|
+
* network: 'mainnet',
|
|
109
|
+
* wallet: fromHotConnect(connector)
|
|
110
|
+
* })
|
|
111
|
+
*
|
|
112
|
+
* // Use near-kit with the connected wallet
|
|
113
|
+
* await near.call('contract.near', 'method', { arg: 'value' })
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function fromHotConnect(connector: HotConnectConnector): WalletConnection;
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../../src/wallets/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAIV,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAGV,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAQnB,KAAK,oBAAoB,GAAG;IAC1B,WAAW,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAA;IACxE,sBAAsB,CAAC,MAAM,EAAE;QAC7B,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,OAAO,EAAE,OAAO,EAAE,CAAA;KACnB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACpB,WAAW,CAAC,CAAC,MAAM,EAAE;QACnB,OAAO,EAAE,MAAM,CAAA;QACf,SAAS,EAAE,MAAM,CAAA;QACjB,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,oBAAoB,GAC3B,gBAAgB,CA8ClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,mBAAmB,GAC7B,gBAAgB,CAqKlB"}
|