@fastnear/api 0.9.7 → 0.9.8
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/cjs/index.d.cts +45 -23
- package/dist/cjs/near.cjs +57 -110
- package/dist/cjs/near.cjs.map +1 -1
- package/dist/cjs/state.cjs +11 -35
- package/dist/cjs/state.cjs.map +1 -1
- package/dist/esm/index.d.ts +45 -23
- package/dist/esm/near.js +57 -113
- package/dist/esm/near.js.map +1 -1
- package/dist/esm/state.js +9 -31
- package/dist/esm/state.js.map +1 -1
- package/dist/umd/browser.global.js +79 -314
- package/dist/umd/browser.global.js.map +1 -1
- package/package.json +3 -4
|
@@ -45,8 +45,10 @@ var near = (() => {
|
|
|
45
45
|
sendRpc: () => sendRpc,
|
|
46
46
|
sendTx: () => sendTx,
|
|
47
47
|
sendTxToRpc: () => sendTxToRpc,
|
|
48
|
+
signMessage: () => signMessage,
|
|
48
49
|
signOut: () => signOut,
|
|
49
50
|
state: () => state,
|
|
51
|
+
useWallet: () => useWallet,
|
|
50
52
|
utils: () => utils,
|
|
51
53
|
view: () => view,
|
|
52
54
|
withBlockId: () => withBlockId
|
|
@@ -1568,7 +1570,7 @@ var near = (() => {
|
|
|
1568
1570
|
const points = [];
|
|
1569
1571
|
let p = elm;
|
|
1570
1572
|
let base = p;
|
|
1571
|
-
for (let
|
|
1573
|
+
for (let window = 0; window < windows; window++) {
|
|
1572
1574
|
base = p;
|
|
1573
1575
|
points.push(base);
|
|
1574
1576
|
for (let i = 1; i < windowSize; i++) {
|
|
@@ -1593,8 +1595,8 @@ var near = (() => {
|
|
|
1593
1595
|
const mask = BigInt(2 ** W - 1);
|
|
1594
1596
|
const maxNumber = 2 ** W;
|
|
1595
1597
|
const shiftBy = BigInt(W);
|
|
1596
|
-
for (let
|
|
1597
|
-
const offset =
|
|
1598
|
+
for (let window = 0; window < windows; window++) {
|
|
1599
|
+
const offset = window * windowSize;
|
|
1598
1600
|
let wbits = Number(n & mask);
|
|
1599
1601
|
n >>= shiftBy;
|
|
1600
1602
|
if (wbits > windowSize) {
|
|
@@ -1603,7 +1605,7 @@ var near = (() => {
|
|
|
1603
1605
|
}
|
|
1604
1606
|
const offset1 = offset;
|
|
1605
1607
|
const offset2 = offset + Math.abs(wbits) - 1;
|
|
1606
|
-
const cond1 =
|
|
1608
|
+
const cond1 = window % 2 !== 0;
|
|
1607
1609
|
const cond2 = wbits < 0;
|
|
1608
1610
|
if (wbits === 0) {
|
|
1609
1611
|
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
|
@@ -1626,8 +1628,8 @@ var near = (() => {
|
|
|
1626
1628
|
const mask = BigInt(2 ** W - 1);
|
|
1627
1629
|
const maxNumber = 2 ** W;
|
|
1628
1630
|
const shiftBy = BigInt(W);
|
|
1629
|
-
for (let
|
|
1630
|
-
const offset =
|
|
1631
|
+
for (let window = 0; window < windows; window++) {
|
|
1632
|
+
const offset = window * windowSize;
|
|
1631
1633
|
if (n === _0n3)
|
|
1632
1634
|
break;
|
|
1633
1635
|
let wbits = Number(n & mask);
|
|
@@ -2362,11 +2364,11 @@ var near = (() => {
|
|
|
2362
2364
|
};
|
|
2363
2365
|
var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
2364
2366
|
|
|
2365
|
-
//
|
|
2367
|
+
// ../utils/node_modules/base58-js/base58_chars.js
|
|
2366
2368
|
var base58_chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2367
2369
|
var base58_chars_default = base58_chars;
|
|
2368
2370
|
|
|
2369
|
-
//
|
|
2371
|
+
// ../utils/node_modules/base58-js/base58_to_binary.js
|
|
2370
2372
|
function base58_to_binary(base58String) {
|
|
2371
2373
|
if (!base58String || typeof base58String !== "string")
|
|
2372
2374
|
throw new Error(`Expected base58 string but got \u201C${base58String}\u201D`);
|
|
@@ -2397,7 +2399,7 @@ var near = (() => {
|
|
|
2397
2399
|
__name(base58_to_binary, "base58_to_binary");
|
|
2398
2400
|
var base58_to_binary_default = base58_to_binary;
|
|
2399
2401
|
|
|
2400
|
-
//
|
|
2402
|
+
// ../utils/node_modules/base58-js/create_base58_map.js
|
|
2401
2403
|
var create_base58_map = /* @__PURE__ */ __name(() => {
|
|
2402
2404
|
const base58M = Array(256).fill(-1);
|
|
2403
2405
|
for (let i = 0; i < base58_chars_default.length; ++i)
|
|
@@ -2406,7 +2408,7 @@ var near = (() => {
|
|
|
2406
2408
|
}, "create_base58_map");
|
|
2407
2409
|
var create_base58_map_default = create_base58_map;
|
|
2408
2410
|
|
|
2409
|
-
//
|
|
2411
|
+
// ../utils/node_modules/base58-js/binary_to_base58.js
|
|
2410
2412
|
var base58Map = create_base58_map_default();
|
|
2411
2413
|
function binary_to_base58(uint8array) {
|
|
2412
2414
|
const result = [];
|
|
@@ -3562,8 +3564,6 @@ var near = (() => {
|
|
|
3562
3564
|
__export(state_exports, {
|
|
3563
3565
|
DEFAULT_NETWORK_ID: () => DEFAULT_NETWORK_ID,
|
|
3564
3566
|
NETWORKS: () => NETWORKS,
|
|
3565
|
-
WIDGET_URL: () => WIDGET_URL,
|
|
3566
|
-
_adapter: () => _adapter,
|
|
3567
3567
|
_config: () => _config,
|
|
3568
3568
|
_state: () => _state,
|
|
3569
3569
|
_txHistory: () => _txHistory,
|
|
@@ -3571,177 +3571,13 @@ var near = (() => {
|
|
|
3571
3571
|
events: () => events,
|
|
3572
3572
|
getConfig: () => getConfig,
|
|
3573
3573
|
getTxHistory: () => getTxHistory,
|
|
3574
|
-
|
|
3575
|
-
onAdapterStateUpdate: () => onAdapterStateUpdate,
|
|
3574
|
+
getWalletProvider: () => getWalletProvider,
|
|
3576
3575
|
resetTxHistory: () => resetTxHistory,
|
|
3577
3576
|
setConfig: () => setConfig,
|
|
3577
|
+
setWalletProvider: () => setWalletProvider,
|
|
3578
3578
|
update: () => update,
|
|
3579
3579
|
updateTxHistory: () => updateTxHistory
|
|
3580
3580
|
});
|
|
3581
|
-
|
|
3582
|
-
// ../wallet-adapter/src/index.ts
|
|
3583
|
-
var WalletAdapter = class _WalletAdapter {
|
|
3584
|
-
static {
|
|
3585
|
-
__name(this, "WalletAdapter");
|
|
3586
|
-
}
|
|
3587
|
-
/** @type {HTMLIFrameElement} */
|
|
3588
|
-
#iframe = null;
|
|
3589
|
-
/** @type {string} */
|
|
3590
|
-
#targetOrigin;
|
|
3591
|
-
/** @type {string} */
|
|
3592
|
-
#widgetUrl;
|
|
3593
|
-
/** @type {Map<string, Function>} */
|
|
3594
|
-
#pending = /* @__PURE__ */ new Map();
|
|
3595
|
-
/** @type {WalletState} */
|
|
3596
|
-
#state;
|
|
3597
|
-
/** @type {Function} */
|
|
3598
|
-
#onStateUpdate;
|
|
3599
|
-
/** @type {string} */
|
|
3600
|
-
#callbackUrl;
|
|
3601
|
-
/** @type {string} */
|
|
3602
|
-
static defaultWidgetUrl = "https://wallet-adapter.fastnear.com";
|
|
3603
|
-
/**
|
|
3604
|
-
* @param {WalletAdapterConfig} [config]
|
|
3605
|
-
*/
|
|
3606
|
-
constructor({
|
|
3607
|
-
widgetUrl = _WalletAdapter.defaultWidgetUrl,
|
|
3608
|
-
targetOrigin = "*",
|
|
3609
|
-
onStateUpdate,
|
|
3610
|
-
lastState,
|
|
3611
|
-
callbackUrl = window.location.href
|
|
3612
|
-
} = {}) {
|
|
3613
|
-
this.#targetOrigin = targetOrigin;
|
|
3614
|
-
this.#widgetUrl = widgetUrl;
|
|
3615
|
-
this.#onStateUpdate = onStateUpdate;
|
|
3616
|
-
this.#callbackUrl = callbackUrl;
|
|
3617
|
-
this.#state = lastState || {};
|
|
3618
|
-
window.addEventListener("message", this.#handleMessage.bind(this));
|
|
3619
|
-
}
|
|
3620
|
-
/**
|
|
3621
|
-
* Creates an iframe for wallet interaction
|
|
3622
|
-
* @param {string} path - Path to load in iframe
|
|
3623
|
-
* @returns {HTMLIFrameElement}
|
|
3624
|
-
*/
|
|
3625
|
-
#createIframe(path) {
|
|
3626
|
-
if (this.#iframe) {
|
|
3627
|
-
this.#iframe.remove();
|
|
3628
|
-
}
|
|
3629
|
-
const url = new URL(path, this.#widgetUrl);
|
|
3630
|
-
const iframe = document.createElement("iframe");
|
|
3631
|
-
iframe.src = url.toString();
|
|
3632
|
-
iframe.allow = "usb";
|
|
3633
|
-
iframe.style.border = "none";
|
|
3634
|
-
iframe.style.zIndex = "10000";
|
|
3635
|
-
iframe.style.position = "fixed";
|
|
3636
|
-
iframe.style.display = "block";
|
|
3637
|
-
iframe.style.top = "0";
|
|
3638
|
-
iframe.style.left = "0";
|
|
3639
|
-
iframe.style.width = "100%";
|
|
3640
|
-
iframe.style.height = "100%";
|
|
3641
|
-
document.body.appendChild(iframe);
|
|
3642
|
-
this.#iframe = iframe;
|
|
3643
|
-
return iframe;
|
|
3644
|
-
}
|
|
3645
|
-
/**
|
|
3646
|
-
* Handles messages from the wallet widget
|
|
3647
|
-
* @param {MessageEvent} event
|
|
3648
|
-
*/
|
|
3649
|
-
#handleMessage(event2) {
|
|
3650
|
-
if (this.#targetOrigin !== "*" && event2.origin !== this.#targetOrigin) {
|
|
3651
|
-
return;
|
|
3652
|
-
}
|
|
3653
|
-
const { id, type, action, payload } = event2.data;
|
|
3654
|
-
if (type !== "wallet-adapter") return;
|
|
3655
|
-
if (action === "close") {
|
|
3656
|
-
this.#iframe?.remove();
|
|
3657
|
-
this.#iframe = null;
|
|
3658
|
-
return;
|
|
3659
|
-
}
|
|
3660
|
-
if (payload?.state) {
|
|
3661
|
-
this.#state = { ...this.#state, ...payload.state };
|
|
3662
|
-
this.#onStateUpdate?.(this.#state);
|
|
3663
|
-
}
|
|
3664
|
-
const resolve = this.#pending.get(id);
|
|
3665
|
-
if (resolve) {
|
|
3666
|
-
this.#pending.delete(id);
|
|
3667
|
-
this.#iframe?.remove();
|
|
3668
|
-
this.#iframe = null;
|
|
3669
|
-
resolve(payload);
|
|
3670
|
-
}
|
|
3671
|
-
}
|
|
3672
|
-
/**
|
|
3673
|
-
* Sends a message to the wallet widget
|
|
3674
|
-
* @param {string} path - Path to load in iframe
|
|
3675
|
-
* @param {string} method - Method to call
|
|
3676
|
-
* @param {Object} params - Parameters to pass
|
|
3677
|
-
* @returns {Promise<any>}
|
|
3678
|
-
*/
|
|
3679
|
-
async #sendMessage(path, method, params) {
|
|
3680
|
-
return new Promise((resolve) => {
|
|
3681
|
-
const id = Math.random().toString(36).slice(2);
|
|
3682
|
-
this.#pending.set(id, resolve);
|
|
3683
|
-
const iframe = this.#createIframe(path);
|
|
3684
|
-
iframe.onload = () => {
|
|
3685
|
-
iframe.contentWindow?.postMessage(
|
|
3686
|
-
{
|
|
3687
|
-
type: "wallet-adapter",
|
|
3688
|
-
method,
|
|
3689
|
-
params: {
|
|
3690
|
-
id,
|
|
3691
|
-
...params,
|
|
3692
|
-
state: this.#state,
|
|
3693
|
-
callbackUrl: params.callbackUrl || this.#callbackUrl
|
|
3694
|
-
}
|
|
3695
|
-
},
|
|
3696
|
-
this.#targetOrigin
|
|
3697
|
-
);
|
|
3698
|
-
};
|
|
3699
|
-
});
|
|
3700
|
-
}
|
|
3701
|
-
/**
|
|
3702
|
-
* Get current wallet state
|
|
3703
|
-
* @returns {WalletState}
|
|
3704
|
-
*/
|
|
3705
|
-
getState() {
|
|
3706
|
-
return { ...this.#state };
|
|
3707
|
-
}
|
|
3708
|
-
/**
|
|
3709
|
-
* Set current wallet state
|
|
3710
|
-
* @param state
|
|
3711
|
-
*/
|
|
3712
|
-
setState(state2) {
|
|
3713
|
-
this.#state = state2;
|
|
3714
|
-
}
|
|
3715
|
-
/**
|
|
3716
|
-
* Sign in with a NEAR wallet
|
|
3717
|
-
* @param {SignInConfig} config
|
|
3718
|
-
* @returns {Promise<any>}
|
|
3719
|
-
*
|
|
3720
|
-
* Should be returning SignInResult
|
|
3721
|
-
*/
|
|
3722
|
-
async signIn(config2) {
|
|
3723
|
-
return this.#sendMessage("/login.html", "signIn", config2);
|
|
3724
|
-
}
|
|
3725
|
-
/**
|
|
3726
|
-
* Send a transaction using connected wallet
|
|
3727
|
-
* @param {TransactionConfig} config
|
|
3728
|
-
* @returns {Promise<TransactionResult>}
|
|
3729
|
-
*/
|
|
3730
|
-
async sendTransactions(config2) {
|
|
3731
|
-
return this.#sendMessage("/send.html", "sendTransactions", config2);
|
|
3732
|
-
}
|
|
3733
|
-
/**
|
|
3734
|
-
* Clean up adapter resources
|
|
3735
|
-
*/
|
|
3736
|
-
destroy() {
|
|
3737
|
-
window.removeEventListener("message", this.#handleMessage);
|
|
3738
|
-
this.#iframe?.remove();
|
|
3739
|
-
this.#iframe = null;
|
|
3740
|
-
}
|
|
3741
|
-
};
|
|
3742
|
-
|
|
3743
|
-
// src/state.ts
|
|
3744
|
-
var WIDGET_URL = "https://js.cdn.fastnear.com";
|
|
3745
3581
|
var DEFAULT_NETWORK_ID = "mainnet";
|
|
3746
3582
|
var NETWORKS = {
|
|
3747
3583
|
testnet: {
|
|
@@ -3757,28 +3593,13 @@ var near = (() => {
|
|
|
3757
3593
|
...NETWORKS[DEFAULT_NETWORK_ID]
|
|
3758
3594
|
};
|
|
3759
3595
|
var _state = lsGet("state") || {};
|
|
3760
|
-
var
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
});
|
|
3768
|
-
}, "onAdapterStateUpdate");
|
|
3769
|
-
var getWalletAdapterState = /* @__PURE__ */ __name(() => {
|
|
3770
|
-
return {
|
|
3771
|
-
publicKey: _state.publicKey,
|
|
3772
|
-
accountId: _state.accountId,
|
|
3773
|
-
lastWalletId: _state.lastWalletId,
|
|
3774
|
-
networkId: _config.networkId
|
|
3775
|
-
};
|
|
3776
|
-
}, "getWalletAdapterState");
|
|
3777
|
-
var _adapter = new WalletAdapter({
|
|
3778
|
-
onStateUpdate: onAdapterStateUpdate,
|
|
3779
|
-
lastState: getWalletAdapterState(),
|
|
3780
|
-
widgetUrl: WIDGET_URL
|
|
3781
|
-
});
|
|
3596
|
+
var _walletProvider = null;
|
|
3597
|
+
var setWalletProvider = /* @__PURE__ */ __name((provider) => {
|
|
3598
|
+
_walletProvider = provider;
|
|
3599
|
+
}, "setWalletProvider");
|
|
3600
|
+
var getWalletProvider = /* @__PURE__ */ __name(() => {
|
|
3601
|
+
return _walletProvider;
|
|
3602
|
+
}, "getWalletProvider");
|
|
3782
3603
|
try {
|
|
3783
3604
|
_state.publicKey = _state.privateKey ? publicKeyFromPrivate(_state.privateKey) : null;
|
|
3784
3605
|
} catch (e) {
|
|
@@ -3855,9 +3676,6 @@ var near = (() => {
|
|
|
3855
3676
|
if (newState.accountId !== oldState.accountId) {
|
|
3856
3677
|
events.notifyAccountListeners(newState.accountId);
|
|
3857
3678
|
}
|
|
3858
|
-
if (newState.hasOwnProperty("lastWalletId") && newState.lastWalletId !== oldState.lastWalletId || newState.hasOwnProperty("accountId") && newState.accountId !== oldState.accountId || newState.hasOwnProperty("privateKey") && newState.privateKey !== oldState.privateKey) {
|
|
3859
|
-
_adapter.setState(getWalletAdapterState());
|
|
3860
|
-
}
|
|
3861
3679
|
}, "update");
|
|
3862
3680
|
var updateTxHistory = /* @__PURE__ */ __name((txStatus) => {
|
|
3863
3681
|
const txId = txStatus.txId;
|
|
@@ -4012,27 +3830,28 @@ var near = (() => {
|
|
|
4012
3830
|
publicKey: publicKey2
|
|
4013
3831
|
};
|
|
4014
3832
|
}, "selected");
|
|
4015
|
-
var requestSignIn = /* @__PURE__ */ __name(async ({
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
3833
|
+
var requestSignIn = /* @__PURE__ */ __name(async ({
|
|
3834
|
+
contractId,
|
|
3835
|
+
excludedWallets,
|
|
3836
|
+
features
|
|
3837
|
+
} = {}) => {
|
|
3838
|
+
const provider = getWalletProvider();
|
|
3839
|
+
if (!provider) {
|
|
3840
|
+
throw new Error("No wallet provider set. Call useWallet() first or load the @fastnear/wallet IIFE bundle.");
|
|
3841
|
+
}
|
|
3842
|
+
if (provider.isConnected()) {
|
|
3843
|
+
await provider.disconnect();
|
|
3844
|
+
}
|
|
3845
|
+
const result = await provider.connect({
|
|
4021
3846
|
contractId,
|
|
4022
|
-
|
|
3847
|
+
network: getConfig().networkId,
|
|
3848
|
+
excludedWallets,
|
|
3849
|
+
features
|
|
4023
3850
|
});
|
|
4024
|
-
if (result
|
|
4025
|
-
|
|
4026
|
-
}
|
|
4027
|
-
if (result.url) {
|
|
4028
|
-
if (typeof window !== "undefined") {
|
|
4029
|
-
setTimeout(() => {
|
|
4030
|
-
window.location.href = result.url;
|
|
4031
|
-
}, 100);
|
|
4032
|
-
}
|
|
4033
|
-
} else if (result.accountId) {
|
|
4034
|
-
update({ accountId: result.accountId });
|
|
3851
|
+
if (!result) {
|
|
3852
|
+
return;
|
|
4035
3853
|
}
|
|
3854
|
+
update({ accountId: result.accountId });
|
|
4036
3855
|
}, "requestSignIn");
|
|
4037
3856
|
var view = /* @__PURE__ */ __name(async ({
|
|
4038
3857
|
contractId,
|
|
@@ -4087,7 +3906,11 @@ var near = (() => {
|
|
|
4087
3906
|
var localTxHistory = /* @__PURE__ */ __name(() => {
|
|
4088
3907
|
return getTxHistory();
|
|
4089
3908
|
}, "localTxHistory");
|
|
4090
|
-
var signOut = /* @__PURE__ */ __name(() => {
|
|
3909
|
+
var signOut = /* @__PURE__ */ __name(async () => {
|
|
3910
|
+
const provider = getWalletProvider();
|
|
3911
|
+
if (provider?.isConnected()) {
|
|
3912
|
+
await provider.disconnect();
|
|
3913
|
+
}
|
|
4091
3914
|
update({ accountId: null, privateKey: null, contractId: null });
|
|
4092
3915
|
setConfig(NETWORKS[DEFAULT_NETWORK_ID]);
|
|
4093
3916
|
}, "signOut");
|
|
@@ -4098,56 +3921,36 @@ var near = (() => {
|
|
|
4098
3921
|
}) => {
|
|
4099
3922
|
const signerId = _state.accountId;
|
|
4100
3923
|
if (!signerId) throw new Error("Must sign in");
|
|
4101
|
-
const
|
|
3924
|
+
const pubKey = _state.publicKey ?? "";
|
|
4102
3925
|
const privKey = _state.privateKey;
|
|
4103
3926
|
const txId = generateTxId();
|
|
4104
3927
|
if (!privKey || receiverId !== _state.accessKeyContractId || !canSignWithLAK(actions2)) {
|
|
4105
3928
|
const jsonTx = { signerId, receiverId, actions: actions2 };
|
|
4106
3929
|
updateTxHistory({ status: "Pending", txId, tx: jsonTx, finalState: false });
|
|
4107
|
-
const url = new URL(typeof window !== "undefined" ? window.location.href : "");
|
|
4108
|
-
url.searchParams.set("txIds", txId);
|
|
4109
|
-
const existingParams = new URLSearchParams(window.location.search);
|
|
4110
|
-
existingParams.forEach((value, key) => {
|
|
4111
|
-
if (!url.searchParams.has(key)) {
|
|
4112
|
-
url.searchParams.set(key, value);
|
|
4113
|
-
}
|
|
4114
|
-
});
|
|
4115
|
-
url.searchParams.delete("errorCode");
|
|
4116
|
-
url.searchParams.delete("errorMessage");
|
|
4117
3930
|
try {
|
|
4118
|
-
const
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
}
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
} else if (result.outcomes?.length) {
|
|
3931
|
+
const provider = getWalletProvider();
|
|
3932
|
+
if (!provider?.isConnected()) {
|
|
3933
|
+
throw new Error("Must sign in");
|
|
3934
|
+
}
|
|
3935
|
+
const result = await provider.sendTransaction(jsonTx);
|
|
3936
|
+
if (!result) {
|
|
3937
|
+
updateTxHistory({ txId, status: "RejectedByUser", finalState: true });
|
|
3938
|
+
return { rejected: true };
|
|
3939
|
+
}
|
|
3940
|
+
if (result.outcomes?.length) {
|
|
4129
3941
|
result.outcomes.forEach(
|
|
4130
3942
|
(r) => updateTxHistory({
|
|
4131
3943
|
txId,
|
|
4132
3944
|
status: "Executed",
|
|
4133
3945
|
result: r,
|
|
4134
|
-
txHash: r.transaction
|
|
3946
|
+
txHash: r.transaction?.hash,
|
|
4135
3947
|
finalState: true
|
|
4136
3948
|
})
|
|
4137
3949
|
);
|
|
4138
|
-
} else if (result.rejected) {
|
|
4139
|
-
updateTxHistory({ txId, status: "RejectedByUser", finalState: true });
|
|
4140
|
-
} else if (result.error) {
|
|
4141
|
-
updateTxHistory({
|
|
4142
|
-
txId,
|
|
4143
|
-
status: "Error",
|
|
4144
|
-
error: tryParseJson(result.error),
|
|
4145
|
-
finalState: true
|
|
4146
|
-
});
|
|
4147
3950
|
}
|
|
4148
3951
|
return result;
|
|
4149
3952
|
} catch (err) {
|
|
4150
|
-
console.error("fastnear: error sending tx using
|
|
3953
|
+
console.error("fastnear: error sending tx using wallet provider:", err);
|
|
4151
3954
|
updateTxHistory({
|
|
4152
3955
|
txId,
|
|
4153
3956
|
status: "Error",
|
|
@@ -4159,9 +3962,9 @@ var near = (() => {
|
|
|
4159
3962
|
}
|
|
4160
3963
|
let nonce = lsGet("nonce");
|
|
4161
3964
|
if (nonce == null) {
|
|
4162
|
-
const accessKey = await queryAccessKey({ accountId: signerId, publicKey:
|
|
3965
|
+
const accessKey = await queryAccessKey({ accountId: signerId, publicKey: pubKey });
|
|
4163
3966
|
if (accessKey.result.error) {
|
|
4164
|
-
throw new Error(`Access key error: ${accessKey.result.error} when attempting to get nonce for ${signerId} for public key ${
|
|
3967
|
+
throw new Error(`Access key error: ${accessKey.result.error} when attempting to get nonce for ${signerId} for public key ${pubKey}`);
|
|
4165
3968
|
}
|
|
4166
3969
|
nonce = accessKey.result.nonce;
|
|
4167
3970
|
lsSet("nonce", nonce);
|
|
@@ -4182,7 +3985,7 @@ var near = (() => {
|
|
|
4182
3985
|
const blockHash = lastKnownBlock.header.hash;
|
|
4183
3986
|
const plainTransactionObj = {
|
|
4184
3987
|
signerId,
|
|
4185
|
-
publicKey:
|
|
3988
|
+
publicKey: pubKey,
|
|
4186
3989
|
nonce,
|
|
4187
3990
|
receiverId,
|
|
4188
3991
|
blockHash,
|
|
@@ -4209,6 +4012,19 @@ var near = (() => {
|
|
|
4209
4012
|
console.error("Error Sending Transaction:", error, plainTransactionObj, signedTxBase64);
|
|
4210
4013
|
}
|
|
4211
4014
|
}, "sendTx");
|
|
4015
|
+
var signMessage = /* @__PURE__ */ __name(async (message) => {
|
|
4016
|
+
const provider = getWalletProvider();
|
|
4017
|
+
if (!provider?.isConnected()) {
|
|
4018
|
+
throw new Error("Must sign in");
|
|
4019
|
+
}
|
|
4020
|
+
if (!provider.signMessage) {
|
|
4021
|
+
throw new Error("Connected wallet does not support signMessage");
|
|
4022
|
+
}
|
|
4023
|
+
return provider.signMessage(message);
|
|
4024
|
+
}, "signMessage");
|
|
4025
|
+
var useWallet = /* @__PURE__ */ __name((provider) => {
|
|
4026
|
+
setWalletProvider(provider);
|
|
4027
|
+
}, "useWallet");
|
|
4212
4028
|
var exp2 = {
|
|
4213
4029
|
utils: {},
|
|
4214
4030
|
// we will map this in a moment, giving keys, for IDE hints
|
|
@@ -4225,61 +4041,6 @@ var near = (() => {
|
|
|
4225
4041
|
}
|
|
4226
4042
|
var event = state["events"];
|
|
4227
4043
|
delete state["events"];
|
|
4228
|
-
try {
|
|
4229
|
-
if (typeof window !== "undefined") {
|
|
4230
|
-
const url = new URL(window.location.href);
|
|
4231
|
-
const accId = url.searchParams.get("account_id");
|
|
4232
|
-
const pubKey = url.searchParams.get("public_key");
|
|
4233
|
-
const errCode = url.searchParams.get("errorCode");
|
|
4234
|
-
const errMsg = url.searchParams.get("errorMessage");
|
|
4235
|
-
const decodedErrMsg = errMsg ? decodeURIComponent(errMsg) : null;
|
|
4236
|
-
const txHashes = url.searchParams.get("transactionHashes");
|
|
4237
|
-
const txIds = url.searchParams.get("txIds");
|
|
4238
|
-
if (errCode || errMsg) {
|
|
4239
|
-
console.warn(new Error(`Wallet raises:
|
|
4240
|
-
code: ${errCode}
|
|
4241
|
-
message: ${decodedErrMsg}`));
|
|
4242
|
-
}
|
|
4243
|
-
if (accId && pubKey) {
|
|
4244
|
-
if (pubKey === _state.publicKey) {
|
|
4245
|
-
update({ accountId: accId });
|
|
4246
|
-
} else {
|
|
4247
|
-
if (authStatus() === "SignedIn") {
|
|
4248
|
-
console.warn("Public key mismatch from wallet redirect", pubKey, _state.publicKey);
|
|
4249
|
-
}
|
|
4250
|
-
url.searchParams.delete("public_key");
|
|
4251
|
-
}
|
|
4252
|
-
}
|
|
4253
|
-
if (txHashes || txIds) {
|
|
4254
|
-
const hashArr = txHashes ? txHashes.split(",") : [];
|
|
4255
|
-
const idArr = txIds ? txIds.split(",") : [];
|
|
4256
|
-
if (idArr.length > hashArr.length) {
|
|
4257
|
-
idArr.forEach((id) => {
|
|
4258
|
-
updateTxHistory({ txId: id, status: "RejectedByUser", finalState: true });
|
|
4259
|
-
});
|
|
4260
|
-
} else if (idArr.length === hashArr.length) {
|
|
4261
|
-
idArr.forEach((id, i) => {
|
|
4262
|
-
updateTxHistory({
|
|
4263
|
-
txId: id,
|
|
4264
|
-
status: "PendingGotTxHash",
|
|
4265
|
-
txHash: hashArr[i],
|
|
4266
|
-
finalState: false
|
|
4267
|
-
});
|
|
4268
|
-
afterTxSent(id);
|
|
4269
|
-
});
|
|
4270
|
-
} else {
|
|
4271
|
-
console.error(new Error("Transaction hash mismatch from wallet redirect"), idArr, hashArr);
|
|
4272
|
-
}
|
|
4273
|
-
}
|
|
4274
|
-
url.searchParams.delete("txIds");
|
|
4275
|
-
if (authStatus() === "SignedOut") {
|
|
4276
|
-
url.searchParams.delete("errorCode");
|
|
4277
|
-
url.searchParams.delete("errorMessage");
|
|
4278
|
-
}
|
|
4279
|
-
}
|
|
4280
|
-
} catch (e) {
|
|
4281
|
-
console.error("Error handling wallet redirect:", e);
|
|
4282
|
-
}
|
|
4283
4044
|
var actions = {
|
|
4284
4045
|
functionCall: /* @__PURE__ */ __name(({
|
|
4285
4046
|
methodName,
|
|
@@ -4365,7 +4126,7 @@ message: ${decodedErrMsg}`));
|
|
|
4365
4126
|
|
|
4366
4127
|
try {
|
|
4367
4128
|
Object.defineProperty(globalThis, 'near', {
|
|
4368
|
-
value: near,
|
|
4129
|
+
value: near,
|
|
4369
4130
|
enumerable: true,
|
|
4370
4131
|
configurable: false,
|
|
4371
4132
|
});
|
|
@@ -4376,4 +4137,8 @@ try {
|
|
|
4376
4137
|
|
|
4377
4138
|
window.$$ = near.utils.convertUnit;
|
|
4378
4139
|
|
|
4140
|
+
if (typeof globalThis.nearWallet !== 'undefined') {
|
|
4141
|
+
near.useWallet(globalThis.nearWallet);
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4379
4144
|
//# sourceMappingURL=browser.global.js.map
|