@xdefi/bitcoin-provider
Advanced tools
Comparing version 0.0.1 to 0.0.11
@@ -0,21 +1,98 @@ | ||
import { EventEmitter } from 'events'; | ||
/** * @internal */ | ||
class Greeter { | ||
constructor(greeting) { | ||
this.greeting = greeting; | ||
const genPayloadId = () => { | ||
const thousand = 1000; | ||
const date = new Date().getTime() * thousand; | ||
const extra = Math.floor(Math.random() * thousand); | ||
return date + extra; | ||
}; | ||
var XDEFIBitcoinPayloadMethods; | ||
(function (XDEFIBitcoinPayloadMethods) { | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["REQUEST_ACCOUNTS"] = 0] = "REQUEST_ACCOUNTS"; | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["SIGN_TRANSACTION"] = 1] = "SIGN_TRANSACTION"; | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["GET_UNSPENT_UTXOS"] = 2] = "GET_UNSPENT_UTXOS"; | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["TRANSFER"] = 3] = "TRANSFER"; | ||
})(XDEFIBitcoinPayloadMethods || (XDEFIBitcoinPayloadMethods = {})); | ||
var MessageNamespace; | ||
(function (MessageNamespace) { | ||
MessageNamespace[MessageNamespace["BINANCEDEX"] = 0] = "BINANCEDEX"; | ||
MessageNamespace[MessageNamespace["BINANCESMARTCHAIN"] = 1] = "BINANCESMARTCHAIN"; | ||
MessageNamespace[MessageNamespace["BITCOIN"] = 2] = "BITCOIN"; | ||
MessageNamespace[MessageNamespace["ETHEREUM"] = 3] = "ETHEREUM"; | ||
})(MessageNamespace || (MessageNamespace = {})); | ||
class XDEFIBitcoinProvider extends EventEmitter { | ||
constructor(msgStream, callBacksMap) { | ||
super(); | ||
this.msgStream = msgStream; | ||
this.callBacksMap = callBacksMap; | ||
this.chainId = 'mainnet'; | ||
this.network = 'mainnet'; | ||
} | ||
greet() { | ||
return `Hello, ${this.greeting}!`; | ||
// This will be called when accounts have changed and need to be re-pulled | ||
// by the dApp | ||
emitAccountsChanged() { | ||
this.emit('accountsChanged', {}); | ||
} | ||
greetMe() { | ||
/* istanbul ignore next line */ | ||
changeNetwork(chainId, network) { | ||
if (chainId !== network) { | ||
throw Error(`changeNetwork failed, incorrect chainId-network ${chainId} ${network}`); | ||
} | ||
if (!['mainnet', 'testnet'].includes(chainId)) { | ||
throw Error(`changeNetwork failed, incorrect chainId-network ${chainId} ${network}`); | ||
} | ||
this.chainId = chainId; | ||
this.network = network; | ||
this.emit('chainChanged', { | ||
chainId, | ||
network, | ||
}); | ||
} | ||
request(payload, callbackFunction) { | ||
{ | ||
// tslint:disable-next-line:no-console | ||
console.warn('this method is deprecated, use #greet instead'); | ||
console.log('<==== request bitcoin provider', payload); | ||
} | ||
return this.greet(); | ||
const pId = genPayloadId(); | ||
let msg; | ||
switch (payload.method) { | ||
case XDEFIBitcoinPayloadMethods.REQUEST_ACCOUNTS: | ||
case XDEFIBitcoinPayloadMethods.SIGN_TRANSACTION: | ||
case XDEFIBitcoinPayloadMethods.GET_UNSPENT_UTXOS: | ||
case XDEFIBitcoinPayloadMethods.TRANSFER: | ||
msg = { | ||
name: 'provider', | ||
data: { | ||
xdefiId: pId, | ||
origin: null, | ||
namespace: MessageNamespace.BITCOIN, | ||
raw: { | ||
id: pId, | ||
method: payload.method, | ||
params: payload.params, | ||
}, | ||
time: Date.now(), | ||
}, | ||
}; | ||
if (callbackFunction && this.callBacksMap) { | ||
this.callBacksMap.set(msg.data.raw.id, callbackFunction); | ||
} | ||
if (this.msgStream) { | ||
this.msgStream.write(msg); | ||
} | ||
break; | ||
default: | ||
throw Error(`XDEFI Bitcoin Provider: this method ${payload.method} is not supported`); | ||
} | ||
// return; | ||
} | ||
} | ||
const _initBinanceDexProvider = (msgStream, callBacksMap) => { | ||
return new XDEFIBitcoinProvider(msgStream, callBacksMap); | ||
}; | ||
const initBinanceDexProvider = _initBinanceDexProvider; | ||
export { Greeter }; | ||
export { XDEFIBitcoinProvider, initBinanceDexProvider, XDEFIBitcoinPayloadMethods, MessageNamespace }; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
class Greeter{constructor(e){this.greeting=e}greet(){return`Hello, ${this.greeting}!`}greetMe(){return this.greet()}}export{Greeter}; | ||
import{EventEmitter}from"events";const genPayloadId=()=>{return 1e3*(new Date).getTime()+Math.floor(1e3*Math.random())};var XDEFIBitcoinPayloadMethods,MessageNamespace;!function(e){e[e.REQUEST_ACCOUNTS=0]="REQUEST_ACCOUNTS",e[e.SIGN_TRANSACTION=1]="SIGN_TRANSACTION",e[e.GET_UNSPENT_UTXOS=2]="GET_UNSPENT_UTXOS",e[e.TRANSFER=3]="TRANSFER"}(XDEFIBitcoinPayloadMethods||(XDEFIBitcoinPayloadMethods={})),function(e){e[e.BINANCEDEX=0]="BINANCEDEX",e[e.BINANCESMARTCHAIN=1]="BINANCESMARTCHAIN",e[e.BITCOIN=2]="BITCOIN",e[e.ETHEREUM=3]="ETHEREUM"}(MessageNamespace||(MessageNamespace={}));class XDEFIBitcoinProvider extends EventEmitter{constructor(e,t){super(),this.msgStream=e,this.callBacksMap=t,this.chainId="mainnet",this.network="mainnet"}emitAccountsChanged(){this.emit("accountsChanged",{})}changeNetwork(e,t){if(e!==t)throw Error(`changeNetwork failed, incorrect chainId-network ${e} ${t}`);if(!["mainnet","testnet"].includes(e))throw Error(`changeNetwork failed, incorrect chainId-network ${e} ${t}`);this.chainId=e,this.network=t,this.emit("chainChanged",{chainId:e,network:t})}request(e,t){const a=genPayloadId();let i;switch(e.method){case XDEFIBitcoinPayloadMethods.REQUEST_ACCOUNTS:case XDEFIBitcoinPayloadMethods.SIGN_TRANSACTION:case XDEFIBitcoinPayloadMethods.GET_UNSPENT_UTXOS:case XDEFIBitcoinPayloadMethods.TRANSFER:i={name:"provider",data:{xdefiId:a,origin:null,namespace:MessageNamespace.BITCOIN,raw:{id:a,method:e.method,params:e.params},time:Date.now()}},t&&this.callBacksMap&&this.callBacksMap.set(i.data.raw.id,t),this.msgStream&&this.msgStream.write(i);break;default:throw Error(`XDEFI Bitcoin Provider: this method ${e.method} is not supported`)}}}const _initBinanceDexProvider=(e,t)=>new XDEFIBitcoinProvider(e,t),initBinanceDexProvider=_initBinanceDexProvider;export{XDEFIBitcoinProvider,initBinanceDexProvider,XDEFIBitcoinPayloadMethods,MessageNamespace}; | ||
//# sourceMappingURL=index.esm.min.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.BitcoinProvider = {})); | ||
}(this, function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('events')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'events'], factory) : | ||
(global = global || self, factory(global.BitcoinProvider = {}, global.tslib_1, global.events)); | ||
}(this, function (exports, tslib_1, events) { 'use strict'; | ||
/** * @internal */ | ||
var Greeter = /** @class */ (function () { | ||
function Greeter(greeting) { | ||
this.greeting = greeting; | ||
var genPayloadId = function () { | ||
var thousand = 1000; | ||
var date = new Date().getTime() * thousand; | ||
var extra = Math.floor(Math.random() * thousand); | ||
return date + extra; | ||
}; | ||
(function (XDEFIBitcoinPayloadMethods) { | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["REQUEST_ACCOUNTS"] = 0] = "REQUEST_ACCOUNTS"; | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["SIGN_TRANSACTION"] = 1] = "SIGN_TRANSACTION"; | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["GET_UNSPENT_UTXOS"] = 2] = "GET_UNSPENT_UTXOS"; | ||
XDEFIBitcoinPayloadMethods[XDEFIBitcoinPayloadMethods["TRANSFER"] = 3] = "TRANSFER"; | ||
})(exports.XDEFIBitcoinPayloadMethods || (exports.XDEFIBitcoinPayloadMethods = {})); | ||
(function (MessageNamespace) { | ||
MessageNamespace[MessageNamespace["BINANCEDEX"] = 0] = "BINANCEDEX"; | ||
MessageNamespace[MessageNamespace["BINANCESMARTCHAIN"] = 1] = "BINANCESMARTCHAIN"; | ||
MessageNamespace[MessageNamespace["BITCOIN"] = 2] = "BITCOIN"; | ||
MessageNamespace[MessageNamespace["ETHEREUM"] = 3] = "ETHEREUM"; | ||
})(exports.MessageNamespace || (exports.MessageNamespace = {})); | ||
var XDEFIBitcoinProvider = /** @class */ (function (_super) { | ||
tslib_1.__extends(XDEFIBitcoinProvider, _super); | ||
function XDEFIBitcoinProvider(msgStream, callBacksMap) { | ||
var _this = _super.call(this) || this; | ||
_this.msgStream = msgStream; | ||
_this.callBacksMap = callBacksMap; | ||
_this.chainId = 'mainnet'; | ||
_this.network = 'mainnet'; | ||
return _this; | ||
} | ||
Greeter.prototype.greet = function () { | ||
return "Hello, " + this.greeting + "!"; | ||
// This will be called when accounts have changed and need to be re-pulled | ||
// by the dApp | ||
XDEFIBitcoinProvider.prototype.emitAccountsChanged = function () { | ||
this.emit('accountsChanged', {}); | ||
}; | ||
Greeter.prototype.greetMe = function () { | ||
/* istanbul ignore next line */ | ||
XDEFIBitcoinProvider.prototype.changeNetwork = function (chainId, network) { | ||
if (chainId !== network) { | ||
throw Error("changeNetwork failed, incorrect chainId-network " + chainId + " " + network); | ||
} | ||
if (!['mainnet', 'testnet'].includes(chainId)) { | ||
throw Error("changeNetwork failed, incorrect chainId-network " + chainId + " " + network); | ||
} | ||
this.chainId = chainId; | ||
this.network = network; | ||
this.emit('chainChanged', { | ||
chainId: chainId, | ||
network: network, | ||
}); | ||
}; | ||
XDEFIBitcoinProvider.prototype.request = function (payload, callbackFunction) { | ||
{ | ||
// tslint:disable-next-line:no-console | ||
console.warn('this method is deprecated, use #greet instead'); | ||
console.log('<==== request bitcoin provider', payload); | ||
} | ||
return this.greet(); | ||
var pId = genPayloadId(); | ||
var msg; | ||
switch (payload.method) { | ||
case exports.XDEFIBitcoinPayloadMethods.REQUEST_ACCOUNTS: | ||
case exports.XDEFIBitcoinPayloadMethods.SIGN_TRANSACTION: | ||
case exports.XDEFIBitcoinPayloadMethods.GET_UNSPENT_UTXOS: | ||
case exports.XDEFIBitcoinPayloadMethods.TRANSFER: | ||
msg = { | ||
name: 'provider', | ||
data: { | ||
xdefiId: pId, | ||
origin: null, | ||
namespace: exports.MessageNamespace.BITCOIN, | ||
raw: { | ||
id: pId, | ||
method: payload.method, | ||
params: payload.params, | ||
}, | ||
time: Date.now(), | ||
}, | ||
}; | ||
if (callbackFunction && this.callBacksMap) { | ||
this.callBacksMap.set(msg.data.raw.id, callbackFunction); | ||
} | ||
if (this.msgStream) { | ||
this.msgStream.write(msg); | ||
} | ||
break; | ||
default: | ||
throw Error("XDEFI Bitcoin Provider: this method " + payload.method + " is not supported"); | ||
} | ||
// return; | ||
}; | ||
return Greeter; | ||
}()); | ||
return XDEFIBitcoinProvider; | ||
}(events.EventEmitter)); | ||
var _initBinanceDexProvider = function (msgStream, callBacksMap) { | ||
return new XDEFIBitcoinProvider(msgStream, callBacksMap); | ||
}; | ||
var initBinanceDexProvider = _initBinanceDexProvider; | ||
exports.Greeter = Greeter; | ||
exports.XDEFIBitcoinProvider = XDEFIBitcoinProvider; | ||
exports.initBinanceDexProvider = initBinanceDexProvider; | ||
@@ -29,0 +105,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).BitcoinProvider={})}(this,function(e){"use strict";var t=function(){function e(e){this.greeting=e}return e.prototype.greet=function(){return"Hello, "+this.greeting+"!"},e.prototype.greetMe=function(){return this.greet()},e}();e.Greeter=t,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("events")):"function"==typeof define&&define.amd?define(["exports","tslib","events"],t):t((e=e||self).BitcoinProvider={},e.tslib_1,e.events)}(this,function(n,t,e){"use strict";var i,a;(i=n.XDEFIBitcoinPayloadMethods||(n.XDEFIBitcoinPayloadMethods={}))[i.REQUEST_ACCOUNTS=0]="REQUEST_ACCOUNTS",i[i.SIGN_TRANSACTION=1]="SIGN_TRANSACTION",i[i.GET_UNSPENT_UTXOS=2]="GET_UNSPENT_UTXOS",i[i.TRANSFER=3]="TRANSFER",(a=n.MessageNamespace||(n.MessageNamespace={}))[a.BINANCEDEX=0]="BINANCEDEX",a[a.BINANCESMARTCHAIN=1]="BINANCESMARTCHAIN",a[a.BITCOIN=2]="BITCOIN",a[a.ETHEREUM=3]="ETHEREUM";var o=function(a){function e(e,t){var i=a.call(this)||this;return i.msgStream=e,i.callBacksMap=t,i.chainId="mainnet",i.network="mainnet",i}return t.__extends(e,a),e.prototype.emitAccountsChanged=function(){this.emit("accountsChanged",{})},e.prototype.changeNetwork=function(e,t){if(e!==t)throw Error("changeNetwork failed, incorrect chainId-network "+e+" "+t);if(!["mainnet","testnet"].includes(e))throw Error("changeNetwork failed, incorrect chainId-network "+e+" "+t);this.chainId=e,this.network=t,this.emit("chainChanged",{chainId:e,network:t})},e.prototype.request=function(e,t){var i,a=1e3*(new Date).getTime()+Math.floor(1e3*Math.random());switch(e.method){case n.XDEFIBitcoinPayloadMethods.REQUEST_ACCOUNTS:case n.XDEFIBitcoinPayloadMethods.SIGN_TRANSACTION:case n.XDEFIBitcoinPayloadMethods.GET_UNSPENT_UTXOS:case n.XDEFIBitcoinPayloadMethods.TRANSFER:i={name:"provider",data:{xdefiId:a,origin:null,namespace:n.MessageNamespace.BITCOIN,raw:{id:a,method:e.method,params:e.params},time:Date.now()}},t&&this.callBacksMap&&this.callBacksMap.set(i.data.raw.id,t),this.msgStream&&this.msgStream.write(i);break;default:throw Error("XDEFI Bitcoin Provider: this method "+e.method+" is not supported")}},e}(e.EventEmitter),r=function(e,t){return new o(e,t)};n.XDEFIBitcoinProvider=o,n.initBinanceDexProvider=r,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -1,2 +0,3 @@ | ||
export { Greeter } from './greeter'; | ||
export * from './xdefi-bitcoin-provider'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,3 @@ | ||
export { Greeter } from './greeter'; | ||
export * from './xdefi-bitcoin-provider'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@xdefi/bitcoin-provider", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "xdefi bitcoin provider", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,3 @@ | ||
export { Greeter } from './greeter'; | ||
export * from './xdefi-bitcoin-provider'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@xdefi/bitcoin-provider", | ||
"version": "0.0.1", | ||
"version": "0.0.11", | ||
"description": "xdefi bitcoin provider", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
65933
46
465
3
1