@t402/near 2.3.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 (38) hide show
  1. package/README.md +173 -0
  2. package/dist/cjs/exact-direct/client/index.d.ts +105 -0
  3. package/dist/cjs/exact-direct/client/index.js +156 -0
  4. package/dist/cjs/exact-direct/client/index.js.map +1 -0
  5. package/dist/cjs/exact-direct/facilitator/index.d.ts +114 -0
  6. package/dist/cjs/exact-direct/facilitator/index.js +304 -0
  7. package/dist/cjs/exact-direct/facilitator/index.js.map +1 -0
  8. package/dist/cjs/exact-direct/server/index.d.ts +129 -0
  9. package/dist/cjs/exact-direct/server/index.js +253 -0
  10. package/dist/cjs/exact-direct/server/index.js.map +1 -0
  11. package/dist/cjs/index.d.ts +226 -0
  12. package/dist/cjs/index.js +711 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/types-Ca7ztL_f.d.ts +169 -0
  15. package/dist/esm/chunk-B3RHERRA.mjs +162 -0
  16. package/dist/esm/chunk-B3RHERRA.mjs.map +1 -0
  17. package/dist/esm/chunk-BU2BQECZ.mjs +206 -0
  18. package/dist/esm/chunk-BU2BQECZ.mjs.map +1 -0
  19. package/dist/esm/chunk-G35SAYZI.mjs +67 -0
  20. package/dist/esm/chunk-G35SAYZI.mjs.map +1 -0
  21. package/dist/esm/chunk-WANNPL6S.mjs +155 -0
  22. package/dist/esm/chunk-WANNPL6S.mjs.map +1 -0
  23. package/dist/esm/chunk-YXBOH4MJ.mjs +103 -0
  24. package/dist/esm/chunk-YXBOH4MJ.mjs.map +1 -0
  25. package/dist/esm/exact-direct/client/index.d.mts +105 -0
  26. package/dist/esm/exact-direct/client/index.mjs +10 -0
  27. package/dist/esm/exact-direct/client/index.mjs.map +1 -0
  28. package/dist/esm/exact-direct/facilitator/index.d.mts +114 -0
  29. package/dist/esm/exact-direct/facilitator/index.mjs +11 -0
  30. package/dist/esm/exact-direct/facilitator/index.mjs.map +1 -0
  31. package/dist/esm/exact-direct/server/index.d.mts +129 -0
  32. package/dist/esm/exact-direct/server/index.mjs +11 -0
  33. package/dist/esm/exact-direct/server/index.mjs.map +1 -0
  34. package/dist/esm/index.d.mts +226 -0
  35. package/dist/esm/index.mjs +97 -0
  36. package/dist/esm/index.mjs.map +1 -0
  37. package/dist/esm/types-Ca7ztL_f.d.mts +169 -0
  38. package/package.json +97 -0
@@ -0,0 +1,97 @@
1
+ import {
2
+ ExactDirectNearClient,
3
+ registerExactDirectNearClient
4
+ } from "./chunk-YXBOH4MJ.mjs";
5
+ import {
6
+ ExactDirectNearServer,
7
+ registerExactDirectNearServer
8
+ } from "./chunk-B3RHERRA.mjs";
9
+ import {
10
+ ExactDirectNearFacilitator,
11
+ registerExactDirectNearFacilitator
12
+ } from "./chunk-BU2BQECZ.mjs";
13
+ import {
14
+ TOKEN_REGISTRY,
15
+ getDefaultToken,
16
+ getNetworkTokens,
17
+ getTokenByContract,
18
+ getTokenConfig,
19
+ isNetworkSupported
20
+ } from "./chunk-G35SAYZI.mjs";
21
+ import {
22
+ DEFAULT_FT_TRANSFER_GAS,
23
+ DEFAULT_STORAGE_DEPOSIT,
24
+ DEFAULT_STORAGE_DEPOSIT_GAS,
25
+ DEFAULT_VALIDITY_DURATION,
26
+ FT_TRANSFER_DEPOSIT,
27
+ MAX_TRANSACTION_AGE,
28
+ NEAR_CAIP2_NAMESPACE,
29
+ NEAR_MAINNET_CAIP2,
30
+ NEAR_MAINNET_RPC,
31
+ NEAR_NETWORKS,
32
+ NEAR_NETWORK_IDS,
33
+ NEAR_TESTNET_CAIP2,
34
+ NEAR_TESTNET_RPC,
35
+ NEP141_FT_BALANCE_OF,
36
+ NEP141_FT_TRANSFER,
37
+ NEP141_STORAGE_BALANCE_OF,
38
+ NEP141_STORAGE_DEPOSIT,
39
+ NETWORK_RPC_ENDPOINTS,
40
+ SCHEME_EXACT_DIRECT,
41
+ extractNetworkId,
42
+ formatAmount,
43
+ getRpcEndpoint,
44
+ isTransactionSuccessful,
45
+ isValidAccountId,
46
+ normalizeNetwork,
47
+ parseFtTransferArgs,
48
+ queryTokenBalance,
49
+ queryTransaction,
50
+ rpcCall,
51
+ toTokenUnits
52
+ } from "./chunk-WANNPL6S.mjs";
53
+ export {
54
+ DEFAULT_FT_TRANSFER_GAS,
55
+ DEFAULT_STORAGE_DEPOSIT,
56
+ DEFAULT_STORAGE_DEPOSIT_GAS,
57
+ DEFAULT_VALIDITY_DURATION,
58
+ ExactDirectNearClient,
59
+ ExactDirectNearFacilitator,
60
+ ExactDirectNearServer,
61
+ FT_TRANSFER_DEPOSIT,
62
+ MAX_TRANSACTION_AGE,
63
+ NEAR_CAIP2_NAMESPACE,
64
+ NEAR_MAINNET_CAIP2,
65
+ NEAR_MAINNET_RPC,
66
+ NEAR_NETWORKS,
67
+ NEAR_NETWORK_IDS,
68
+ NEAR_TESTNET_CAIP2,
69
+ NEAR_TESTNET_RPC,
70
+ NEP141_FT_BALANCE_OF,
71
+ NEP141_FT_TRANSFER,
72
+ NEP141_STORAGE_BALANCE_OF,
73
+ NEP141_STORAGE_DEPOSIT,
74
+ NETWORK_RPC_ENDPOINTS,
75
+ SCHEME_EXACT_DIRECT,
76
+ TOKEN_REGISTRY,
77
+ extractNetworkId,
78
+ formatAmount,
79
+ getDefaultToken,
80
+ getNetworkTokens,
81
+ getRpcEndpoint,
82
+ getTokenByContract,
83
+ getTokenConfig,
84
+ isNetworkSupported,
85
+ isTransactionSuccessful,
86
+ isValidAccountId,
87
+ normalizeNetwork,
88
+ parseFtTransferArgs,
89
+ queryTokenBalance,
90
+ queryTransaction,
91
+ registerExactDirectNearClient,
92
+ registerExactDirectNearFacilitator,
93
+ registerExactDirectNearServer,
94
+ rpcCall,
95
+ toTokenUnits
96
+ };
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * NEAR Payment Types
3
+ *
4
+ * Defines the payload structure for NEAR NEP-141 payments using the exact-direct scheme.
5
+ * The exact-direct scheme has the client execute the transfer directly, then provide
6
+ * the transaction hash as proof of payment.
7
+ */
8
+ /**
9
+ * NEAR payment payload for the exact-direct scheme
10
+ * Contains transaction hash and metadata for verification
11
+ */
12
+ type ExactDirectNearPayload = {
13
+ /**
14
+ * Transaction hash of the completed ft_transfer
15
+ * This is the base58 encoded transaction hash from NEAR
16
+ */
17
+ txHash: string;
18
+ /**
19
+ * Sender account ID (e.g., "alice.near")
20
+ */
21
+ from: string;
22
+ /**
23
+ * Recipient account ID (e.g., "merchant.near")
24
+ */
25
+ to: string;
26
+ /**
27
+ * Transfer amount in smallest units (e.g., "1000000" for 1 USDC)
28
+ */
29
+ amount: string;
30
+ };
31
+ /**
32
+ * Result of transaction verification
33
+ */
34
+ interface VerifyTransactionResult {
35
+ /** Whether the transaction is valid */
36
+ valid: boolean;
37
+ /** Reason for invalidity (if applicable) */
38
+ reason?: string;
39
+ /** Extracted transfer parameters */
40
+ transfer?: {
41
+ from: string;
42
+ to: string;
43
+ amount: bigint;
44
+ tokenContract: string;
45
+ blockHash: string;
46
+ };
47
+ }
48
+ /**
49
+ * NEAR transaction status
50
+ */
51
+ interface TransactionStatus {
52
+ SuccessValue?: string;
53
+ Failure?: unknown;
54
+ }
55
+ /**
56
+ * NEAR transaction outcome
57
+ */
58
+ interface TransactionOutcome {
59
+ block_hash: string;
60
+ id: string;
61
+ }
62
+ /**
63
+ * NEAR function call action
64
+ */
65
+ interface FunctionCallAction {
66
+ FunctionCall: {
67
+ method_name: string;
68
+ args: string;
69
+ gas: number;
70
+ deposit: string;
71
+ };
72
+ }
73
+ /**
74
+ * NEAR transaction
75
+ */
76
+ interface NearTransaction {
77
+ hash: string;
78
+ signer_id: string;
79
+ receiver_id: string;
80
+ actions: FunctionCallAction[];
81
+ }
82
+ /**
83
+ * NEAR transaction result from RPC query
84
+ */
85
+ interface TransactionResult {
86
+ status: TransactionStatus;
87
+ transaction: NearTransaction;
88
+ transaction_outcome: TransactionOutcome;
89
+ receipts_outcome: Array<{
90
+ id: string;
91
+ outcome: {
92
+ status: TransactionStatus;
93
+ gas_burnt: number;
94
+ tokens_burnt: string;
95
+ };
96
+ }>;
97
+ }
98
+ /**
99
+ * NEAR RPC request
100
+ */
101
+ interface NearRpcRequest {
102
+ jsonrpc: "2.0";
103
+ id: string;
104
+ method: string;
105
+ params: unknown[] | Record<string, unknown>;
106
+ }
107
+ /**
108
+ * NEAR RPC response
109
+ */
110
+ interface NearRpcResponse<T = unknown> {
111
+ jsonrpc: "2.0";
112
+ id: string;
113
+ result?: T;
114
+ error?: {
115
+ code: number;
116
+ message: string;
117
+ data?: string;
118
+ };
119
+ }
120
+ /**
121
+ * ft_transfer arguments
122
+ */
123
+ interface FtTransferArgs {
124
+ receiver_id: string;
125
+ amount: string;
126
+ memo?: string | null;
127
+ }
128
+ /**
129
+ * NEAR signer interface for client operations
130
+ */
131
+ interface ClientNearSigner {
132
+ /** Get the account ID */
133
+ readonly accountId: string;
134
+ /**
135
+ * Sign and send a transaction
136
+ * @param receiverId - Contract to call
137
+ * @param methodName - Method to call
138
+ * @param args - Method arguments
139
+ * @param gas - Gas to attach
140
+ * @param deposit - yoctoNEAR to attach
141
+ * @returns Transaction hash
142
+ */
143
+ signAndSendTransaction(receiverId: string, methodName: string, args: Record<string, unknown>, gas: string, deposit: string): Promise<string>;
144
+ }
145
+ /**
146
+ * NEAR signer interface for facilitator operations
147
+ */
148
+ interface FacilitatorNearSigner {
149
+ /**
150
+ * Get the facilitator's account IDs for a network
151
+ * @param network - CAIP-2 network identifier
152
+ */
153
+ getAddresses(network: string): string[];
154
+ /**
155
+ * Query a transaction by hash
156
+ * @param txHash - Transaction hash
157
+ * @param senderAccountId - Sender account ID (required for NEAR tx query)
158
+ * @returns Transaction result
159
+ */
160
+ queryTransaction(txHash: string, senderAccountId: string): Promise<TransactionResult>;
161
+ /**
162
+ * Get token balance for an account
163
+ * @param accountId - Account ID
164
+ * @param tokenContract - Token contract address
165
+ */
166
+ getBalance(accountId: string, tokenContract: string): Promise<bigint>;
167
+ }
168
+
169
+ export type { ClientNearSigner as C, ExactDirectNearPayload as E, FtTransferArgs as F, NearRpcRequest as N, TransactionResult as T, VerifyTransactionResult as V, TransactionStatus as a, TransactionOutcome as b, FunctionCallAction as c, NearTransaction as d, NearRpcResponse as e, FacilitatorNearSigner as f };
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@t402/near",
3
+ "version": "2.3.0",
4
+ "main": "./dist/cjs/index.js",
5
+ "module": "./dist/esm/index.js",
6
+ "types": "./dist/cjs/index.d.ts",
7
+ "keywords": [
8
+ "t402",
9
+ "payment",
10
+ "protocol",
11
+ "near",
12
+ "blockchain",
13
+ "nep-141"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "author": "T402 Team",
17
+ "repository": "https://github.com/t402-io/t402",
18
+ "description": "t402 Payment Protocol NEAR Implementation",
19
+ "devDependencies": {
20
+ "@eslint/js": "^9.24.0",
21
+ "@types/node": "^22.13.4",
22
+ "@typescript-eslint/eslint-plugin": "^8.29.1",
23
+ "@typescript-eslint/parser": "^8.29.1",
24
+ "eslint": "^9.24.0",
25
+ "eslint-plugin-import": "^2.31.0",
26
+ "eslint-plugin-jsdoc": "^50.6.9",
27
+ "eslint-plugin-prettier": "^5.2.6",
28
+ "glob": "^13.0.0",
29
+ "prettier": "3.5.2",
30
+ "tsup": "^8.4.0",
31
+ "tsx": "^4.21.0",
32
+ "typescript": "^5.7.3",
33
+ "vite": "^7.3.1",
34
+ "vite-tsconfig-paths": "^5.1.4",
35
+ "vitest": "^3.2.4"
36
+ },
37
+ "dependencies": {
38
+ "@t402/core": "2.3.0"
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "import": {
43
+ "types": "./dist/esm/index.d.mts",
44
+ "default": "./dist/esm/index.mjs"
45
+ },
46
+ "require": {
47
+ "types": "./dist/cjs/index.d.ts",
48
+ "default": "./dist/cjs/index.js"
49
+ }
50
+ },
51
+ "./exact-direct/client": {
52
+ "import": {
53
+ "types": "./dist/esm/exact-direct/client/index.d.mts",
54
+ "default": "./dist/esm/exact-direct/client/index.mjs"
55
+ },
56
+ "require": {
57
+ "types": "./dist/cjs/exact-direct/client/index.d.ts",
58
+ "default": "./dist/cjs/exact-direct/client/index.js"
59
+ }
60
+ },
61
+ "./exact-direct/server": {
62
+ "import": {
63
+ "types": "./dist/esm/exact-direct/server/index.d.mts",
64
+ "default": "./dist/esm/exact-direct/server/index.mjs"
65
+ },
66
+ "require": {
67
+ "types": "./dist/cjs/exact-direct/server/index.d.ts",
68
+ "default": "./dist/cjs/exact-direct/server/index.js"
69
+ }
70
+ },
71
+ "./exact-direct/facilitator": {
72
+ "import": {
73
+ "types": "./dist/esm/exact-direct/facilitator/index.d.mts",
74
+ "default": "./dist/esm/exact-direct/facilitator/index.mjs"
75
+ },
76
+ "require": {
77
+ "types": "./dist/cjs/exact-direct/facilitator/index.d.ts",
78
+ "default": "./dist/cjs/exact-direct/facilitator/index.js"
79
+ }
80
+ }
81
+ },
82
+ "files": [
83
+ "dist"
84
+ ],
85
+ "scripts": {
86
+ "start": "tsx --env-file=.env index.ts",
87
+ "build": "tsup",
88
+ "test": "vitest run",
89
+ "test:integration": "vitest run --config vitest.integration.config.ts",
90
+ "test:watch": "vitest",
91
+ "watch": "tsc --watch",
92
+ "format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
93
+ "format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
94
+ "lint": "eslint . --ext .ts --fix",
95
+ "lint:check": "eslint . --ext .ts"
96
+ }
97
+ }