Socket
Socket
Sign inDemoInstall

xumm-sdk

Package Overview
Dependencies
Maintainers
4
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xumm-sdk - npm Package Compare versions

Comparing version 1.8.10 to 1.9.0

2

dist/browser.min.js

@@ -1,2 +0,2 @@

require=function t(e,r,n){function o(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=r[s]={exports:{}};e[s][0].call(c.exports,(function(t){return o(e[s][1][t]||t)}),c,c.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.JwtUserdata=void 0;const o=t("debug"),i=t("./utils"),s=o.debug("xumm-sdk:xapp:userdata");r.JwtUserdata=class{constructor(t){s("Constructed"),this.Meta=t}list(){return n(this,void 0,void 0,(function*(){const t=yield this.Meta.call("userdata","GET");return i.throwIfError(t),t.keys}))}get(t){var e;return n(this,void 0,void 0,(function*(){const r=Array.isArray(t)?t.join(","):t,n=yield this.Meta.call("userdata/"+r,"GET");return i.throwIfError(n),r.split(",").length>1?n.data:(null===(e=n.data)||void 0===e?void 0:e[r])||{}}))}delete(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("userdata/"+t,"DELETE");return i.throwIfError(e),e.persisted}))}set(t,e){return n(this,void 0,void 0,(function*(){const r=yield this.Meta.call("userdata/"+t,"POST",e);return i.throwIfError(r),r.persisted}))}}},{"./utils":6,debug:10}],2:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,"__esModule",{value:!0}),r.Meta=void 0;const i=t("debug"),s=o(t("fetch-ponyfill")),{fetch:a,Request:u,Response:f,Headers:c}=s.default(),l=t("os-browserify"),h=t("./utils"),d=t("./index"),p=i.debug("xumm-sdk:meta");r.Meta=class{constructor(t,e){this.isBrowser=!1,this.jwtFlow=!1,this.injected=!1,this.endpoint="https://xumm.app",p("Constructed");const r=new RegExp("^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"),n={split:e.split(":"),uuidv4:""};if(3===n.split.length&&"xApp:OneTimeToken"===n.split.slice(0,2).join(":")?(n.uuidv4=n.split[2],this.jwtFlow=!0):n.split.length>1&&"RAWJWT"===n.split[0]?(this.jwtFlow=!0,this.jwt=n.split.slice(1).join(":")):n.uuidv4=e,!r.test(t)||!r.test(n.uuidv4)){if(!this.jwtFlow)throw new Error("Invalid API Key and/or API Secret. Use dotenv or constructor params.");if(!this.jwt)throw new Error("Invalid API Key and/or OTT (One Time Token). Provide OTT param (2nd param) or make sure `xAppToken` query param is present (Browser)")}return"undefined"!=typeof globalThis&&Object.keys(globalThis).indexOf("window")<0?p("Running in node"):(console.log("XUMM SDK: Running in browser"),this.isBrowser=!0),this.apiKey=t,this.apiSecret=n.uuidv4,this.jwtFlow&&!this.jwt&&(this.authPromise=new Promise((t=>{this.authPromiseResolve=t})),Promise.resolve().then((()=>this.authorize())).catch((t=>{p("Authorize error:",t.message),(null==this?void 0:this.invoker)&&this.invoker.caught(t),this.authPromiseResolve&&this.authPromiseResolve()}))),this}setEndpoint(t){return!!t.match(/^http/)&&(this.endpoint=t.trim(),!0)}authorize(){var t,e,r,o;return n(this,void 0,void 0,(function*(){let n;p("JWT Authorize",this.apiSecret),(null==this?void 0:this.invoker)&&this.invoker.constructor===d.XummSdkJwt&&(n=this.invoker._jwtStore(this,(t=>this.jwt=t)));const i=(null==n?void 0:n.get(this.apiSecret))||(yield this.call("authorize"));if(null===(e=null===(t=i)||void 0===t?void 0:t.error)||void 0===e?void 0:e.code)p("Could not resolve API Key & OTT to JWT (already fetched? Unauthorized?)"),(null==this?void 0:this.invoker)&&this.invoker.constructor===d.XummSdkJwt&&(null===(r=null==this?void 0:this.invoker)||void 0===r?void 0:r.fatalHandler)?this.invoker.fatalHandler(new Error(i.error.reference)):h.throwIfError(i);else{if(!(null===(o=i)||void 0===o?void 0:o.jwt))throw new Error("Unexpected response for xApp JWT authorize request");{const t=i;null==n||n.set(this.apiSecret,t)}}this.authPromiseResolve&&this.authPromiseResolve()}))}call(t,e="GET",r){var o;return n(this,void 0,void 0,(function*(){const n=e.toUpperCase(),i=t.split("/")[0];this.jwtFlow&&!(null==this?void 0:this.jwt)&&this.authPromise&&"authorize"!==t&&(yield this.authPromise);try{let e;void 0!==r&&("object"==typeof r&&null!==r&&(e=JSON.stringify(r)),"string"==typeof r&&(e=r));const o={"Content-Type":"application/json"};this.isBrowser||Object.assign(o,{"User-Agent":`xumm-sdk/node (${l.hostname()}) node-fetch`}),this.jwtFlow?"authorize"===t?Object.assign(o,{"x-api-key":this.apiKey,"x-api-ott":this.apiSecret}):Object.assign(o,{Authorization:"Bearer "+this.jwt}):Object.assign(o,{"x-api-key":this.apiKey,"x-api-secret":this.apiSecret});const s=["authorize","ping","curated-assets","rates","payload","userdata","xrpl-tx","nftoken-detail"],u=this.jwtFlow&&s.indexOf(i)>-1?"jwt":"platform",f=yield a(this.endpoint+"/api/v1/"+u+"/"+t,{method:n,body:e,headers:o});return yield f.json()}catch(t){const e=new Error(`Unexpected response from XUMM API [${n}:${i}]`);throw e.stack=(null===(o=t)||void 0===o?void 0:o.stack)||void 0,e}}))}ping(){var t,e;return n(this,void 0,void 0,(function*(){const r=yield this.call("ping");if(h.throwIfError(r),void 0!==r.auth)return r.auth;if(void 0!==(null===(t=r)||void 0===t?void 0:t.ott_uuidv4))return{application:{uuidv4:r.app_uuidv4,name:r.app_name},jwtData:r};if(void 0!==(null===(e=r)||void 0===e?void 0:e.usertoken_uuidv4))return{application:{uuidv4:r.client_id,name:r.app_name},jwtData:r};throw new Error("Unexpected response for ping request")}))}getCuratedAssets(){return n(this,void 0,void 0,(function*(){return yield this.call("curated-assets")}))}getRates(t){return n(this,void 0,void 0,(function*(){return yield this.call("rates/"+t.trim().toUpperCase())}))}getKycStatus(t){return n(this,void 0,void 0,(function*(){if(t.trim().match(/^r/)){const e=yield this.call("kyc-status/"+t.trim());return(null==e?void 0:e.kycApproved)?"SUCCESSFUL":"NONE"}{const e=yield this.call("kyc-status","POST",{user_token:t});return(null==e?void 0:e.kycStatus)||"NONE"}}))}getRails(){return n(this,void 0,void 0,(function*(){return yield this.call("rails")}))}getHookHash(t){return n(this,void 0,void 0,(function*(){if("string"==typeof t&&t.trim().match(/^[A-Fa-f0-9]{64}$/))return yield this.call("hookhash/"+t.trim());throw Error("Invalid Hook Hash (expecting 64 char hex)")}))}getHookHashes(){return n(this,void 0,void 0,(function*(){return yield this.call("hookhash")}))}getTransaction(t){return n(this,void 0,void 0,(function*(){return yield this.call("xrpl-tx/"+t.trim())}))}getNftokenDetail(t){return n(this,void 0,void 0,(function*(){if(!this.jwtFlow)throw new Error("getNftokenDetail: only available in JWT (XummSdkJwt) mode");return yield this.call("nftoken-detail/"+t.trim())}))}verifyUserTokens(t){return n(this,void 0,void 0,(function*(){return(yield this.call("user-tokens","POST",{tokens:Array.isArray(t)?t:[t]})).tokens}))}_inject(t){if(this.injected)throw new Error("Cannot `_inject` twice");this.invoker=t}}},{"./index":"xumm-sdk","./utils":6,debug:10,"fetch-ponyfill":13,"os-browserify":16}],3:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.Payload=void 0;const o=t("debug"),i=t("websocket"),s=t("./utils"),a=o.debug("xumm-sdk:payload"),u=o.debug("xumm-sdk:payload:websocket");r.Payload=class{constructor(t){a("Constructed"),this.Meta=t}resolvePayload(t){var e,r,o;return n(this,void 0,void 0,(function*(){if("string"==typeof t)return yield this.get(t,!0);if(void 0!==(null===(e=t)||void 0===e?void 0:e.uuid))return yield this.get(t.uuid,!0);if(void 0!==(null===(o=null===(r=t)||void 0===r?void 0:r.meta)||void 0===o?void 0:o.uuid))return t;throw new Error("Could not resolve payload (not found)")}))}create(t,e=!1){var r;return n(this,void 0,void 0,(function*(){const n=void 0!==t.TransactionType&&void 0===t.txjson,o=yield this.Meta.call("payload","POST",n?{txjson:t}:t);e&&s.throwIfError(o);return void 0!==(null===(r=o)||void 0===r?void 0:r.next)?o:null}))}get(t,e=!1){var r,o;return n(this,void 0,void 0,(function*(){const n="string"==typeof t?t:null==t?void 0:t.uuid,i=yield this.Meta.call("payload/"+n,"GET");e&&s.throwIfError(i);return void 0!==(null===(o=null===(r=i)||void 0===r?void 0:r.meta)||void 0===o?void 0:o.uuid)?i:null}))}subscribe(t,e){var r,o;return n(this,void 0,void 0,(function*(){const a=new s.DeferredPromise,f=yield this.resolvePayload(t);if(f){const t="undefined",s=typeof(null===(r=globalThis)||void 0===r?void 0:r.MockedWebSocket)!==t&&typeof jest!==t?new(null===(o=globalThis)||void 0===o?void 0:o.MockedWebSocket)("ws://xumm.local"):new i.w3cwebsocket(this.Meta.endpoint.replace(/^http/,"ws")+"/sign/"+f.meta.uuid);return a.promise.then((()=>{s.close()})),s.onopen=()=>{u(`Payload ${f.meta.uuid}: Subscription active (WebSocket opened)`)},s.onmessage=t=>n(this,void 0,void 0,(function*(){const r=t.data;let o;try{o=JSON.parse(r.toString())}catch(t){u(`Payload ${f.meta.uuid}: Received message, unable to parse as JSON`,t)}if(o&&e&&void 0===o.devapp_fetched)try{const t=yield e({uuid:f.meta.uuid,data:o,resolve(t){return n(this,void 0,void 0,(function*(){yield a.resolve(t||void 0)}))},payload:f});void 0!==t&&a.resolve(t)}catch(t){u(`Payload ${f.meta.uuid}: Callback exception`,t)}})),s.onclose=t=>{u(`Payload ${f.meta.uuid}: Subscription ended (WebSocket closed)`)},{payload:f,resolve(t){a.resolve(t||void 0)},resolved:a.promise,websocket:s}}throw s.throwIfError(f),Error("Couldn't subscribe: couldn't fetch payload")}))}cancel(t,e=!1){var r,o,i;return n(this,void 0,void 0,(function*(){const n=yield this.resolvePayload(t),a=yield this.Meta.call("payload/"+(null===(r=null==n?void 0:n.meta)||void 0===r?void 0:r.uuid),"DELETE");e&&s.throwIfError(a);return void 0!==(null===(i=null===(o=a)||void 0===o?void 0:o.meta)||void 0===i?void 0:i.uuid)?a:null}))}createAndSubscribe(t,e){return n(this,void 0,void 0,(function*(){const r=yield this.create(t,!0);if(r){const t=yield this.subscribe(r,e);return Object.assign({created:r},t)}throw new Error("Error creating payload or subscribing to created payload")}))}}},{"./utils":6,debug:10,websocket:18}],4:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.Push=void 0;const o=t("debug"),i=t("./JwtUserdata"),s=t("./utils"),a=o.debug("xumm-sdk:xapp");r.Push=class{constructor(t){a("Constructed"),this.Meta=t,this.userdata=new i.JwtUserdata(t)}event(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("xapp/event","POST",t);return s.throwIfError(e),e}))}notification(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("xapp/push","POST",t);return s.throwIfError(e),e}))}}},{"./JwtUserdata":1,"./utils":6,debug:10}],5:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.Storage=void 0;const o=t("debug"),i=t("./utils"),s=o.debug("xumm-sdk:storage");r.Storage=class{constructor(t){s("Constructed"),this.Meta=t}get(){return n(this,void 0,void 0,(function*(){const t=yield this.Meta.call("app-storage","GET");return i.throwIfError(t),t.data}))}set(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("app-storage","POST",t);return i.throwIfError(e),e.stored}))}delete(){return n(this,void 0,void 0,(function*(){const t=yield this.Meta.call("app-storage","DELETE");return i.throwIfError(t),t.stored}))}}},{"./utils":6,debug:10}],6:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.DeferredPromise=r.throwIfError=void 0,r.throwIfError=function(t){var e,r,n,o,i,s;if(void 0!==t.message)throw new Error(t.message);if(void 0===t.next&&void 0===(null===(r=null===(e=t)||void 0===e?void 0:e.meta)||void 0===r?void 0:r.uuid)&&void 0===(null===(o=null===(n=t)||void 0===n?void 0:n.application)||void 0===o?void 0:o.uuidv4)&&void 0!==(null===(s=null===(i=t)||void 0===i?void 0:i.error)||void 0===s?void 0:s.code)){const e=t.error;throw new Error(`Error code ${e.code}, see XUMM Dev Console, reference: ${e.reference}`)}};r.DeferredPromise=class{constructor(){this.resolveFn=t=>{},this.rejectFn=t=>{},this.promise=new Promise(((t,e)=>{this.resolveFn=t,this.rejectFn=e}))}resolve(t){return this.resolveFn(t),this.promise}reject(t){return this.rejectFn(t),this.promise}}},{}],7:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.xApp=void 0;const o=t("debug"),i=t("./JwtUserdata"),s=t("./utils"),a=o.debug("xumm-sdk:xapp");r.xApp=class{constructor(t){a("Constructed"),this.Meta=t,this.userdata=new i.JwtUserdata(t)}get(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("xapp/ott/"+t,"GET");return s.throwIfError(e),e}))}}},{"./JwtUserdata":1,"./utils":6,debug:10}],8:[function(t,e,r){"use strict";r.byteLength=function(t){var e=f(t),r=e[0],n=e[1];return 3*(r+n)/4-n},r.toByteArray=function(t){var e,r,n=f(t),s=n[0],a=n[1],u=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,a)),c=0,l=a>0?s-4:s;for(r=0;r<l;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],u[c++]=e>>16&255,u[c++]=e>>8&255,u[c++]=255&e;2===a&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,u[c++]=255&e);1===a&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,u[c++]=e>>8&255,u[c++]=255&e);return u},r.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],s=16383,a=0,u=r-o;a<u;a+=s)i.push(c(t,a,a+s>u?u:a+s));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function f(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function c(t,e,r){for(var o,i,s=[],a=e;a<r;a+=3)o=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],9:[function(t,e,r){(function(e){(function(){
require=function t(e,r,n){function o(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=r[s]={exports:{}};e[s][0].call(c.exports,(function(t){return o(e[s][1][t]||t)}),c,c.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.JwtUserdata=void 0;const o=t("debug"),i=t("./utils"),s=o.debug("xumm-sdk:xapp:userdata");r.JwtUserdata=class{constructor(t){s("Constructed"),this.Meta=t}list(){return n(this,void 0,void 0,(function*(){const t=yield this.Meta.call("userdata","GET");return i.throwIfError(t),t.keys}))}get(t){var e;return n(this,void 0,void 0,(function*(){const r=Array.isArray(t)?t.join(","):t,n=yield this.Meta.call("userdata/"+r,"GET");return i.throwIfError(n),r.split(",").length>1?n.data:(null===(e=n.data)||void 0===e?void 0:e[r])||{}}))}delete(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("userdata/"+t,"DELETE");return i.throwIfError(e),e.persisted}))}set(t,e){return n(this,void 0,void 0,(function*(){const r=yield this.Meta.call("userdata/"+t,"POST",e);return i.throwIfError(r),r.persisted}))}}},{"./utils":6,debug:10}],2:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,"__esModule",{value:!0}),r.Meta=void 0;const i=t("debug"),s=o(t("fetch-ponyfill")),{fetch:a,Request:u,Response:f,Headers:c}=s.default(),l=t("os-browserify"),h=t("./utils"),d=t("./index"),p=i.debug("xumm-sdk:meta");r.Meta=class{constructor(t,e){this.isBrowser=!1,this.jwtFlow=!1,this.injected=!1,this.endpoint="https://xumm.app",p("Constructed");const r=new RegExp("^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"),n={split:e.split(":"),uuidv4:""};if(3===n.split.length&&"xApp:OneTimeToken"===n.split.slice(0,2).join(":")?(n.uuidv4=n.split[2],this.jwtFlow=!0):n.split.length>1&&"RAWJWT"===n.split[0]?(this.jwtFlow=!0,this.jwt=n.split.slice(1).join(":")):n.uuidv4=e,!r.test(t)||!r.test(n.uuidv4)){if(!this.jwtFlow)throw new Error("Invalid API Key and/or API Secret. Use dotenv or constructor params.");if(!this.jwt)throw new Error("Invalid API Key and/or OTT (One Time Token). Provide OTT param (2nd param) or make sure `xAppToken` query param is present (Browser)")}return"undefined"!=typeof globalThis&&Object.keys(globalThis).indexOf("window")<0?p("Running in node"):(console.log("XUMM SDK: Running in browser"),this.isBrowser=!0),this.apiKey=t,this.apiSecret=n.uuidv4,this.jwtFlow&&!this.jwt&&(this.authPromise=new Promise((t=>{this.authPromiseResolve=t})),Promise.resolve().then((()=>this.authorize())).catch((t=>{p("Authorize error:",t.message),(null==this?void 0:this.invoker)&&this.invoker.caught(t),this.authPromiseResolve&&this.authPromiseResolve()}))),this}setEndpoint(t){return!!t.match(/^http/)&&(this.endpoint=t.trim(),!0)}authorize(){var t,e,r,o;return n(this,void 0,void 0,(function*(){let n;p("JWT Authorize",this.apiSecret),(null==this?void 0:this.invoker)&&this.invoker.constructor===d.XummSdkJwt&&(n=this.invoker._jwtStore(this,(t=>this.jwt=t)));const i=(null==n?void 0:n.get(this.apiSecret))||(yield this.call("authorize"));if(null===(e=null===(t=i)||void 0===t?void 0:t.error)||void 0===e?void 0:e.code)p("Could not resolve API Key & OTT to JWT (already fetched? Unauthorized?)"),(null==this?void 0:this.invoker)&&this.invoker.constructor===d.XummSdkJwt&&(null===(r=null==this?void 0:this.invoker)||void 0===r?void 0:r.fatalHandler)?this.invoker.fatalHandler(new Error(i.error.reference)):h.throwIfError(i);else{if(!(null===(o=i)||void 0===o?void 0:o.jwt))throw new Error("Unexpected response for xApp JWT authorize request");{const t=i;null==n||n.set(this.apiSecret,t)}}this.authPromiseResolve&&this.authPromiseResolve()}))}call(t,e="GET",r){var o;return n(this,void 0,void 0,(function*(){const n=e.toUpperCase(),i=t.split("/")[0];this.jwtFlow&&!(null==this?void 0:this.jwt)&&this.authPromise&&"authorize"!==t&&(yield this.authPromise);try{let e;void 0!==r&&("object"==typeof r&&null!==r&&(e=JSON.stringify(r)),"string"==typeof r&&(e=r));const o={"Content-Type":"application/json"};this.isBrowser||Object.assign(o,{"User-Agent":`xumm-sdk/node (${l.hostname()}) node-fetch`}),this.jwtFlow?"authorize"===t?Object.assign(o,{"x-api-key":this.apiKey,"x-api-ott":this.apiSecret}):Object.assign(o,{Authorization:"Bearer "+this.jwt}):Object.assign(o,{"x-api-key":this.apiKey,"x-api-secret":this.apiSecret});const s=["authorize","ping","curated-assets","rates","payload","userdata","xrpl-tx","nftoken-detail","rails","hookhash"],u=this.jwtFlow&&s.indexOf(i)>-1?"jwt":"platform",f=yield a(this.endpoint+"/api/v1/"+u+"/"+t,{method:n,body:e,headers:o});return yield f.json()}catch(t){const e=new Error(`Unexpected response from XUMM API [${n}:${i}]`);throw e.stack=(null===(o=t)||void 0===o?void 0:o.stack)||void 0,e}}))}ping(){var t,e;return n(this,void 0,void 0,(function*(){const r=yield this.call("ping");if(h.throwIfError(r),void 0!==r.auth)return r.auth;if(void 0!==(null===(t=r)||void 0===t?void 0:t.ott_uuidv4))return{application:{uuidv4:r.app_uuidv4,name:r.app_name},jwtData:r};if(void 0!==(null===(e=r)||void 0===e?void 0:e.usertoken_uuidv4))return{application:{uuidv4:r.client_id,name:r.app_name},jwtData:r};throw new Error("Unexpected response for ping request")}))}getCuratedAssets(){return n(this,void 0,void 0,(function*(){return yield this.call("curated-assets")}))}getRates(t){return n(this,void 0,void 0,(function*(){return yield this.call("rates/"+t.trim().toUpperCase())}))}getKycStatus(t){return n(this,void 0,void 0,(function*(){if(t.trim().match(/^r/)){const e=yield this.call("kyc-status/"+t.trim());return(null==e?void 0:e.kycApproved)?"SUCCESSFUL":"NONE"}{const e=yield this.call("kyc-status","POST",{user_token:t});return(null==e?void 0:e.kycStatus)||"NONE"}}))}getRails(){return n(this,void 0,void 0,(function*(){return yield this.call("rails")}))}getHookHash(t){return n(this,void 0,void 0,(function*(){if("string"==typeof t&&t.trim().match(/^[A-Fa-f0-9]{64}$/))return yield this.call("hookhash/"+t.trim());throw Error("Invalid Hook Hash (expecting 64 char hex)")}))}getHookHashes(){return n(this,void 0,void 0,(function*(){return yield this.call("hookhash")}))}getTransaction(t){return n(this,void 0,void 0,(function*(){return yield this.call("xrpl-tx/"+t.trim())}))}getNftokenDetail(t){return n(this,void 0,void 0,(function*(){if(!this.jwtFlow)throw new Error("getNftokenDetail: only available in JWT (XummSdkJwt) mode");return yield this.call("nftoken-detail/"+t.trim())}))}verifyUserTokens(t){return n(this,void 0,void 0,(function*(){return(yield this.call("user-tokens","POST",{tokens:Array.isArray(t)?t:[t]})).tokens}))}_inject(t){if(this.injected)throw new Error("Cannot `_inject` twice");this.invoker=t}}},{"./index":"xumm-sdk","./utils":6,debug:10,"fetch-ponyfill":13,"os-browserify":16}],3:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.Payload=void 0;const o=t("debug"),i=t("websocket"),s=t("./utils"),a=o.debug("xumm-sdk:payload"),u=o.debug("xumm-sdk:payload:websocket");r.Payload=class{constructor(t){a("Constructed"),this.Meta=t}resolvePayload(t){var e,r,o;return n(this,void 0,void 0,(function*(){if("string"==typeof t)return yield this.get(t,!0);if(void 0!==(null===(e=t)||void 0===e?void 0:e.uuid))return yield this.get(t.uuid,!0);if(void 0!==(null===(o=null===(r=t)||void 0===r?void 0:r.meta)||void 0===o?void 0:o.uuid))return t;throw new Error("Could not resolve payload (not found)")}))}create(t,e=!1){var r;return n(this,void 0,void 0,(function*(){const n=void 0!==t.TransactionType&&void 0===t.txjson,o=yield this.Meta.call("payload","POST",n?{txjson:t}:t);e&&s.throwIfError(o);return void 0!==(null===(r=o)||void 0===r?void 0:r.next)?o:null}))}get(t,e=!1){var r,o;return n(this,void 0,void 0,(function*(){const n="string"==typeof t?t:null==t?void 0:t.uuid,i=yield this.Meta.call("payload/"+n,"GET");e&&s.throwIfError(i);return void 0!==(null===(o=null===(r=i)||void 0===r?void 0:r.meta)||void 0===o?void 0:o.uuid)?i:null}))}subscribe(t,e){var r,o;return n(this,void 0,void 0,(function*(){const a=new s.DeferredPromise,f=yield this.resolvePayload(t);if(f){const t="undefined",s=typeof(null===(r=globalThis)||void 0===r?void 0:r.MockedWebSocket)!==t&&typeof jest!==t?new(null===(o=globalThis)||void 0===o?void 0:o.MockedWebSocket)("ws://xumm.local"):new i.w3cwebsocket(this.Meta.endpoint.replace(/^http/,"ws")+"/sign/"+f.meta.uuid);return a.promise.then((()=>{s.close()})),s.onopen=()=>{u(`Payload ${f.meta.uuid}: Subscription active (WebSocket opened)`)},s.onmessage=t=>n(this,void 0,void 0,(function*(){const r=t.data;let o;try{o=JSON.parse(r.toString())}catch(t){u(`Payload ${f.meta.uuid}: Received message, unable to parse as JSON`,t)}if(o&&e&&void 0===o.devapp_fetched)try{const t=yield e({uuid:f.meta.uuid,data:o,resolve(t){return n(this,void 0,void 0,(function*(){yield a.resolve(t||void 0)}))},payload:f});void 0!==t&&a.resolve(t)}catch(t){u(`Payload ${f.meta.uuid}: Callback exception`,t)}})),s.onclose=t=>{u(`Payload ${f.meta.uuid}: Subscription ended (WebSocket closed)`)},{payload:f,resolve(t){a.resolve(t||void 0)},resolved:a.promise,websocket:s}}throw s.throwIfError(f),Error("Couldn't subscribe: couldn't fetch payload")}))}cancel(t,e=!1){var r,o,i;return n(this,void 0,void 0,(function*(){const n=yield this.resolvePayload(t),a=yield this.Meta.call("payload/"+(null===(r=null==n?void 0:n.meta)||void 0===r?void 0:r.uuid),"DELETE");e&&s.throwIfError(a);return void 0!==(null===(i=null===(o=a)||void 0===o?void 0:o.meta)||void 0===i?void 0:i.uuid)?a:null}))}createAndSubscribe(t,e){return n(this,void 0,void 0,(function*(){const r=yield this.create(t,!0);if(r){const t=yield this.subscribe(r,e);return Object.assign({created:r},t)}throw new Error("Error creating payload or subscribing to created payload")}))}}},{"./utils":6,debug:10,websocket:18}],4:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.Push=void 0;const o=t("debug"),i=t("./JwtUserdata"),s=t("./utils"),a=o.debug("xumm-sdk:xapp");r.Push=class{constructor(t){a("Constructed"),this.Meta=t,this.userdata=new i.JwtUserdata(t)}event(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("xapp/event","POST",t);return s.throwIfError(e),e}))}notification(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("xapp/push","POST",t);return s.throwIfError(e),e}))}}},{"./JwtUserdata":1,"./utils":6,debug:10}],5:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.Storage=void 0;const o=t("debug"),i=t("./utils"),s=o.debug("xumm-sdk:storage");r.Storage=class{constructor(t){s("Constructed"),this.Meta=t}get(){return n(this,void 0,void 0,(function*(){const t=yield this.Meta.call("app-storage","GET");return i.throwIfError(t),t.data}))}set(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("app-storage","POST",t);return i.throwIfError(e),e.stored}))}delete(){return n(this,void 0,void 0,(function*(){const t=yield this.Meta.call("app-storage","DELETE");return i.throwIfError(t),t.stored}))}}},{"./utils":6,debug:10}],6:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.DeferredPromise=r.throwIfError=void 0,r.throwIfError=function(t){var e,r,n,o,i,s;if(void 0!==t.message)throw new Error(t.message);if(void 0===t.next&&void 0===(null===(r=null===(e=t)||void 0===e?void 0:e.meta)||void 0===r?void 0:r.uuid)&&void 0===(null===(o=null===(n=t)||void 0===n?void 0:n.application)||void 0===o?void 0:o.uuidv4)&&void 0!==(null===(s=null===(i=t)||void 0===i?void 0:i.error)||void 0===s?void 0:s.code)){const e=t.error;throw new Error(`Error code ${e.code}, see XUMM Dev Console, reference: ${e.reference}`)}};r.DeferredPromise=class{constructor(){this.resolveFn=t=>{},this.rejectFn=t=>{},this.promise=new Promise(((t,e)=>{this.resolveFn=t,this.rejectFn=e}))}resolve(t){return this.resolveFn(t),this.promise}reject(t){return this.rejectFn(t),this.promise}}},{}],7:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.xApp=void 0;const o=t("debug"),i=t("./JwtUserdata"),s=t("./utils"),a=o.debug("xumm-sdk:xapp");r.xApp=class{constructor(t){a("Constructed"),this.Meta=t,this.userdata=new i.JwtUserdata(t)}get(t){return n(this,void 0,void 0,(function*(){const e=yield this.Meta.call("xapp/ott/"+t,"GET");return s.throwIfError(e),e}))}}},{"./JwtUserdata":1,"./utils":6,debug:10}],8:[function(t,e,r){"use strict";r.byteLength=function(t){var e=f(t),r=e[0],n=e[1];return 3*(r+n)/4-n},r.toByteArray=function(t){var e,r,n=f(t),s=n[0],a=n[1],u=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,a)),c=0,l=a>0?s-4:s;for(r=0;r<l;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],u[c++]=e>>16&255,u[c++]=e>>8&255,u[c++]=255&e;2===a&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,u[c++]=255&e);1===a&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,u[c++]=e>>8&255,u[c++]=255&e);return u},r.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],s=16383,a=0,u=r-o;a<u;a+=s)i.push(c(t,a,a+s>u?u:a+s));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function f(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function c(t,e,r){for(var o,i,s=[],a=e;a<r;a+=3)o=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],9:[function(t,e,r){(function(e){(function(){
/*!

@@ -3,0 +3,0 @@ * The buffer module from node.js, for the browser.

@@ -180,3 +180,5 @@ "use strict";

'xrpl-tx',
'nftoken-detail'
'nftoken-detail',
'rails',
'hookhash'
];

@@ -183,0 +185,0 @@ const endpointType = this.jwtFlow && jwtEndpoints.indexOf(trEndpoint) > -1

{
"name": "xumm-sdk",
"version": "1.8.10",
"version": "1.9.0",
"description": "Interact with the Xumm Developer API",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc