UNPKG

@bsv/sdk

Version:

BSV Blockchain Software Development Kit

165 lines 6.11 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Random_js_1 = __importDefault(require("../../primitives/Random.js")); const Utils = __importStar(require("../../primitives/utils.js")); const WalletError_js_1 = require("../WalletError.js"); /** * Facilitates wallet operations over cross-document messaging. */ class ReactNativeWebView { constructor(domain = '*') { if (typeof window !== 'object') { throw new Error('The XDM substrate requires a global window object.'); } if (!window.hasOwnProperty("ReactNativeWebView")) { throw new Error('The window object does not have a ReactNativeWebView property.'); } if (typeof window.ReactNativeWebView.postMessage !== 'function') { throw new Error('The window.ReactNativeWebView property does not seem to support postMessage calls.'); } this.domain = domain; } async invoke(call, args) { return await new Promise((resolve, reject) => { const id = Utils.toBase64((0, Random_js_1.default)(12)); const listener = (e) => { const data = JSON.parse(e.data); if (data.type !== 'CWI' || data.id !== id || data.isInvocation === true) { return; } if (typeof window.removeEventListener === 'function') { window.removeEventListener('message', listener); } if (data.status === 'error') { const err = new WalletError_js_1.WalletError(data.description, data.code); reject(err); } else { resolve(data.result); } }; window.addEventListener('message', listener); window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'CWI', isInvocation: true, id, call, args })); }); } async createAction(args) { return await this.invoke('createAction', args); } async signAction(args) { return await this.invoke('signAction', args); } async abortAction(args) { return await this.invoke('abortAction', args); } async listActions(args) { return await this.invoke('listActions', args); } async internalizeAction(args) { return await this.invoke('internalizeAction', args); } async listOutputs(args) { return await this.invoke('listOutputs', args); } async relinquishOutput(args) { return await this.invoke('relinquishOutput', args); } async getPublicKey(args) { return await this.invoke('getPublicKey', args); } async revealCounterpartyKeyLinkage(args) { return await this.invoke('revealCounterpartyKeyLinkage', args); } async revealSpecificKeyLinkage(args) { return await this.invoke('revealSpecificKeyLinkage', args); } async encrypt(args) { return await this.invoke('encrypt', args); } async decrypt(args) { return await this.invoke('decrypt', args); } async createHmac(args) { return await this.invoke('createHmac', args); } async verifyHmac(args) { return await this.invoke('verifyHmac', args); } async createSignature(args) { return await this.invoke('createSignature', args); } async verifySignature(args) { return await this.invoke('verifySignature', args); } async acquireCertificate(args) { return await this.invoke('acquireCertificate', args); } async listCertificates(args) { return await this.invoke('listCertificates', args); } async proveCertificate(args) { return await this.invoke('proveCertificate', args); } async relinquishCertificate(args) { return await this.invoke('relinquishCertificate', args); } async discoverByIdentityKey(args) { return await this.invoke('discoverByIdentityKey', args); } async discoverByAttributes(args) { return await this.invoke('discoverByAttributes', args); } async isAuthenticated(args) { return await this.invoke('isAuthenticated', args); } async waitForAuthentication(args) { return await this.invoke('waitForAuthentication', args); } async getHeight(args) { return await this.invoke('getHeight', args); } async getHeaderForHeight(args) { return await this.invoke('getHeaderForHeight', args); } async getNetwork(args) { return await this.invoke('getNetwork', args); } async getVersion(args) { return await this.invoke('getVersion', args); } } exports.default = ReactNativeWebView; //# sourceMappingURL=ReactNativeWebView.js.map