@fastnear/api 0.6.2 → 0.7.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.
@@ -0,0 +1,213 @@
1
+ /* ⋈ 🏃🏻💨 FastNEAR API - CJS (@fastnear/api version 0.6.3) */
2
+ /* https://www.npmjs.com/package/@fastnear/api/v/0.6.3 */
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var state_exports = {};
23
+ __export(state_exports, {
24
+ DEFAULT_NETWORK_ID: () => DEFAULT_NETWORK_ID,
25
+ NETWORKS: () => NETWORKS,
26
+ WIDGET_URL: () => WIDGET_URL,
27
+ _adapter: () => _adapter,
28
+ _config: () => _config,
29
+ _eventListeners: () => _eventListeners,
30
+ _state: () => _state,
31
+ _txHistory: () => _txHistory,
32
+ _unbroadcastedEvents: () => _unbroadcastedEvents,
33
+ getConfig: () => getConfig,
34
+ getTxHistory: () => getTxHistory,
35
+ getWalletAdapterState: () => getWalletAdapterState,
36
+ notifyAccountListeners: () => notifyAccountListeners,
37
+ notifyTxListeners: () => notifyTxListeners,
38
+ onAccount: () => onAccount,
39
+ onAdapterStateUpdate: () => onAdapterStateUpdate,
40
+ onTx: () => onTx,
41
+ resetTxHistory: () => resetTxHistory,
42
+ setConfig: () => setConfig,
43
+ updateState: () => updateState,
44
+ updateTxHistory: () => updateTxHistory
45
+ });
46
+ module.exports = __toCommonJS(state_exports);
47
+ var import_utils = require("@fastnear/utils");
48
+ var import_wallet_adapter = require("@fastnear/wallet-adapter");
49
+ const WIDGET_URL = "https://wallet-adapter.fastnear.com";
50
+ const DEFAULT_NETWORK_ID = "mainnet";
51
+ const NETWORKS = {
52
+ testnet: {
53
+ networkId: "testnet",
54
+ nodeUrl: "https://rpc.testnet.fastnear.com/"
55
+ },
56
+ mainnet: {
57
+ networkId: "mainnet",
58
+ nodeUrl: "https://rpc.mainnet.fastnear.com/"
59
+ }
60
+ };
61
+ let _config = (0, import_utils.lsGet)("config") || {
62
+ ...NETWORKS[DEFAULT_NETWORK_ID]
63
+ };
64
+ let _state = (0, import_utils.lsGet)("state") || {};
65
+ const onAdapterStateUpdate = /* @__PURE__ */ __name((state) => {
66
+ console.log("Adapter state update:", state);
67
+ const { accountId, lastWalletId, privateKey } = state;
68
+ updateState({
69
+ accountId: accountId || void 0,
70
+ lastWalletId: lastWalletId || void 0,
71
+ ...privateKey ? { privateKey } : {}
72
+ });
73
+ }, "onAdapterStateUpdate");
74
+ const getWalletAdapterState = /* @__PURE__ */ __name(() => {
75
+ return {
76
+ publicKey: _state.publicKey,
77
+ accountId: _state.accountId,
78
+ lastWalletId: _state.lastWalletId,
79
+ networkId: DEFAULT_NETWORK_ID
80
+ };
81
+ }, "getWalletAdapterState");
82
+ let _adapter = new import_wallet_adapter.WalletAdapter({
83
+ onStateUpdate: onAdapterStateUpdate,
84
+ lastState: getWalletAdapterState(),
85
+ widgetUrl: WIDGET_URL
86
+ });
87
+ try {
88
+ _state.publicKey = _state.privateKey ? (0, import_utils.publicKeyFromPrivate)(_state.privateKey) : null;
89
+ } catch (e) {
90
+ console.error("Error parsing private key:", e);
91
+ _state.privateKey = null;
92
+ (0, import_utils.lsSet)("nonce", null);
93
+ }
94
+ let _txHistory = (0, import_utils.lsGet)("txHistory") || {};
95
+ const _eventListeners = {
96
+ account: /* @__PURE__ */ new Set(),
97
+ tx: /* @__PURE__ */ new Set()
98
+ };
99
+ const _unbroadcastedEvents = {
100
+ account: [],
101
+ tx: []
102
+ };
103
+ const updateState = /* @__PURE__ */ __name((newState) => {
104
+ const oldState = _state;
105
+ _state = { ..._state, ...newState };
106
+ (0, import_utils.lsSet)("state", {
107
+ accountId: _state.accountId,
108
+ privateKey: _state.privateKey,
109
+ lastWalletId: _state.lastWalletId,
110
+ accessKeyContractId: _state.accessKeyContractId
111
+ });
112
+ if (newState.hasOwnProperty("privateKey") && newState.privateKey !== oldState.privateKey) {
113
+ _state.publicKey = newState.privateKey ? (0, import_utils.publicKeyFromPrivate)(newState.privateKey) : null;
114
+ (0, import_utils.lsSet)("nonce", null);
115
+ }
116
+ if (newState.accountId !== oldState.accountId) {
117
+ notifyAccountListeners(newState.accountId);
118
+ }
119
+ if (newState.hasOwnProperty("lastWalletId") && newState.lastWalletId !== oldState.lastWalletId || newState.hasOwnProperty("accountId") && newState.accountId !== oldState.accountId || newState.hasOwnProperty("privateKey") && newState.privateKey !== oldState.privateKey) {
120
+ _adapter.setState(getWalletAdapterState());
121
+ }
122
+ }, "updateState");
123
+ const updateTxHistory = /* @__PURE__ */ __name((txStatus) => {
124
+ const txId = txStatus.txId;
125
+ _txHistory[txId] = {
126
+ ..._txHistory[txId] || {},
127
+ ...txStatus,
128
+ updateTimestamp: Date.now()
129
+ };
130
+ (0, import_utils.lsSet)("txHistory", _txHistory);
131
+ notifyTxListeners(_txHistory[txId]);
132
+ }, "updateTxHistory");
133
+ const notifyAccountListeners = /* @__PURE__ */ __name((accountId) => {
134
+ if (_eventListeners.account.size === 0) {
135
+ _unbroadcastedEvents.account.push(accountId);
136
+ return;
137
+ }
138
+ _eventListeners.account.forEach((callback) => {
139
+ try {
140
+ callback(accountId);
141
+ } catch (e) {
142
+ console.error(e);
143
+ }
144
+ });
145
+ }, "notifyAccountListeners");
146
+ const notifyTxListeners = /* @__PURE__ */ __name((tx) => {
147
+ if (_eventListeners.tx.size === 0) {
148
+ _unbroadcastedEvents.tx.push(tx);
149
+ return;
150
+ }
151
+ _eventListeners.tx.forEach((callback) => {
152
+ try {
153
+ callback(tx);
154
+ } catch (e) {
155
+ console.error(e);
156
+ }
157
+ });
158
+ }, "notifyTxListeners");
159
+ const onAccount = /* @__PURE__ */ __name((callback) => {
160
+ _eventListeners.account.add(callback);
161
+ if (_unbroadcastedEvents.account.length > 0) {
162
+ const events = _unbroadcastedEvents.account;
163
+ _unbroadcastedEvents.account = [];
164
+ events.forEach(notifyAccountListeners);
165
+ }
166
+ }, "onAccount");
167
+ const onTx = /* @__PURE__ */ __name((callback) => {
168
+ _eventListeners.tx.add(callback);
169
+ if (_unbroadcastedEvents.tx.length > 0) {
170
+ const events = _unbroadcastedEvents.tx;
171
+ _unbroadcastedEvents.tx = [];
172
+ events.forEach(notifyTxListeners);
173
+ }
174
+ }, "onTx");
175
+ const getConfig = /* @__PURE__ */ __name(() => {
176
+ return _config;
177
+ }, "getConfig");
178
+ const getTxHistory = /* @__PURE__ */ __name(() => {
179
+ return _txHistory;
180
+ }, "getTxHistory");
181
+ const setConfig = /* @__PURE__ */ __name((newConf) => {
182
+ _config = { ...NETWORKS[newConf.networkId], ...newConf };
183
+ (0, import_utils.lsSet)("config", _config);
184
+ }, "setConfig");
185
+ const resetTxHistory = /* @__PURE__ */ __name(() => {
186
+ _txHistory = {};
187
+ (0, import_utils.lsSet)("txHistory", _txHistory);
188
+ }, "resetTxHistory");
189
+ // Annotate the CommonJS export names for ESM import in node:
190
+ 0 && (module.exports = {
191
+ DEFAULT_NETWORK_ID,
192
+ NETWORKS,
193
+ WIDGET_URL,
194
+ _adapter,
195
+ _config,
196
+ _eventListeners,
197
+ _state,
198
+ _txHistory,
199
+ _unbroadcastedEvents,
200
+ getConfig,
201
+ getTxHistory,
202
+ getWalletAdapterState,
203
+ notifyAccountListeners,
204
+ notifyTxListeners,
205
+ onAccount,
206
+ onAdapterStateUpdate,
207
+ onTx,
208
+ resetTxHistory,
209
+ setConfig,
210
+ updateState,
211
+ updateTxHistory
212
+ });
213
+ //# sourceMappingURL=state.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/state.ts"],"sourcesContent":["import {\n lsSet,\n lsGet,\n publicKeyFromPrivate,\n} from \"@fastnear/utils\";\nimport {WalletAdapter} from \"@fastnear/wallet-adapter\";\n\nexport const WIDGET_URL = \"https://wallet-adapter.fastnear.com\";\n\nexport const DEFAULT_NETWORK_ID = \"mainnet\";\nexport const NETWORKS = {\n testnet: {\n networkId: \"testnet\",\n nodeUrl: \"https://rpc.testnet.fastnear.com/\",\n },\n mainnet: {\n networkId: \"mainnet\",\n nodeUrl: \"https://rpc.mainnet.fastnear.com/\",\n },\n};\n\nexport interface NetworkConfig {\n networkId: string;\n nodeUrl?: string;\n walletUrl?: string;\n helperUrl?: string;\n explorerUrl?: string;\n\n [key: string]: any;\n}\n\nexport interface AppState {\n accountId?: string | null;\n privateKey?: string | null;\n lastWalletId?: string | null;\n publicKey?: string | null;\n accessKeyContractId?: string | null;\n\n [key: string]: any;\n}\n\nexport interface TxStatus {\n txId: string;\n updateTimestamp?: number;\n\n [key: string]: any;\n}\n\nexport type TxHistory = Record<string, TxStatus>;\n\nexport interface EventListeners {\n account: Set<(accountId: string) => void>;\n tx: Set<(tx: TxStatus) => void>;\n}\n\nexport interface UnbroadcastedEvents {\n account: string[];\n tx: TxStatus[];\n}\n\nexport interface WalletAdapterState {\n publicKey?: string | null;\n privateKey?: string | null;\n accountId?: string | null;\n lastWalletId?: string | null;\n networkId: string;\n}\n\n\n// Load config from localStorage or default to the network's config\nexport let _config: NetworkConfig = lsGet(\"config\") || {\n ...NETWORKS[DEFAULT_NETWORK_ID]\n};\n\n// Load application state from localStorage\nexport let _state: AppState = lsGet(\"state\") || {};\n\n// Triggered by the wallet adapter\nexport const onAdapterStateUpdate = (state: WalletAdapterState) => {\n console.log(\"Adapter state update:\", state);\n const { accountId, lastWalletId, privateKey } = state;\n updateState({\n accountId: accountId || undefined,\n lastWalletId: lastWalletId || undefined,\n ...(privateKey ? { privateKey } : {}),\n });\n}\n\nexport const getWalletAdapterState = (): WalletAdapterState => {\n return {\n publicKey: _state.publicKey,\n accountId: _state.accountId,\n lastWalletId: _state.lastWalletId,\n networkId: DEFAULT_NETWORK_ID,\n };\n}\n\n// We can create an adapter instance here\nexport let _adapter = new WalletAdapter({\n onStateUpdate: onAdapterStateUpdate,\n lastState: getWalletAdapterState(),\n widgetUrl: WIDGET_URL,\n});\n\n// Attempt to set publicKey if we have a privateKey\ntry {\n _state.publicKey = _state.privateKey\n ? publicKeyFromPrivate(_state.privateKey)\n : null;\n} catch (e) {\n console.error(\"Error parsing private key:\", e);\n _state.privateKey = null;\n lsSet(\"nonce\", null);\n}\n\n// Transaction history\nexport let _txHistory: TxHistory = lsGet(\"txHistory\") || {};\n\n// Event listeners\nexport const _eventListeners: EventListeners = {\n account: new Set(),\n tx: new Set(),\n};\n\nexport const _unbroadcastedEvents: UnbroadcastedEvents = {\n account: [],\n tx: [],\n};\n\n// Mutators\n// @todo: in favor of limiting when out of alpha\n// but haven't given it enough thought ~ mike\nexport const updateState = (newState: Partial<AppState>) => {\n const oldState = _state;\n _state = {..._state, ...newState};\n\n lsSet(\"state\", {\n accountId: _state.accountId,\n privateKey: _state.privateKey,\n lastWalletId: _state.lastWalletId,\n accessKeyContractId: _state.accessKeyContractId,\n });\n\n if (\n newState.hasOwnProperty(\"privateKey\") &&\n newState.privateKey !== oldState.privateKey\n ) {\n _state.publicKey = newState.privateKey\n ? publicKeyFromPrivate(newState.privateKey as string)\n : null;\n lsSet(\"nonce\", null);\n }\n\n if (newState.accountId !== oldState.accountId) {\n notifyAccountListeners(newState.accountId as string);\n }\n\n if (\n (newState.hasOwnProperty(\"lastWalletId\") &&\n newState.lastWalletId !== oldState.lastWalletId) ||\n (newState.hasOwnProperty(\"accountId\") &&\n newState.accountId !== oldState.accountId) ||\n (newState.hasOwnProperty(\"privateKey\") &&\n newState.privateKey !== oldState.privateKey)\n ) {\n _adapter.setState(getWalletAdapterState());\n }\n}\n\nexport const updateTxHistory = (txStatus: TxStatus) => {\n const txId = txStatus.txId;\n _txHistory[txId] = {\n ...(_txHistory[txId] || {}),\n ...txStatus,\n updateTimestamp: Date.now(),\n };\n lsSet(\"txHistory\", _txHistory);\n notifyTxListeners(_txHistory[txId]);\n}\n\n\n\n// Event Notifiers\nexport const notifyAccountListeners = (accountId: string) => {\n if (_eventListeners.account.size === 0) {\n _unbroadcastedEvents.account.push(accountId);\n return;\n }\n _eventListeners.account.forEach((callback) => {\n try {\n callback(accountId);\n } catch (e) {\n console.error(e);\n }\n });\n}\n\nexport const notifyTxListeners = (tx: TxStatus) => {\n if (_eventListeners.tx.size === 0) {\n _unbroadcastedEvents.tx.push(tx);\n return;\n }\n _eventListeners.tx.forEach((callback) => {\n try {\n callback(tx);\n } catch (e) {\n console.error(e);\n }\n });\n}\n\n// Event Handlers\nexport const onAccount = (callback: (accountId: string) => void) => {\n _eventListeners.account.add(callback);\n if (_unbroadcastedEvents.account.length > 0) {\n const events = _unbroadcastedEvents.account;\n _unbroadcastedEvents.account = [];\n events.forEach(notifyAccountListeners);\n }\n};\n\nexport const onTx = (callback: (tx: TxStatus) => void): void => {\n _eventListeners.tx.add(callback);\n if (_unbroadcastedEvents.tx.length > 0) {\n const events = _unbroadcastedEvents.tx;\n _unbroadcastedEvents.tx = [];\n events.forEach(notifyTxListeners);\n }\n};\n\nexport const getConfig = (): NetworkConfig => {\n return _config;\n}\n\nexport const getTxHistory = (): TxHistory => {\n return _txHistory;\n}\n\n// Exposed \"write\" functions\nexport const setConfig = (newConf: NetworkConfig): void => {\n _config = { ...NETWORKS[newConf.networkId], ...newConf };\n lsSet(\"config\", _config);\n}\n\nexport const resetTxHistory = (): void => {\n _txHistory = {};\n lsSet(\"tx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}
@@ -1,6 +1,18 @@
1
- import * as reExportUtils from '@fastnear/utils';
2
- import { reExportBorshSchema } from '@fastnear/utils';
1
+ import { WalletAdapter } from '@fastnear/wallet-adapter';
2
+ import * as borsh from 'borsh';
3
3
 
4
+ declare const WIDGET_URL = "https://wallet-adapter.fastnear.com";
5
+ declare const DEFAULT_NETWORK_ID = "mainnet";
6
+ declare const NETWORKS: {
7
+ testnet: {
8
+ networkId: string;
9
+ nodeUrl: string;
10
+ };
11
+ mainnet: {
12
+ networkId: string;
13
+ nodeUrl: string;
14
+ };
15
+ };
4
16
  interface NetworkConfig {
5
17
  networkId: string;
6
18
  nodeUrl?: string;
@@ -9,14 +21,66 @@ interface NetworkConfig {
9
21
  explorerUrl?: string;
10
22
  [key: string]: any;
11
23
  }
24
+ interface AppState {
25
+ accountId?: string | null;
26
+ privateKey?: string | null;
27
+ lastWalletId?: string | null;
28
+ publicKey?: string | null;
29
+ accessKeyContractId?: string | null;
30
+ [key: string]: any;
31
+ }
12
32
  interface TxStatus {
13
33
  txId: string;
14
34
  updateTimestamp?: number;
15
35
  [key: string]: any;
16
36
  }
17
37
  type TxHistory = Record<string, TxStatus>;
38
+ interface EventListeners {
39
+ account: Set<(accountId: string) => void>;
40
+ tx: Set<(tx: TxStatus) => void>;
41
+ }
42
+ interface UnbroadcastedEvents {
43
+ account: string[];
44
+ tx: TxStatus[];
45
+ }
46
+ interface WalletAdapterState {
47
+ publicKey?: string | null;
48
+ privateKey?: string | null;
49
+ accountId?: string | null;
50
+ lastWalletId?: string | null;
51
+ networkId: string;
52
+ }
53
+ declare let _config: NetworkConfig;
54
+ declare let _state: AppState;
55
+ declare const onAdapterStateUpdate: (state: WalletAdapterState) => void;
56
+ declare const getWalletAdapterState: () => WalletAdapterState;
57
+ declare let _adapter: WalletAdapter;
58
+ declare let _txHistory: TxHistory;
59
+ declare const _eventListeners: EventListeners;
60
+ declare const _unbroadcastedEvents: UnbroadcastedEvents;
61
+ declare const updateState: (newState: Partial<AppState>) => void;
62
+ declare const updateTxHistory: (txStatus: TxStatus) => void;
63
+ declare const notifyAccountListeners: (accountId: string) => void;
64
+ declare const notifyTxListeners: (tx: TxStatus) => void;
65
+ declare const onAccount: (callback: (accountId: string) => void) => void;
66
+ declare const onTx: (callback: (tx: TxStatus) => void) => void;
67
+ declare const getConfig: () => NetworkConfig;
68
+ declare const getTxHistory: () => TxHistory;
69
+ declare const setConfig: (newConf: NetworkConfig) => void;
70
+ declare const resetTxHistory: () => void;
18
71
 
19
72
  declare const MaxBlockDelayMs: number;
73
+ interface AccessKeyWithError {
74
+ nonce: number;
75
+ permission?: any;
76
+ error?: string;
77
+ }
78
+ interface BlockView {
79
+ header: {
80
+ prev_hash: string;
81
+ timestamp_nanosec: string;
82
+ };
83
+ }
20
84
  declare function withBlockId(params: Record<string, any>, blockId?: string): {
21
85
  finality: string;
22
86
  } | {
@@ -24,15 +88,31 @@ declare function withBlockId(params: Record<string, any>, blockId?: string): {
24
88
  };
25
89
  declare function queryRpc(method: string, params: Record<string, any> | any[]): Promise<any>;
26
90
  declare function afterTxSent(txId: string): void;
27
- declare function sendTxToRpc(signedTxBase64: string, waitUntil: string | undefined, txId: string): void;
91
+ declare function sendTxToRpc(signedTxBase64: string, waitUntil: string | undefined, txId: string): Promise<any>;
28
92
  interface AccessKeyView {
29
93
  nonce: number;
30
94
  permission: any;
31
95
  }
32
- declare const accountId: () => string;
33
- declare const publicKey: () => string;
96
+ /**
97
+ * Generates a mock transaction ID.
98
+ *
99
+ * This function creates a pseudo-unique transaction ID for testing or
100
+ * non-production use. It combines the current timestamp with a
101
+ * random component for uniqueness.
102
+ *
103
+ * **Note:** This is not cryptographically secure and should not be used
104
+ * for actual transaction processing.
105
+ *
106
+ * @returns {string} A mock transaction ID in the format `tx-{timestamp}-{random}`
107
+ */
108
+ declare function generateTxId(): string;
109
+ declare const accountId: () => string | null | undefined;
110
+ declare const publicKey: () => string | null | undefined;
34
111
  declare const config: (newConfig?: Record<string, any>) => NetworkConfig;
35
112
  declare const authStatus: () => string | Record<string, any>;
113
+ declare const requestSignIn: ({ contractId }: {
114
+ contractId: string;
115
+ }) => Promise<void>;
36
116
  declare const view: ({ contractId, methodName, args, argsBase64, blockId, }: {
37
117
  contractId: string;
38
118
  methodName: string;
@@ -40,32 +120,63 @@ declare const view: ({ contractId, methodName, args, argsBase64, blockId, }: {
40
120
  argsBase64?: string;
41
121
  blockId?: string;
42
122
  }) => Promise<any>;
43
- declare const account: ({ accountId, blockId, }: {
123
+ declare const queryAccount: ({ accountId, blockId, }: {
44
124
  accountId: string;
45
125
  blockId?: string;
46
126
  }) => Promise<any>;
47
- declare const block: ({ blockId }: {
127
+ declare const queryBlock: ({ blockId }: {
48
128
  blockId?: string;
49
- }) => Promise<any>;
50
- declare const accessKey: ({ accountId, publicKey, blockId, }: {
129
+ }) => Promise<BlockView>;
130
+ declare const queryAccessKey: ({ accountId, publicKey, blockId, }: {
51
131
  accountId: string;
52
132
  publicKey: string;
53
133
  blockId?: string;
54
- }) => Promise<AccessKeyView>;
55
- declare const tx: ({ txHash, accountId, }: {
134
+ }) => Promise<AccessKeyWithError>;
135
+ declare const queryTx: ({ txHash, accountId }: {
56
136
  txHash: string;
57
137
  accountId: string;
58
138
  }) => Promise<any>;
59
139
  declare const localTxHistory: () => TxHistory;
140
+ declare const signOut: () => void;
60
141
  declare const sendTx: ({ receiverId, actions, waitUntil, }: {
61
142
  receiverId: string;
62
143
  actions: any[];
63
144
  waitUntil?: string;
64
- }) => Promise<string>;
65
- declare const requestSignIn: ({ contractId }: {
66
- contractId: string;
67
- }) => Promise<void>;
68
- declare const signOut: () => void;
145
+ }) => Promise<any>;
146
+ declare const exp: {
147
+ utils: {};
148
+ borsh: {
149
+ serialize: typeof borsh.serialize;
150
+ deserialize: typeof borsh.deserialize;
151
+ };
152
+ borshSchema: {
153
+ Ed25519Signature: borsh.Schema;
154
+ Secp256k1Signature: borsh.Schema;
155
+ Signature: borsh.Schema;
156
+ Ed25519Data: borsh.Schema;
157
+ Secp256k1Data: borsh.Schema;
158
+ PublicKey: borsh.Schema;
159
+ FunctionCallPermission: borsh.Schema;
160
+ FullAccessPermission: borsh.Schema;
161
+ AccessKeyPermission: borsh.Schema;
162
+ AccessKey: borsh.Schema;
163
+ CreateAccount: borsh.Schema;
164
+ DeployContract: borsh.Schema;
165
+ FunctionCall: borsh.Schema;
166
+ Transfer: borsh.Schema;
167
+ Stake: borsh.Schema;
168
+ AddKey: borsh.Schema;
169
+ DeleteKey: borsh.Schema;
170
+ DeleteAccount: borsh.Schema;
171
+ ClassicAction: borsh.Schema;
172
+ DelegateAction: borsh.Schema;
173
+ SignedDelegate: borsh.Schema;
174
+ Action: borsh.Schema;
175
+ Transaction: borsh.Schema;
176
+ SignedTransaction: borsh.Schema;
177
+ };
178
+ };
179
+ declare const utils: {};
69
180
  declare const actions: {
70
181
  functionCall: ({ methodName, gas, deposit, args, argsBase64, }: {
71
182
  methodName: string;
@@ -76,10 +187,10 @@ declare const actions: {
76
187
  }) => {
77
188
  type: string;
78
189
  methodName: string;
79
- args: Record<string, any>;
80
- argsBase64: string;
81
- gas: string;
82
- deposit: string;
190
+ args: Record<string, any> | undefined;
191
+ argsBase64: string | undefined;
192
+ gas: string | undefined;
193
+ deposit: string | undefined;
83
194
  };
84
195
  transfer: (yoctoAmount: string) => {
85
196
  type: string;
@@ -139,10 +250,5 @@ declare const actions: {
139
250
  codeBase64: string;
140
251
  };
141
252
  };
142
- declare const reExports: {
143
- utils: typeof reExportUtils;
144
- borshSchema: typeof reExportBorshSchema;
145
- };
146
- declare const utils: typeof reExportUtils;
147
253
 
148
- export { type AccessKeyView, MaxBlockDelayMs, accessKey, account, accountId, actions, afterTxSent, authStatus, block, config, localTxHistory, publicKey, queryRpc, reExports, requestSignIn, sendTx, sendTxToRpc, signOut, tx, utils, view, withBlockId };
254
+ export { type AccessKeyView, type AppState, DEFAULT_NETWORK_ID, type EventListeners, MaxBlockDelayMs, NETWORKS, type NetworkConfig, type TxHistory, type TxStatus, type UnbroadcastedEvents, WIDGET_URL, type WalletAdapterState, _adapter, _config, _eventListeners, _state, _txHistory, _unbroadcastedEvents, accountId, actions, afterTxSent, authStatus, config, exp, generateTxId, getConfig, getTxHistory, getWalletAdapterState, localTxHistory, notifyAccountListeners, notifyTxListeners, onAccount, onAdapterStateUpdate, onTx, publicKey, queryAccessKey, queryAccount, queryBlock, queryRpc, queryTx, requestSignIn, resetTxHistory, sendTx, sendTxToRpc, setConfig, signOut, updateState, updateTxHistory, utils, view, withBlockId };
package/dist/esm/index.js CHANGED
@@ -1,8 +1,5 @@
1
- /* ⋈ 🏃🏻💨 FastNEAR API - ESM (@fastnear/api version 0.6.1) */
2
- /* https://www.npmjs.com/package/@fastnear/api/v/0.6.1 */
3
- import { convertUnit } from "@fastnear/utils";
4
- if (typeof window !== "undefined") {
5
- window.$$ = convertUnit;
6
- }
1
+ /* ⋈ 🏃🏻💨 FastNEAR API - ESM (@fastnear/api version 0.6.3) */
2
+ /* https://www.npmjs.com/package/@fastnear/api/v/0.6.3 */
3
+ export * from "./state.js";
7
4
  export * from "./near.js";
8
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { convertUnit } from \"@fastnear/utils\";\n\nif (typeof window !== \"undefined\") {\n // @ts-ignore\n window.$$ = convertUnit;\n}\n\nexport * from \"./near.js\";\n"],"mappings":";;AAAA,SAAS,mBAAmB;AAE5B,IAAI,OAAO,WAAW,aAAa;AAEjC,SAAO,KAAK;AACd;AAEA,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// See tsup.config.ts for additional banner/footer js\nexport * from \"./state.js\"\nexport * from \"./near.js\";\n"],"mappings":";;AACA,cAAc;AACd,cAAc;","names":[]}