@fastnear/wallet-adapter 0.1.0 → 0.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.
- package/dist/{index.cjs → cjs/index.js} +35 -18
- package/dist/cjs/index.js.map +7 -0
- package/dist/{index.js → esm/index.js} +32 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/umd/index.js +182 -0
- package/dist/umd/index.js.map +7 -0
- package/package.json +22 -13
- package/README.md +0 -174
- package/dist/index.d.ts +0 -199
- package/dist/index.d.ts.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR API - https://github.com/fastnear */
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// src/index.
|
|
20
|
+
// src/index.ts
|
|
20
21
|
var src_exports = {};
|
|
21
22
|
__export(src_exports, {
|
|
22
23
|
WalletAdapter: () => WalletAdapter
|
|
@@ -32,7 +33,7 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
32
33
|
/** @type {Map<string, Function>} */
|
|
33
34
|
#pending = /* @__PURE__ */ new Map();
|
|
34
35
|
/** @type {WalletState} */
|
|
35
|
-
#state
|
|
36
|
+
#state;
|
|
36
37
|
/** @type {Function} */
|
|
37
38
|
#onStateUpdate;
|
|
38
39
|
/** @type {string} */
|
|
@@ -40,18 +41,20 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
40
41
|
/** @type {string} */
|
|
41
42
|
static defaultWidgetUrl = "https://wallet-adapter.fastnear.com";
|
|
42
43
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
* @param {WalletAdapterConfig} [config]
|
|
45
|
+
*/
|
|
45
46
|
constructor({
|
|
46
47
|
widgetUrl = _WalletAdapter.defaultWidgetUrl,
|
|
47
48
|
targetOrigin = "*",
|
|
48
49
|
onStateUpdate,
|
|
50
|
+
lastState,
|
|
49
51
|
callbackUrl = window.location.href
|
|
50
52
|
} = {}) {
|
|
51
53
|
this.#targetOrigin = targetOrigin;
|
|
52
54
|
this.#widgetUrl = widgetUrl;
|
|
53
55
|
this.#onStateUpdate = onStateUpdate;
|
|
54
56
|
this.#callbackUrl = callbackUrl;
|
|
57
|
+
this.#state = lastState || {};
|
|
55
58
|
window.addEventListener("message", this.#handleMessage.bind(this));
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
@@ -88,8 +91,7 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
90
93
|
const { id, type, action, payload } = event.data;
|
|
91
|
-
if (type !== "wallet-adapter")
|
|
92
|
-
return;
|
|
94
|
+
if (type !== "wallet-adapter") return;
|
|
93
95
|
if (action === "close") {
|
|
94
96
|
this.#iframe?.remove();
|
|
95
97
|
this.#iframe = null;
|
|
@@ -120,16 +122,19 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
120
122
|
this.#pending.set(id, resolve);
|
|
121
123
|
const iframe = this.#createIframe(path);
|
|
122
124
|
iframe.onload = () => {
|
|
123
|
-
iframe.contentWindow?.postMessage(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
iframe.contentWindow?.postMessage(
|
|
126
|
+
{
|
|
127
|
+
type: "wallet-adapter",
|
|
128
|
+
method,
|
|
129
|
+
params: {
|
|
130
|
+
id,
|
|
131
|
+
...params,
|
|
132
|
+
state: this.#state,
|
|
133
|
+
callbackUrl: params.callbackUrl || this.#callbackUrl
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
this.#targetOrigin
|
|
137
|
+
);
|
|
133
138
|
};
|
|
134
139
|
});
|
|
135
140
|
}
|
|
@@ -140,6 +145,13 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
140
145
|
getState() {
|
|
141
146
|
return { ...this.#state };
|
|
142
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Set current wallet state
|
|
150
|
+
* @param state
|
|
151
|
+
*/
|
|
152
|
+
setState(state) {
|
|
153
|
+
this.#state = state;
|
|
154
|
+
}
|
|
143
155
|
/**
|
|
144
156
|
* Sign in with a NEAR wallet
|
|
145
157
|
* @param {SignInConfig} config
|
|
@@ -153,8 +165,8 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
153
165
|
* @param {TransactionConfig} config
|
|
154
166
|
* @returns {Promise<TransactionResult>}
|
|
155
167
|
*/
|
|
156
|
-
async
|
|
157
|
-
return this.#sendMessage("/
|
|
168
|
+
async sendTransactions(config) {
|
|
169
|
+
return this.#sendMessage("/send.html", "sendTransactions", config);
|
|
158
170
|
}
|
|
159
171
|
/**
|
|
160
172
|
* Clean up adapter resources
|
|
@@ -165,3 +177,8 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
165
177
|
this.#iframe = null;
|
|
166
178
|
}
|
|
167
179
|
};
|
|
180
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
181
|
+
0 && (module.exports = {
|
|
182
|
+
WalletAdapter
|
|
183
|
+
});
|
|
184
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @typedef {Object} WalletState\n * @property {string} [accountId] - NEAR account ID if signed in\n * @property {string} [publicKey] - Public key if available\n * @property {string} [privateKey] - Private key if available\n * @property {string} [lastWalletId] - ID of last used wallet\n * @property {string} [networkId] - ID of last used network\n */\n\n/**\n * @typedef {Object} SignInConfig\n * @property {string} networkId - NEAR network ID ('mainnet' or 'testnet')\n * @property {string} contractId - Contract ID to request access for\n * @property {string} [walletId] - Preferred wallet to use. E.g. 'near', 'here', 'meteor'\n * @property {string} [callbackUrl] - URL to redirect back to after wallet interaction\n */\n\n/**\n * @typedef {Object} SignInResult\n * @property {string} [url] - URL to redirect to if needed\n * @property {string} [accountId] - Account ID if immediately available\n * @property {string} [error] - Error message if sign in failed\n */\n\n/**\n * @typedef {Object} Transaction\n * @property {string} [signerId] - Transaction signer account ID\n * @property {string} receiverId - Transaction receiver account ID\n * @property {Object[]} actions - Transaction actions to perform\n */\n\n/**\n * @typedef {Object} TransactionConfig\n * @property {Transaction} transactions - Transaction actions to perform\n * @property {string} [callbackUrl] - URL to redirect back to after wallet interaction\n */\n\n/**\n * @typedef {Object} TransactionResult\n * @property {string} [url] - URL to redirect to if needed\n * @property {string} [hash] - Transaction hash if immediately available\n * @property {string} [error] - Error message if transaction failed\n */\n\nexport interface WalletAdapterConstructor {\n widgetUrl?: string;\n targetOrigin?: string;\n onStateUpdate?: (state: any) => void;\n lastState?: any;\n callbackUrl?: string;\n}\n\n/**\n * @typedef {Object} WalletAdapterConfig\n * @property {string} [widgetUrl] - URL of the wallet widget (defaults to official hosted version)\n * @property {string} [targetOrigin] - Target origin for postMessage (defaults to '*')\n * @property {string} [lastState] - The last state that was given by WalletAdapter before the redirect or reload.\n * @property {(state: WalletState) => void} [onStateUpdate] - Called when wallet state changes\n * @property {string} [callbackUrl] - Default callback URL for wallet interactions (defaults to current page URL)\n */\n\n/**\n * Interface for interacting with NEAR wallets\n */\nexport class WalletAdapter {\n /** @type {HTMLIFrameElement} */\n #iframe = null;\n\n /** @type {string} */\n #targetOrigin;\n\n /** @type {string} */\n #widgetUrl;\n\n /** @type {Map<string, Function>} */\n #pending = new Map();\n\n /** @type {WalletState} */\n #state;\n\n /** @type {Function} */\n #onStateUpdate;\n\n /** @type {string} */\n #callbackUrl;\n\n /** @type {string} */\n static defaultWidgetUrl = \"https://wallet-adapter.fastnear.com\";\n\n\n\n/**\n * @param {WalletAdapterConfig} [config]\n */\n constructor({\n widgetUrl = WalletAdapter.defaultWidgetUrl,\n targetOrigin = \"*\",\n onStateUpdate,\n lastState,\n callbackUrl = window.location.href,\n }: WalletAdapterConstructor = {}) {\n this.#targetOrigin = targetOrigin;\n this.#widgetUrl = widgetUrl;\n this.#onStateUpdate = onStateUpdate;\n this.#callbackUrl = callbackUrl;\n this.#state = lastState || {};\n window.addEventListener(\"message\", this.#handleMessage.bind(this));\n }\n\n /**\n * Creates an iframe for wallet interaction\n * @param {string} path - Path to load in iframe\n * @returns {HTMLIFrameElement}\n */\n #createIframe(path) {\n // Remove existing iframe if any\n if (this.#iframe) {\n this.#iframe.remove();\n }\n\n // Create URL\n const url = new URL(path, this.#widgetUrl);\n\n // Create and configure iframe\n const iframe = document.createElement(\"iframe\");\n iframe.src = url.toString();\n iframe.allow = \"usb\";\n iframe.style.border = \"none\";\n iframe.style.zIndex = \"10000\";\n iframe.style.position = \"fixed\";\n iframe.style.display = \"block\";\n iframe.style.top = \"0\";\n iframe.style.left = \"0\";\n iframe.style.width = \"100%\";\n iframe.style.height = \"100%\";\n document.body.appendChild(iframe);\n\n this.#iframe = iframe;\n return iframe;\n }\n\n /**\n * Handles messages from the wallet widget\n * @param {MessageEvent} event\n */\n #handleMessage(event) {\n // Check origin if specified\n if (this.#targetOrigin !== \"*\" && event.origin !== this.#targetOrigin) {\n return;\n }\n\n const { id, type, action, payload } = event.data;\n if (type !== \"wallet-adapter\") return;\n\n // Handle close action\n if (action === \"close\") {\n this.#iframe?.remove();\n this.#iframe = null;\n return;\n }\n\n // Update state if provided\n if (payload?.state) {\n this.#state = { ...this.#state, ...payload.state };\n this.#onStateUpdate?.(this.#state);\n }\n\n // Resolve pending promise if any\n const resolve = this.#pending.get(id);\n if (resolve) {\n this.#pending.delete(id);\n this.#iframe?.remove();\n this.#iframe = null;\n resolve(payload);\n }\n }\n\n /**\n * Sends a message to the wallet widget\n * @param {string} path - Path to load in iframe\n * @param {string} method - Method to call\n * @param {Object} params - Parameters to pass\n * @returns {Promise<any>}\n */\n async #sendMessage(path, method, params) {\n return new Promise((resolve) => {\n const id = Math.random().toString(36).slice(2);\n this.#pending.set(id, resolve);\n\n const iframe = this.#createIframe(path);\n\n iframe.onload = () => {\n iframe.contentWindow?.postMessage(\n {\n type: \"wallet-adapter\",\n method,\n params: {\n id,\n ...params,\n state: this.#state,\n callbackUrl: params.callbackUrl || this.#callbackUrl,\n },\n },\n this.#targetOrigin\n );\n };\n });\n }\n\n /**\n * Get current wallet state\n * @returns {WalletState}\n */\n getState() {\n return { ...this.#state };\n }\n\n /**\n * Set current wallet state\n * @param state\n */\n setState(state) {\n this.#state = state;\n }\n\n /**\n * Sign in with a NEAR wallet\n * @param {SignInConfig} config\n * @returns {Promise<SignInResult>}\n */\n async signIn(config) {\n return this.#sendMessage(\"/login.html\", \"signIn\", config);\n }\n\n /**\n * Send a transaction using connected wallet\n * @param {TransactionConfig} config\n * @returns {Promise<TransactionResult>}\n */\n async sendTransactions(config) {\n return this.#sendMessage(\"/send.html\", \"sendTransactions\", config);\n }\n\n /**\n * Clean up adapter resources\n */\n destroy() {\n window.removeEventListener(\"message\", this.#handleMessage);\n this.#iframe?.remove();\n this.#iframe = null;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgEO,IAAM,gBAAN,MAAM,eAAc;AAAA;AAAA,EAEzB,UAAU;AAAA;AAAA,EAGV;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,WAAW,oBAAI,IAAI;AAAA;AAAA,EAGnB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,OAAO,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAO1B,YAAY;AAAA,IACV,YAAY,eAAc;AAAA,IAC1B,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,cAAc,OAAO,SAAS;A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1
|
-
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR API - https://github.com/fastnear */
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
2
4
|
var WalletAdapter = class _WalletAdapter {
|
|
3
5
|
/** @type {HTMLIFrameElement} */
|
|
4
6
|
#iframe = null;
|
|
@@ -9,7 +11,7 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
9
11
|
/** @type {Map<string, Function>} */
|
|
10
12
|
#pending = /* @__PURE__ */ new Map();
|
|
11
13
|
/** @type {WalletState} */
|
|
12
|
-
#state
|
|
14
|
+
#state;
|
|
13
15
|
/** @type {Function} */
|
|
14
16
|
#onStateUpdate;
|
|
15
17
|
/** @type {string} */
|
|
@@ -17,18 +19,20 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
17
19
|
/** @type {string} */
|
|
18
20
|
static defaultWidgetUrl = "https://wallet-adapter.fastnear.com";
|
|
19
21
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
* @param {WalletAdapterConfig} [config]
|
|
23
|
+
*/
|
|
22
24
|
constructor({
|
|
23
25
|
widgetUrl = _WalletAdapter.defaultWidgetUrl,
|
|
24
26
|
targetOrigin = "*",
|
|
25
27
|
onStateUpdate,
|
|
28
|
+
lastState,
|
|
26
29
|
callbackUrl = window.location.href
|
|
27
30
|
} = {}) {
|
|
28
31
|
this.#targetOrigin = targetOrigin;
|
|
29
32
|
this.#widgetUrl = widgetUrl;
|
|
30
33
|
this.#onStateUpdate = onStateUpdate;
|
|
31
34
|
this.#callbackUrl = callbackUrl;
|
|
35
|
+
this.#state = lastState || {};
|
|
32
36
|
window.addEventListener("message", this.#handleMessage.bind(this));
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
@@ -65,8 +69,7 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
65
69
|
return;
|
|
66
70
|
}
|
|
67
71
|
const { id, type, action, payload } = event.data;
|
|
68
|
-
if (type !== "wallet-adapter")
|
|
69
|
-
return;
|
|
72
|
+
if (type !== "wallet-adapter") return;
|
|
70
73
|
if (action === "close") {
|
|
71
74
|
this.#iframe?.remove();
|
|
72
75
|
this.#iframe = null;
|
|
@@ -97,16 +100,19 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
97
100
|
this.#pending.set(id, resolve);
|
|
98
101
|
const iframe = this.#createIframe(path);
|
|
99
102
|
iframe.onload = () => {
|
|
100
|
-
iframe.contentWindow?.postMessage(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
iframe.contentWindow?.postMessage(
|
|
104
|
+
{
|
|
105
|
+
type: "wallet-adapter",
|
|
106
|
+
method,
|
|
107
|
+
params: {
|
|
108
|
+
id,
|
|
109
|
+
...params,
|
|
110
|
+
state: this.#state,
|
|
111
|
+
callbackUrl: params.callbackUrl || this.#callbackUrl
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
this.#targetOrigin
|
|
115
|
+
);
|
|
110
116
|
};
|
|
111
117
|
});
|
|
112
118
|
}
|
|
@@ -117,6 +123,13 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
117
123
|
getState() {
|
|
118
124
|
return { ...this.#state };
|
|
119
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Set current wallet state
|
|
128
|
+
* @param state
|
|
129
|
+
*/
|
|
130
|
+
setState(state) {
|
|
131
|
+
this.#state = state;
|
|
132
|
+
}
|
|
120
133
|
/**
|
|
121
134
|
* Sign in with a NEAR wallet
|
|
122
135
|
* @param {SignInConfig} config
|
|
@@ -130,8 +143,8 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
130
143
|
* @param {TransactionConfig} config
|
|
131
144
|
* @returns {Promise<TransactionResult>}
|
|
132
145
|
*/
|
|
133
|
-
async
|
|
134
|
-
return this.#sendMessage("/
|
|
146
|
+
async sendTransactions(config) {
|
|
147
|
+
return this.#sendMessage("/send.html", "sendTransactions", config);
|
|
135
148
|
}
|
|
136
149
|
/**
|
|
137
150
|
* Clean up adapter resources
|
|
@@ -145,3 +158,4 @@ var WalletAdapter = class _WalletAdapter {
|
|
|
145
158
|
export {
|
|
146
159
|
WalletAdapter
|
|
147
160
|
};
|
|
161
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @typedef {Object} WalletState\n * @property {string} [accountId] - NEAR account ID if signed in\n * @property {string} [publicKey] - Public key if available\n * @property {string} [privateKey] - Private key if available\n * @property {string} [lastWalletId] - ID of last used wallet\n * @property {string} [networkId] - ID of last used network\n */\n\n/**\n * @typedef {Object} SignInConfig\n * @property {string} networkId - NEAR network ID ('mainnet' or 'testnet')\n * @property {string} contractId - Contract ID to request access for\n * @property {string} [walletId] - Preferred wallet to use. E.g. 'near', 'here', 'meteor'\n * @property {string} [callbackUrl] - URL to redirect back to after wallet interaction\n */\n\n/**\n * @typedef {Object} SignInResult\n * @property {string} [url] - URL to redirect to if needed\n * @property {string} [accountId] - Account ID if immediately available\n * @property {string} [error] - Error message if sign in failed\n */\n\n/**\n * @typedef {Object} Transaction\n * @property {string} [signerId] - Transaction signer account ID\n * @property {string} receiverId - Transaction receiver account ID\n * @property {Object[]} actions - Transaction actions to perform\n */\n\n/**\n * @typedef {Object} TransactionConfig\n * @property {Transaction} transactions - Transaction actions to perform\n * @property {string} [callbackUrl] - URL to redirect back to after wallet interaction\n */\n\n/**\n * @typedef {Object} TransactionResult\n * @property {string} [url] - URL to redirect to if needed\n * @property {string} [hash] - Transaction hash if immediately available\n * @property {string} [error] - Error message if transaction failed\n */\n\nexport interface WalletAdapterConstructor {\n widgetUrl?: string;\n targetOrigin?: string;\n onStateUpdate?: (state: any) => void;\n lastState?: any;\n callbackUrl?: string;\n}\n\n/**\n * @typedef {Object} WalletAdapterConfig\n * @property {string} [widgetUrl] - URL of the wallet widget (defaults to official hosted version)\n * @property {string} [targetOrigin] - Target origin for postMessage (defaults to '*')\n * @property {string} [lastState] - The last state that was given by WalletAdapter before the redirect or reload.\n * @property {(state: WalletState) => void} [onStateUpdate] - Called when wallet state changes\n * @property {string} [callbackUrl] - Default callback URL for wallet interactions (defaults to current page URL)\n */\n\n/**\n * Interface for interacting with NEAR wallets\n */\nexport class WalletAdapter {\n /** @type {HTMLIFrameElement} */\n #iframe = null;\n\n /** @type {string} */\n #targetOrigin;\n\n /** @type {string} */\n #widgetUrl;\n\n /** @type {Map<string, Function>} */\n #pending = new Map();\n\n /** @type {WalletState} */\n #state;\n\n /** @type {Function} */\n #onStateUpdate;\n\n /** @type {string} */\n #callbackUrl;\n\n /** @type {string} */\n static defaultWidgetUrl = \"https://wallet-adapter.fastnear.com\";\n\n\n\n/**\n * @param {WalletAdapterConfig} [config]\n */\n constructor({\n widgetUrl = WalletAdapter.defaultWidgetUrl,\n targetOrigin = \"*\",\n onStateUpdate,\n lastState,\n callbackUrl = window.location.href,\n }: WalletAdapterConstructor = {}) {\n this.#targetOrigin = targetOrigin;\n this.#widgetUrl = widgetUrl;\n this.#onStateUpdate = onStateUpdate;\n this.#callbackUrl = callbackUrl;\n this.#state = lastState || {};\n window.addEventListener(\"message\", this.#handleMessage.bind(this));\n }\n\n /**\n * Creates an iframe for wallet interaction\n * @param {string} path - Path to load in iframe\n * @returns {HTMLIFrameElement}\n */\n #createIframe(path) {\n // Remove existing iframe if any\n if (this.#iframe) {\n this.#iframe.remove();\n }\n\n // Create URL\n const url = new URL(path, this.#widgetUrl);\n\n // Create and configure iframe\n const iframe = document.createElement(\"iframe\");\n iframe.src = url.toString();\n iframe.allow = \"usb\";\n iframe.style.border = \"none\";\n iframe.style.zIndex = \"10000\";\n iframe.style.position = \"fixed\";\n iframe.style.display = \"block\";\n iframe.style.top = \"0\";\n iframe.style.left = \"0\";\n iframe.style.width = \"100%\";\n iframe.style.height = \"100%\";\n document.body.appendChild(iframe);\n\n this.#iframe = iframe;\n return iframe;\n }\n\n /**\n * Handles messages from the wallet widget\n * @param {MessageEvent} event\n */\n #handleMessage(event) {\n // Check origin if specified\n if (this.#targetOrigin !== \"*\" && event.origin !== this.#targetOrigin) {\n return;\n }\n\n const { id, type, action, payload } = event.data;\n if (type !== \"wallet-adapter\") return;\n\n // Handle close action\n if (action === \"close\") {\n this.#iframe?.remove();\n this.#iframe = null;\n return;\n }\n\n // Update state if provided\n if (payload?.state) {\n this.#state = { ...this.#state, ...payload.state };\n this.#onStateUpdate?.(this.#state);\n }\n\n // Resolve pending promise if any\n const resolve = this.#pending.get(id);\n if (resolve) {\n this.#pending.delete(id);\n this.#iframe?.remove();\n this.#iframe = null;\n resolve(payload);\n }\n }\n\n /**\n * Sends a message to the wallet widget\n * @param {string} path - Path to load in iframe\n * @param {string} method - Method to call\n * @param {Object} params - Parameters to pass\n * @returns {Promise<any>}\n */\n async #sendMessage(path, method, params) {\n return new Promise((resolve) => {\n const id = Math.random().toString(36).slice(2);\n this.#pending.set(id, resolve);\n\n const iframe = this.#createIframe(path);\n\n iframe.onload = () => {\n iframe.contentWindow?.postMessage(\n {\n type: \"wallet-adapter\",\n method,\n params: {\n id,\n ...params,\n state: this.#state,\n callbackUrl: params.callbackUrl || this.#callbackUrl,\n },\n },\n this.#targetOrigin\n );\n };\n });\n }\n\n /**\n * Get current wallet state\n * @returns {WalletState}\n */\n getState() {\n return { ...this.#state };\n }\n\n /**\n * Set current wallet state\n * @param state\n */\n setState(state) {\n this.#state = state;\n }\n\n /**\n * Sign in with a NEAR wallet\n * @param {SignInConfig} config\n * @returns {Promise<SignInResult>}\n */\n async signIn(config) {\n return this.#sendMessage(\"/login.html\", \"signIn\", config);\n }\n\n /**\n * Send a transaction using connected wallet\n * @param {TransactionConfig} config\n * @returns {Promise<TransactionResult>}\n */\n async sendTransactions(config) {\n return this.#sendMessage(\"/send.html\", \"sendTransactions\", config);\n }\n\n /**\n * Clean up adapter resources\n */\n destroy() {\n window.removeEventListener(\"message\", this.#handleMessage);\n this.#iframe?.remove();\n this.#iframe = null;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAgEO,IAAM,gBAAN,MAAM,eAAc;AAAA;AAAA,EAEzB,UAAU;AAAA;AAAA,EAGV;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,WAAW,oBAAI,IAAI;AAAA;AAAA,EAGnB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,OAAO,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAO1B,YAAY;AAAA,IACV,YAAY,eAAc;AAAA,IAC1B,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,cAAc,OAAO,SAAS;AAAA,EAChC,IAA8B,CAAC,GAAG;AAChC,SAAK,gBAAgB;AACrB,SAAK,aAAa;AAClB,SAAK,iBAAiB;AACtB,SAAK,eAAe;AACpB,SAAK,SAAS,aAAa,CAAC;AAC5B,WAAO,iBAAiB,WAAW,KAAK,eAAe,KAAK,IAAI,CAAC;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAc,MAAM;AAElB,QAAI,KAAK,SAAS;AAChB,WAAK,QAAQ,OAAO;AAAA,IACtB;AAGA,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,UAAU;AAGzC,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM,IAAI,SAAS;AAC1B,WAAO,QAAQ;AACf,WAAO,MAAM,SAAS;AACtB,WAAO,MAAM,SAAS;AACtB,WAAO,MAAM,WAAW;AACxB,WAAO,MAAM,UAAU;AACvB,WAAO,MAAM,MAAM;AACnB,WAAO,MAAM,OAAO;AACpB,WAAO,MAAM,QAAQ;AACrB,WAAO,MAAM,SAAS;AACtB,aAAS,KAAK,YAAY,MAAM;AAEhC,SAAK,UAAU;AACf,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe,OAAO;AAE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,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,OAAO,QAAQ;AACnB,WAAO,KAAK,aAAa,eAAe,UAAU,MAAM;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,iBAAiB,QAAQ;AAC7B,WAAO,KAAK,aAAa,cAAc,oBAAoB,MAAM;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU;AACR,WAAO,oBAAoB,WAAW,KAAK,cAAc;AACzD,SAAK,SAAS,OAAO;AACrB,SAAK,UAAU;AAAA,EACjB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR API - https://github.com/fastnear */
|
|
2
|
+
var nearWalletAdapter = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
WalletAdapter: () => WalletAdapter
|
|
25
|
+
});
|
|
26
|
+
var WalletAdapter = class _WalletAdapter {
|
|
27
|
+
/** @type {HTMLIFrameElement} */
|
|
28
|
+
#iframe = null;
|
|
29
|
+
/** @type {string} */
|
|
30
|
+
#targetOrigin;
|
|
31
|
+
/** @type {string} */
|
|
32
|
+
#widgetUrl;
|
|
33
|
+
/** @type {Map<string, Function>} */
|
|
34
|
+
#pending = /* @__PURE__ */ new Map();
|
|
35
|
+
/** @type {WalletState} */
|
|
36
|
+
#state;
|
|
37
|
+
/** @type {Function} */
|
|
38
|
+
#onStateUpdate;
|
|
39
|
+
/** @type {string} */
|
|
40
|
+
#callbackUrl;
|
|
41
|
+
/** @type {string} */
|
|
42
|
+
static defaultWidgetUrl = "https://wallet-adapter.fastnear.com";
|
|
43
|
+
/**
|
|
44
|
+
* @param {WalletAdapterConfig} [config]
|
|
45
|
+
*/
|
|
46
|
+
constructor({
|
|
47
|
+
widgetUrl = _WalletAdapter.defaultWidgetUrl,
|
|
48
|
+
targetOrigin = "*",
|
|
49
|
+
onStateUpdate,
|
|
50
|
+
lastState,
|
|
51
|
+
callbackUrl = window.location.href
|
|
52
|
+
} = {}) {
|
|
53
|
+
this.#targetOrigin = targetOrigin;
|
|
54
|
+
this.#widgetUrl = widgetUrl;
|
|
55
|
+
this.#onStateUpdate = onStateUpdate;
|
|
56
|
+
this.#callbackUrl = callbackUrl;
|
|
57
|
+
this.#state = lastState || {};
|
|
58
|
+
window.addEventListener("message", this.#handleMessage.bind(this));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates an iframe for wallet interaction
|
|
62
|
+
* @param {string} path - Path to load in iframe
|
|
63
|
+
* @returns {HTMLIFrameElement}
|
|
64
|
+
*/
|
|
65
|
+
#createIframe(path) {
|
|
66
|
+
if (this.#iframe) {
|
|
67
|
+
this.#iframe.remove();
|
|
68
|
+
}
|
|
69
|
+
const url = new URL(path, this.#widgetUrl);
|
|
70
|
+
const iframe = document.createElement("iframe");
|
|
71
|
+
iframe.src = url.toString();
|
|
72
|
+
iframe.allow = "usb";
|
|
73
|
+
iframe.style.border = "none";
|
|
74
|
+
iframe.style.zIndex = "10000";
|
|
75
|
+
iframe.style.position = "fixed";
|
|
76
|
+
iframe.style.display = "block";
|
|
77
|
+
iframe.style.top = "0";
|
|
78
|
+
iframe.style.left = "0";
|
|
79
|
+
iframe.style.width = "100%";
|
|
80
|
+
iframe.style.height = "100%";
|
|
81
|
+
document.body.appendChild(iframe);
|
|
82
|
+
this.#iframe = iframe;
|
|
83
|
+
return iframe;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Handles messages from the wallet widget
|
|
87
|
+
* @param {MessageEvent} event
|
|
88
|
+
*/
|
|
89
|
+
#handleMessage(event) {
|
|
90
|
+
if (this.#targetOrigin !== "*" && event.origin !== this.#targetOrigin) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const { id, type, action, payload } = event.data;
|
|
94
|
+
if (type !== "wallet-adapter") return;
|
|
95
|
+
if (action === "close") {
|
|
96
|
+
this.#iframe?.remove();
|
|
97
|
+
this.#iframe = null;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (payload?.state) {
|
|
101
|
+
this.#state = { ...this.#state, ...payload.state };
|
|
102
|
+
this.#onStateUpdate?.(this.#state);
|
|
103
|
+
}
|
|
104
|
+
const resolve = this.#pending.get(id);
|
|
105
|
+
if (resolve) {
|
|
106
|
+
this.#pending.delete(id);
|
|
107
|
+
this.#iframe?.remove();
|
|
108
|
+
this.#iframe = null;
|
|
109
|
+
resolve(payload);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sends a message to the wallet widget
|
|
114
|
+
* @param {string} path - Path to load in iframe
|
|
115
|
+
* @param {string} method - Method to call
|
|
116
|
+
* @param {Object} params - Parameters to pass
|
|
117
|
+
* @returns {Promise<any>}
|
|
118
|
+
*/
|
|
119
|
+
async #sendMessage(path, method, params) {
|
|
120
|
+
return new Promise((resolve) => {
|
|
121
|
+
const id = Math.random().toString(36).slice(2);
|
|
122
|
+
this.#pending.set(id, resolve);
|
|
123
|
+
const iframe = this.#createIframe(path);
|
|
124
|
+
iframe.onload = () => {
|
|
125
|
+
iframe.contentWindow?.postMessage(
|
|
126
|
+
{
|
|
127
|
+
type: "wallet-adapter",
|
|
128
|
+
method,
|
|
129
|
+
params: {
|
|
130
|
+
id,
|
|
131
|
+
...params,
|
|
132
|
+
state: this.#state,
|
|
133
|
+
callbackUrl: params.callbackUrl || this.#callbackUrl
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
this.#targetOrigin
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get current wallet state
|
|
143
|
+
* @returns {WalletState}
|
|
144
|
+
*/
|
|
145
|
+
getState() {
|
|
146
|
+
return { ...this.#state };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Set current wallet state
|
|
150
|
+
* @param state
|
|
151
|
+
*/
|
|
152
|
+
setState(state) {
|
|
153
|
+
this.#state = state;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Sign in with a NEAR wallet
|
|
157
|
+
* @param {SignInConfig} config
|
|
158
|
+
* @returns {Promise<SignInResult>}
|
|
159
|
+
*/
|
|
160
|
+
async signIn(config) {
|
|
161
|
+
return this.#sendMessage("/login.html", "signIn", config);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Send a transaction using connected wallet
|
|
165
|
+
* @param {TransactionConfig} config
|
|
166
|
+
* @returns {Promise<TransactionResult>}
|
|
167
|
+
*/
|
|
168
|
+
async sendTransactions(config) {
|
|
169
|
+
return this.#sendMessage("/send.html", "sendTransactions", config);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Clean up adapter resources
|
|
173
|
+
*/
|
|
174
|
+
destroy() {
|
|
175
|
+
window.removeEventListener("message", this.#handleMessage);
|
|
176
|
+
this.#iframe?.remove();
|
|
177
|
+
this.#iframe = null;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return __toCommonJS(src_exports);
|
|
181
|
+
})();
|
|
182
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @typedef {Object} WalletState\n * @property {string} [accountId] - NEAR account ID if signed in\n * @property {string} [publicKey] - Public key if available\n * @property {string} [privateKey] - Private key if available\n * @property {string} [lastWalletId] - ID of last used wallet\n * @property {string} [networkId] - ID of last used network\n */\n\n/**\n * @typedef {Object} SignInConfig\n * @property {string} networkId - NEAR network ID ('mainnet' or 'testnet')\n * @property {string} contractId - Contract ID to request access for\n * @property {string} [walletId] - Preferred wallet to use. E.g. 'near', 'here', 'meteor'\n * @property {string} [callbackUrl] - URL to redirect back to after wallet interaction\n */\n\n/**\n * @typedef {Object} SignInResult\n * @property {string} [url] - URL to redirect to if needed\n * @property {string} [accountId] - Account ID if immediately available\n * @property {string} [error] - Error message if sign in failed\n */\n\n/**\n * @typedef {Object} Transaction\n * @property {string} [signerId] - Transaction signer account ID\n * @property {string} receiverId - Transaction receiver account ID\n * @property {Object[]} actions - Transaction actions to perform\n */\n\n/**\n * @typedef {Object} TransactionConfig\n * @property {Transaction} transactions - Transaction actions to perform\n * @property {string} [callbackUrl] - URL to redirect back to after wallet interaction\n */\n\n/**\n * @typedef {Object} TransactionResult\n * @property {string} [url] - URL to redirect to if needed\n * @property {string} [hash] - Transaction hash if immediately available\n * @property {string} [error] - Error message if transaction failed\n */\n\nexport interface WalletAdapterConstructor {\n widgetUrl?: string;\n targetOrigin?: string;\n onStateUpdate?: (state: any) => void;\n lastState?: any;\n callbackUrl?: string;\n}\n\n/**\n * @typedef {Object} WalletAdapterConfig\n * @property {string} [widgetUrl] - URL of the wallet widget (defaults to official hosted version)\n * @property {string} [targetOrigin] - Target origin for postMessage (defaults to '*')\n * @property {string} [lastState] - The last state that was given by WalletAdapter before the redirect or reload.\n * @property {(state: WalletState) => void} [onStateUpdate] - Called when wallet state changes\n * @property {string} [callbackUrl] - Default callback URL for wallet interactions (defaults to current page URL)\n */\n\n/**\n * Interface for interacting with NEAR wallets\n */\nexport class WalletAdapter {\n /** @type {HTMLIFrameElement} */\n #iframe = null;\n\n /** @type {string} */\n #targetOrigin;\n\n /** @type {string} */\n #widgetUrl;\n\n /** @type {Map<string, Function>} */\n #pending = new Map();\n\n /** @type {WalletState} */\n #state;\n\n /** @type {Function} */\n #onStateUpdate;\n\n /** @type {string} */\n #callbackUrl;\n\n /** @type {string} */\n static defaultWidgetUrl = \"https://wallet-adapter.fastnear.com\";\n\n\n\n/**\n * @param {WalletAdapterConfig} [config]\n */\n constructor({\n widgetUrl = WalletAdapter.defaultWidgetUrl,\n targetOrigin = \"*\",\n onStateUpdate,\n lastState,\n callbackUrl = window.location.href,\n }: WalletAdapterConstructor = {}) {\n this.#targetOrigin = targetOrigin;\n this.#widgetUrl = widgetUrl;\n this.#onStateUpdate = onStateUpdate;\n this.#callbackUrl = callbackUrl;\n this.#state = lastState || {};\n window.addEventListener(\"message\", this.#handleMessage.bind(this));\n }\n\n /**\n * Creates an iframe for wallet interaction\n * @param {string} path - Path to load in iframe\n * @returns {HTMLIFrameElement}\n */\n #createIframe(path) {\n // Remove existing iframe if any\n if (this.#iframe) {\n this.#iframe.remove();\n }\n\n // Create URL\n const url = new URL(path, this.#widgetUrl);\n\n // Create and configure iframe\n const iframe = document.createElement(\"iframe\");\n iframe.src = url.toString();\n iframe.allow = \"usb\";\n iframe.style.border = \"none\";\n iframe.style.zIndex = \"10000\";\n iframe.style.position = \"fixed\";\n iframe.style.display = \"block\";\n iframe.style.top = \"0\";\n iframe.style.left = \"0\";\n iframe.style.width = \"100%\";\n iframe.style.height = \"100%\";\n document.body.appendChild(iframe);\n\n this.#iframe = iframe;\n return iframe;\n }\n\n /**\n * Handles messages from the wallet widget\n * @param {MessageEvent} event\n */\n #handleMessage(event) {\n // Check origin if specified\n if (this.#targetOrigin !== \"*\" && event.origin !== this.#targetOrigin) {\n return;\n }\n\n const { id, type, action, payload } = event.data;\n if (type !== \"wallet-adapter\") return;\n\n // Handle close action\n if (action === \"close\") {\n this.#iframe?.remove();\n this.#iframe = null;\n return;\n }\n\n // Update state if provided\n if (payload?.state) {\n this.#state = { ...this.#state, ...payload.state };\n this.#onStateUpdate?.(this.#state);\n }\n\n // Resolve pending promise if any\n const resolve = this.#pending.get(id);\n if (resolve) {\n this.#pending.delete(id);\n this.#iframe?.remove();\n this.#iframe = null;\n resolve(payload);\n }\n }\n\n /**\n * Sends a message to the wallet widget\n * @param {string} path - Path to load in iframe\n * @param {string} method - Method to call\n * @param {Object} params - Parameters to pass\n * @returns {Promise<any>}\n */\n async #sendMessage(path, method, params) {\n return new Promise((resolve) => {\n const id = Math.random().toString(36).slice(2);\n this.#pending.set(id, resolve);\n\n const iframe = this.#createIframe(path);\n\n iframe.onload = () => {\n iframe.contentWindow?.postMessage(\n {\n type: \"wallet-adapter\",\n method,\n params: {\n id,\n ...params,\n state: this.#state,\n callbackUrl: params.callbackUrl || this.#callbackUrl,\n },\n },\n this.#targetOrigin\n );\n };\n });\n }\n\n /**\n * Get current wallet state\n * @returns {WalletState}\n */\n getState() {\n return { ...this.#state };\n }\n\n /**\n * Set current wallet state\n * @param state\n */\n setState(state) {\n this.#state = state;\n }\n\n /**\n * Sign in with a NEAR wallet\n * @param {SignInConfig} config\n * @returns {Promise<SignInResult>}\n */\n async signIn(config) {\n return this.#sendMessage(\"/login.html\", \"signIn\", config);\n }\n\n /**\n * Send a transaction using connected wallet\n * @param {TransactionConfig} config\n * @returns {Promise<TransactionResult>}\n */\n async sendTransactions(config) {\n return this.#sendMessage(\"/send.html\", \"sendTransactions\", config);\n }\n\n /**\n * Clean up adapter resources\n */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AAA;AAAA;AAAA;AAAA,IAMA,SAAS,OAAO;AACd,WAAK,SAAS;AAAA,IAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,MAAM,OAAO,QAAQ;AACnB,aAAO,KAAK,aAAa,eAAe,UAAU,MAAM;AAAA,IAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,MAAM,iBAAiB,QAAQ;AAC7B,aAAO,KAAK,aAAa,cAAc,oBAAoB,MAAM;AAAA,IACnE;AAAA;AAAA;AAAA;AAAA,IAKA,UAAU;AACR,aAAO,oBAAoB,WAAW,KAAK,cAAc;AACzD,WAAK,SAAS,OAAO;AACrB,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastnear/wallet-adapter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"repository": "https://github.com/fastnear/wallet-adapter.git",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Optimized interfaces for a NEAR Protocol wallet adapter",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"main": "./dist/index.cjs",
|
|
8
|
-
"module": "./dist/index.js",
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"files": ["dist"],
|
|
11
6
|
"scripts": {
|
|
12
|
-
"build": "node
|
|
13
|
-
"
|
|
14
|
-
"
|
|
7
|
+
"build": "node esbuild.config.mjs",
|
|
8
|
+
"publish": "yarn npm publish",
|
|
9
|
+
"clean": "yarn rimraf dist node_modules"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"near-protocol",
|
|
13
|
+
"blockchain",
|
|
14
|
+
"fastnear"
|
|
15
|
+
],
|
|
16
|
+
"author": "FastNEAR",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"require": "./dist/cjs/index.js",
|
|
23
|
+
"import": "./dist/esm/index.js"
|
|
24
|
+
}
|
|
15
25
|
},
|
|
16
26
|
"devDependencies": {
|
|
17
|
-
"
|
|
18
|
-
"typescript": "^5.0.0"
|
|
27
|
+
"rimraf": "*"
|
|
19
28
|
}
|
|
20
|
-
}
|
|
29
|
+
}
|
package/README.md
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
# @fastnear/wallet-adapter
|
|
2
|
-
|
|
3
|
-
A lightweight, dependency-free client interface for integrating NEAR wallets into your dApp.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🚀 Zero dependencies
|
|
8
|
-
- 📱 Works with all major NEAR wallets
|
|
9
|
-
- 💪 Full TypeScript support
|
|
10
|
-
- 🔒 Secure iframe-based design
|
|
11
|
-
- 📦 ESM and CommonJS support
|
|
12
|
-
- 🎯 Simple, promise-based API
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install @fastnear/wallet-adapter
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Basic Usage
|
|
21
|
-
|
|
22
|
-
```javascript
|
|
23
|
-
import { WalletAdapter } from '@fastnear/wallet-adapter';
|
|
24
|
-
|
|
25
|
-
// Create adapter instance
|
|
26
|
-
const adapter = new WalletAdapter();
|
|
27
|
-
|
|
28
|
-
// Sign in
|
|
29
|
-
const result = await adapter.signIn({
|
|
30
|
-
networkId: 'mainnet',
|
|
31
|
-
contractId: 'example.near',
|
|
32
|
-
wallet: 'near' // optional, defaults to user choice
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (result.url) {
|
|
36
|
-
// Redirect to wallet
|
|
37
|
-
window.location.href = result.url;
|
|
38
|
-
} else if (result.accountId) {
|
|
39
|
-
console.log('Signed in as:', result.accountId);
|
|
40
|
-
} else if (result.error) {
|
|
41
|
-
console.error('Failed to sign in:', result.error);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Send transaction
|
|
45
|
-
const txResult = await adapter.sendTransaction({
|
|
46
|
-
receiverId: 'example.near',
|
|
47
|
-
actions: [{
|
|
48
|
-
type: 'FunctionCall',
|
|
49
|
-
params: {
|
|
50
|
-
methodName: 'example_method',
|
|
51
|
-
args: { /* ... */ },
|
|
52
|
-
gas: '30000000000000',
|
|
53
|
-
deposit: '0'
|
|
54
|
-
}
|
|
55
|
-
}]
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (txResult.url) {
|
|
59
|
-
window.location.href = txResult.url;
|
|
60
|
-
} else if (txResult.hash) {
|
|
61
|
-
console.log('Transaction hash:', txResult.hash);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Clean up when done
|
|
65
|
-
adapter.destroy();
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Advanced Configuration
|
|
69
|
-
|
|
70
|
-
```javascript
|
|
71
|
-
const adapter = new WalletAdapter({
|
|
72
|
-
// Custom widget URL (defaults to official hosted version)
|
|
73
|
-
widgetUrl: 'https://your-domain.com/wallet-widget/',
|
|
74
|
-
|
|
75
|
-
// Restrict message origin for security (defaults to '*')
|
|
76
|
-
targetOrigin: 'https://your-domain.com',
|
|
77
|
-
|
|
78
|
-
// Handle wallet state updates
|
|
79
|
-
onStateUpdate: (state) => {
|
|
80
|
-
localStorage.setItem('wallet-state', JSON.stringify(state));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## API Reference
|
|
86
|
-
|
|
87
|
-
### `new WalletAdapter(config?)`
|
|
88
|
-
|
|
89
|
-
Creates a new wallet adapter instance.
|
|
90
|
-
|
|
91
|
-
#### Config Options
|
|
92
|
-
- `widgetUrl?: string` - URL of the wallet widget (defaults to official hosted version)
|
|
93
|
-
- `targetOrigin?: string` - Target origin for postMessage (defaults to '*')
|
|
94
|
-
- `onStateUpdate?: (state: WalletState) => void` - Called when wallet state changes
|
|
95
|
-
|
|
96
|
-
### `signIn(config)`
|
|
97
|
-
|
|
98
|
-
Signs in with a NEAR wallet.
|
|
99
|
-
|
|
100
|
-
#### Config
|
|
101
|
-
```typescript
|
|
102
|
-
{
|
|
103
|
-
networkId: 'mainnet' | 'testnet',
|
|
104
|
-
contractId: string,
|
|
105
|
-
wallet?: 'near' | 'here' | 'meteor'
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
#### Returns
|
|
110
|
-
```typescript
|
|
111
|
-
Promise<{
|
|
112
|
-
url?: string, // URL to redirect to if needed
|
|
113
|
-
accountId?: string, // Account ID if immediately available
|
|
114
|
-
error?: string // Error message if sign in failed
|
|
115
|
-
}>
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### `sendTransaction(config)`
|
|
119
|
-
|
|
120
|
-
Sends a transaction using the connected wallet.
|
|
121
|
-
|
|
122
|
-
#### Config
|
|
123
|
-
```typescript
|
|
124
|
-
{
|
|
125
|
-
receiverId: string,
|
|
126
|
-
actions: Array<{
|
|
127
|
-
type: string,
|
|
128
|
-
params: {
|
|
129
|
-
methodName?: string,
|
|
130
|
-
args?: Object,
|
|
131
|
-
gas?: string,
|
|
132
|
-
deposit?: string
|
|
133
|
-
}
|
|
134
|
-
}>,
|
|
135
|
-
wallet?: 'near' | 'here' | 'meteor'
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### Returns
|
|
140
|
-
```typescript
|
|
141
|
-
Promise<{
|
|
142
|
-
url?: string, // URL to redirect to if needed
|
|
143
|
-
hash?: string, // Transaction hash if immediately available
|
|
144
|
-
error?: string // Error message if transaction failed
|
|
145
|
-
}>
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### `getState()`
|
|
149
|
-
|
|
150
|
-
Gets current wallet state.
|
|
151
|
-
|
|
152
|
-
#### Returns
|
|
153
|
-
```typescript
|
|
154
|
-
{
|
|
155
|
-
accountId?: string, // NEAR account ID if signed in
|
|
156
|
-
publicKey?: string, // Public key if available
|
|
157
|
-
privateKey?: string, // Private key if available
|
|
158
|
-
lastWalletId?: string // ID of last used wallet
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### `destroy()`
|
|
163
|
-
|
|
164
|
-
Cleans up adapter resources. Should be called when adapter is no longer needed.
|
|
165
|
-
|
|
166
|
-
## Supported Wallets
|
|
167
|
-
|
|
168
|
-
- NEAR Wallet (MyNearWallet)
|
|
169
|
-
- HERE Wallet
|
|
170
|
-
- Meteor Wallet
|
|
171
|
-
|
|
172
|
-
## License
|
|
173
|
-
|
|
174
|
-
MIT
|
package/dist/index.d.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} WalletState
|
|
3
|
-
* @property {string} [accountId] - NEAR account ID if signed in
|
|
4
|
-
* @property {string} [publicKey] - Public key if available
|
|
5
|
-
* @property {string} [privateKey] - Private key if available
|
|
6
|
-
* @property {string} [lastWalletId] - ID of last used wallet
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {Object} WalletAction
|
|
10
|
-
* @property {string} type - Action type
|
|
11
|
-
* @property {Object} [args] - Action arguments
|
|
12
|
-
* @property {string|number} [gas] - Gas to attach
|
|
13
|
-
* @property {string|number} [deposit] - Deposit to attach
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {Object} SignInConfig
|
|
17
|
-
* @property {string} networkId - NEAR network ID ('mainnet' or 'testnet')
|
|
18
|
-
* @property {string} contractId - Contract ID to request access for
|
|
19
|
-
* @property {'near'|'here'|'meteor'} [wallet] - Preferred wallet to use
|
|
20
|
-
* @property {string} [callbackUrl] - URL to redirect back to after wallet interaction
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* @typedef {Object} SignInResult
|
|
24
|
-
* @property {string} [url] - URL to redirect to if needed
|
|
25
|
-
* @property {string} [accountId] - Account ID if immediately available
|
|
26
|
-
* @property {string} [error] - Error message if sign in failed
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* @typedef {Object} TransactionConfig
|
|
30
|
-
* @property {string} receiverId - Transaction receiver account ID
|
|
31
|
-
* @property {WalletAction[]} actions - Transaction actions to perform
|
|
32
|
-
* @property {'near'|'here'|'meteor'} [wallet] - Preferred wallet to use
|
|
33
|
-
* @property {string} [callbackUrl] - URL to redirect back to after wallet interaction
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {Object} TransactionResult
|
|
37
|
-
* @property {string} [url] - URL to redirect to if needed
|
|
38
|
-
* @property {string} [hash] - Transaction hash if immediately available
|
|
39
|
-
* @property {string} [error] - Error message if transaction failed
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* @typedef {Object} WalletAdapterConfig
|
|
43
|
-
* @property {string} [widgetUrl] - URL of the wallet widget (defaults to official hosted version)
|
|
44
|
-
* @property {string} [targetOrigin] - Target origin for postMessage (defaults to '*')
|
|
45
|
-
* @property {(state: WalletState) => void} [onStateUpdate] - Called when wallet state changes
|
|
46
|
-
* @property {string} [callbackUrl] - Default callback URL for wallet interactions (defaults to current page URL)
|
|
47
|
-
*/
|
|
48
|
-
/**
|
|
49
|
-
* Interface for interacting with NEAR wallets
|
|
50
|
-
*/
|
|
51
|
-
export class WalletAdapter {
|
|
52
|
-
/** @type {string} */
|
|
53
|
-
static defaultWidgetUrl: string;
|
|
54
|
-
/**
|
|
55
|
-
* @param {WalletAdapterConfig} [config]
|
|
56
|
-
*/
|
|
57
|
-
constructor({ widgetUrl, targetOrigin, onStateUpdate, callbackUrl }?: WalletAdapterConfig);
|
|
58
|
-
/**
|
|
59
|
-
* Get current wallet state
|
|
60
|
-
* @returns {WalletState}
|
|
61
|
-
*/
|
|
62
|
-
getState(): WalletState;
|
|
63
|
-
/**
|
|
64
|
-
* Sign in with a NEAR wallet
|
|
65
|
-
* @param {SignInConfig} config
|
|
66
|
-
* @returns {Promise<SignInResult>}
|
|
67
|
-
*/
|
|
68
|
-
signIn(config: SignInConfig): Promise<SignInResult>;
|
|
69
|
-
/**
|
|
70
|
-
* Send a transaction using connected wallet
|
|
71
|
-
* @param {TransactionConfig} config
|
|
72
|
-
* @returns {Promise<TransactionResult>}
|
|
73
|
-
*/
|
|
74
|
-
sendTransaction(config: TransactionConfig): Promise<TransactionResult>;
|
|
75
|
-
/**
|
|
76
|
-
* Clean up adapter resources
|
|
77
|
-
*/
|
|
78
|
-
destroy(): void;
|
|
79
|
-
#private;
|
|
80
|
-
}
|
|
81
|
-
export type WalletState = {
|
|
82
|
-
/**
|
|
83
|
-
* - NEAR account ID if signed in
|
|
84
|
-
*/
|
|
85
|
-
accountId?: string;
|
|
86
|
-
/**
|
|
87
|
-
* - Public key if available
|
|
88
|
-
*/
|
|
89
|
-
publicKey?: string;
|
|
90
|
-
/**
|
|
91
|
-
* - Private key if available
|
|
92
|
-
*/
|
|
93
|
-
privateKey?: string;
|
|
94
|
-
/**
|
|
95
|
-
* - ID of last used wallet
|
|
96
|
-
*/
|
|
97
|
-
lastWalletId?: string;
|
|
98
|
-
};
|
|
99
|
-
export type WalletAction = {
|
|
100
|
-
/**
|
|
101
|
-
* - Action type
|
|
102
|
-
*/
|
|
103
|
-
type: string;
|
|
104
|
-
/**
|
|
105
|
-
* - Action arguments
|
|
106
|
-
*/
|
|
107
|
-
args?: any;
|
|
108
|
-
/**
|
|
109
|
-
* - Gas to attach
|
|
110
|
-
*/
|
|
111
|
-
gas?: string | number;
|
|
112
|
-
/**
|
|
113
|
-
* - Deposit to attach
|
|
114
|
-
*/
|
|
115
|
-
deposit?: string | number;
|
|
116
|
-
};
|
|
117
|
-
export type SignInConfig = {
|
|
118
|
-
/**
|
|
119
|
-
* - NEAR network ID ('mainnet' or 'testnet')
|
|
120
|
-
*/
|
|
121
|
-
networkId: string;
|
|
122
|
-
/**
|
|
123
|
-
* - Contract ID to request access for
|
|
124
|
-
*/
|
|
125
|
-
contractId: string;
|
|
126
|
-
/**
|
|
127
|
-
* - Preferred wallet to use
|
|
128
|
-
*/
|
|
129
|
-
wallet?: "near" | "here" | "meteor";
|
|
130
|
-
/**
|
|
131
|
-
* - URL to redirect back to after wallet interaction
|
|
132
|
-
*/
|
|
133
|
-
callbackUrl?: string;
|
|
134
|
-
};
|
|
135
|
-
export type SignInResult = {
|
|
136
|
-
/**
|
|
137
|
-
* - URL to redirect to if needed
|
|
138
|
-
*/
|
|
139
|
-
url?: string;
|
|
140
|
-
/**
|
|
141
|
-
* - Account ID if immediately available
|
|
142
|
-
*/
|
|
143
|
-
accountId?: string;
|
|
144
|
-
/**
|
|
145
|
-
* - Error message if sign in failed
|
|
146
|
-
*/
|
|
147
|
-
error?: string;
|
|
148
|
-
};
|
|
149
|
-
export type TransactionConfig = {
|
|
150
|
-
/**
|
|
151
|
-
* - Transaction receiver account ID
|
|
152
|
-
*/
|
|
153
|
-
receiverId: string;
|
|
154
|
-
/**
|
|
155
|
-
* - Transaction actions to perform
|
|
156
|
-
*/
|
|
157
|
-
actions: WalletAction[];
|
|
158
|
-
/**
|
|
159
|
-
* - Preferred wallet to use
|
|
160
|
-
*/
|
|
161
|
-
wallet?: "near" | "here" | "meteor";
|
|
162
|
-
/**
|
|
163
|
-
* - URL to redirect back to after wallet interaction
|
|
164
|
-
*/
|
|
165
|
-
callbackUrl?: string;
|
|
166
|
-
};
|
|
167
|
-
export type TransactionResult = {
|
|
168
|
-
/**
|
|
169
|
-
* - URL to redirect to if needed
|
|
170
|
-
*/
|
|
171
|
-
url?: string;
|
|
172
|
-
/**
|
|
173
|
-
* - Transaction hash if immediately available
|
|
174
|
-
*/
|
|
175
|
-
hash?: string;
|
|
176
|
-
/**
|
|
177
|
-
* - Error message if transaction failed
|
|
178
|
-
*/
|
|
179
|
-
error?: string;
|
|
180
|
-
};
|
|
181
|
-
export type WalletAdapterConfig = {
|
|
182
|
-
/**
|
|
183
|
-
* - URL of the wallet widget (defaults to official hosted version)
|
|
184
|
-
*/
|
|
185
|
-
widgetUrl?: string;
|
|
186
|
-
/**
|
|
187
|
-
* - Target origin for postMessage (defaults to '*')
|
|
188
|
-
*/
|
|
189
|
-
targetOrigin?: string;
|
|
190
|
-
/**
|
|
191
|
-
* - Called when wallet state changes
|
|
192
|
-
*/
|
|
193
|
-
onStateUpdate?: (state: WalletState) => void;
|
|
194
|
-
/**
|
|
195
|
-
* - Default callback URL for wallet interactions (defaults to current page URL)
|
|
196
|
-
*/
|
|
197
|
-
callbackUrl?: string;
|
|
198
|
-
};
|
|
199
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;GAEG;AACH;IAsBI,qBAAqB;IACrB,yBADW,MAAM,CAC+C;IAEhE;;OAEG;IACH,sEAFW,mBAAmB,EAa7B;IAmGD;;;OAGG;IACH,YAFa,WAAW,CAIvB;IAED;;;;OAIG;IACH,eAHW,YAAY,GACV,OAAO,CAAC,YAAY,CAAC,CAIjC;IAED;;;;OAIG;IACH,wBAHW,iBAAiB,GACf,OAAO,CAAC,iBAAiB,CAAC,CAItC;IAED;;OAEG;IACH,gBAIC;;CACF;;;;;gBAnOW,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM;;;;mBACN,MAAM;;;;;;UAKN,MAAM;;;;;;;;UAEN,MAAM,GAAC,MAAM;;;;cACb,MAAM,GAAC,MAAM;;;;;;eAKb,MAAM;;;;gBACN,MAAM;;;;aACN,MAAM,GAAC,MAAM,GAAC,QAAQ;;;;kBACtB,MAAM;;;;;;UAKN,MAAM;;;;gBACN,MAAM;;;;YACN,MAAM;;;;;;gBAKN,MAAM;;;;aACN,YAAY,EAAE;;;;aACd,MAAM,GAAC,MAAM,GAAC,QAAQ;;;;kBACtB,MAAM;;;;;;UAKN,MAAM;;;;WACN,MAAM;;;;YACN,MAAM;;;;;;gBAKN,MAAM;;;;mBACN,MAAM;;;;oBACN,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI;;;;kBAC5B,MAAM"}
|