UNPKG

@fastnear/wallet-adapter-widget

Version:

User interfaces for select NEAR Protocol web3 wallets

83 lines 3.32 kB
/* ⋈ 🏃🏻💨 FastNEAR Wallet Adapter Widget - CJS (@fastnear/wallet-adapter-widget v0.9.7) */ /* https://www.npmjs.com/package/@fastnear/wallet-adapter-widget/v/0.9.7 */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var near_exports = {}; __export(near_exports, { createNearAdapter: () => createNearAdapter, walletUrl: () => walletUrl }); module.exports = __toCommonJS(near_exports); var import_utils = require("@fastnear/utils"); const walletUrl = /* @__PURE__ */ __name((networkId) => networkId === "testnet" ? "https://testnet.mynearwallet.com" : "https://app.mynearwallet.com", "walletUrl"); function createNearAdapter() { return { async signIn({ networkId, contractId, callbackUrl, publicKey }) { const url = new URL(`${walletUrl(networkId)}/login`); url.searchParams.set("contract_id", contractId); url.searchParams.set("public_key", publicKey); url.searchParams.set("success_url", callbackUrl); url.searchParams.set("failure_url", callbackUrl); return { url: url.toString(), state: { publicKey, networkId } }; }, async sendTransactions({ state, transactions, callbackUrl }) { console.log( "sendTransactions", JSON.stringify({ state, transactions, callbackUrl }) ); if (!state?.accountId) { throw new Error("Not signed in"); } const url = new URL("sign", walletUrl(state?.networkId)); transactions = transactions.map(({ signerId, receiverId, actions }) => { if (signerId && signerId !== state.accountId) { throw new Error("Invalid signer"); } return { signerId: state.accountId, receiverId, actions, publicKey: `ed25519:${(0, import_utils.toBase58)(new Uint8Array(32))}`, nonce: 0, blockHash: (0, import_utils.toBase58)(new Uint8Array(32)) }; }); url.searchParams.set( "transactions", transactions.map((transaction) => (0, import_utils.serializeTransaction)(transaction)).map((serialized) => Buffer.from(serialized).toString("base64")).join(",") ); url.searchParams.set("callbackUrl", callbackUrl); return { url: url.toString() }; } }; } __name(createNearAdapter, "createNearAdapter"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createNearAdapter, walletUrl }); //# sourceMappingURL=near.cjs.map