anchor-link
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -251,2 +251,13 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.AnchorLink = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
} | ||
prepare(request) { | ||
if (this.link.transport.prepare) { | ||
return this.link.transport.prepare(request, this); | ||
} | ||
return Promise.resolve(request); | ||
} | ||
showLoading() { | ||
if (this.link.transport.showLoading) { | ||
return this.link.transport.showLoading(); | ||
} | ||
} | ||
makeSignatureProvider() { | ||
@@ -300,2 +311,13 @@ return this.link.makeSignatureProvider([this.publicKey], this); | ||
} | ||
prepare(request) { | ||
if (this.link.transport.prepare) { | ||
return this.link.transport.prepare(request, this); | ||
} | ||
return Promise.resolve(request); | ||
} | ||
showLoading() { | ||
if (this.link.transport.showLoading) { | ||
return this.link.transport.showLoading(); | ||
} | ||
} | ||
makeSignatureProvider() { | ||
@@ -369,2 +391,3 @@ return this.link.makeSignatureProvider([this.publicKey], this); | ||
this.abiCache = new Map(); | ||
this.pendingAbis = new Map(); | ||
if (typeof options !== 'object') { | ||
@@ -410,3 +433,9 @@ throw new TypeError('Missing options object'); | ||
if (!rv) { | ||
rv = (await this.rpc.get_abi(account)).abi; | ||
let getAbi = this.pendingAbis.get(account); | ||
if (!getAbi) { | ||
getAbi = this.rpc.get_abi(account); | ||
this.pendingAbis.set(account, getAbi); | ||
} | ||
rv = (await getAbi).abi; | ||
this.pendingAbis.delete(account); | ||
if (rv) { | ||
@@ -429,5 +458,6 @@ this.abiCache.set(account, rv); | ||
*/ | ||
async createRequest(args) { | ||
async createRequest(args, transport) { | ||
const t = transport || this.transport; | ||
// generate unique callback url | ||
const request = await esr.SigningRequest.create({ | ||
let request = await esr.SigningRequest.create({ | ||
...args, | ||
@@ -441,2 +471,5 @@ chainId: this.chainId, | ||
}, this.requestOptions); | ||
if (t.prepare) { | ||
request = await t.prepare(request); | ||
} | ||
return request; | ||
@@ -460,3 +493,8 @@ } | ||
const ctx = {}; | ||
const socket = waitForCallback(linkUrl, ctx); | ||
const socket = waitForCallback(linkUrl, ctx).then((data) => { | ||
if (typeof data.rejected === 'string') { | ||
throw new errors_1.CancelError(`Rejected by wallet: ${data.rejected}`); | ||
} | ||
return data; | ||
}); | ||
const cancel = new Promise((resolve, reject) => { | ||
@@ -485,2 +523,6 @@ t.onRequest(request, (reason) => { | ||
const resolved = await esr.ResolvedSigningRequest.fromPayload(payload, this.requestOptions); | ||
const info = resolved.request.getInfo(); | ||
if (info['fuel_sig']) { | ||
signatures.unshift(info['fuel_sig']); | ||
} | ||
const { serializedTransaction, transaction } = resolved; | ||
@@ -530,3 +572,28 @@ const result = { | ||
const broadcast = options ? options.broadcast !== false : true; | ||
const request = await this.createRequest(args); | ||
// Initialize the loading state of the transport | ||
if (t && t.showLoading) { | ||
t.showLoading(); | ||
} | ||
// eosjs transact compat: upgrade to transaction if args have any header fields | ||
let anyArgs = args; | ||
if (args.actions && | ||
(anyArgs.expiration || | ||
anyArgs.ref_block_num || | ||
anyArgs.ref_block_prefix || | ||
anyArgs.max_net_usage_words || | ||
anyArgs.max_cpu_usage_ms || | ||
anyArgs.delay_sec)) { | ||
args = { | ||
transaction: { | ||
expiration: '1970-01-01T00:00:00', | ||
ref_block_num: 0, | ||
ref_block_prefix: 0, | ||
max_net_usage_words: 0, | ||
max_cpu_usage_ms: 0, | ||
delay_sec: 0, | ||
...anyArgs, | ||
}, | ||
}; | ||
} | ||
const request = await this.createRequest(args, t); | ||
const result = await this.sendRequest(request, t, broadcast); | ||
@@ -533,0 +600,0 @@ return result; |
@@ -96,2 +96,4 @@ import { ApiInterfaces } from 'eosjs'; | ||
onRequest(request: any, cancel: any): void; | ||
prepare(request: any): Promise<any>; | ||
showLoading(): void; | ||
makeSignatureProvider(): ApiInterfaces.SignatureProvider; | ||
@@ -131,2 +133,4 @@ makeAuthorityProvider(): ApiInterfaces.AuthorityProvider; | ||
onRequest(request: any, cancel: any): void; | ||
prepare(request: any): Promise<any>; | ||
showLoading(): void; | ||
makeSignatureProvider(): ApiInterfaces.SignatureProvider; | ||
@@ -133,0 +137,0 @@ makeAuthorityProvider(): ApiInterfaces.AuthorityProvider; |
@@ -103,2 +103,13 @@ import { SessionError } from './errors'; | ||
} | ||
prepare(request) { | ||
if (this.link.transport.prepare) { | ||
return this.link.transport.prepare(request, this); | ||
} | ||
return Promise.resolve(request); | ||
} | ||
showLoading() { | ||
if (this.link.transport.showLoading) { | ||
return this.link.transport.showLoading(); | ||
} | ||
} | ||
makeSignatureProvider() { | ||
@@ -151,2 +162,13 @@ return this.link.makeSignatureProvider([this.publicKey], this); | ||
} | ||
prepare(request) { | ||
if (this.link.transport.prepare) { | ||
return this.link.transport.prepare(request, this); | ||
} | ||
return Promise.resolve(request); | ||
} | ||
showLoading() { | ||
if (this.link.transport.showLoading) { | ||
return this.link.transport.showLoading(); | ||
} | ||
} | ||
makeSignatureProvider() { | ||
@@ -153,0 +175,0 @@ return this.link.makeSignatureProvider([this.publicKey], this); |
@@ -29,2 +29,6 @@ import { SigningRequest } from 'eosio-signing-request'; | ||
storage?: LinkStorage; | ||
/** Can be implemented to modify request just after it has been created. */ | ||
prepare?(request: SigningRequest, session?: LinkSession): Promise<SigningRequest>; | ||
/** Called immediately when the transaction starts */ | ||
showLoading?(): void; | ||
} |
@@ -96,2 +96,3 @@ import * as esr from 'eosio-signing-request'; | ||
private abiCache; | ||
private pendingAbis; | ||
/** Create a new link instance. */ | ||
@@ -113,3 +114,3 @@ constructor(options: LinkOptions); | ||
*/ | ||
createRequest(args: esr.SigningRequestCreateArguments): Promise<esr.SigningRequest>; | ||
createRequest(args: esr.SigningRequestCreateArguments, transport?: LinkTransport): Promise<esr.SigningRequest>; | ||
/** | ||
@@ -116,0 +117,0 @@ * Send a SigningRequest instance using this link. |
@@ -31,2 +31,3 @@ import * as esr from 'eosio-signing-request'; | ||
this.abiCache = new Map(); | ||
this.pendingAbis = new Map(); | ||
if (typeof options !== 'object') { | ||
@@ -72,3 +73,9 @@ throw new TypeError('Missing options object'); | ||
if (!rv) { | ||
rv = (await this.rpc.get_abi(account)).abi; | ||
let getAbi = this.pendingAbis.get(account); | ||
if (!getAbi) { | ||
getAbi = this.rpc.get_abi(account); | ||
this.pendingAbis.set(account, getAbi); | ||
} | ||
rv = (await getAbi).abi; | ||
this.pendingAbis.delete(account); | ||
if (rv) { | ||
@@ -91,5 +98,6 @@ this.abiCache.set(account, rv); | ||
*/ | ||
async createRequest(args) { | ||
async createRequest(args, transport) { | ||
const t = transport || this.transport; | ||
// generate unique callback url | ||
const request = await esr.SigningRequest.create({ | ||
let request = await esr.SigningRequest.create({ | ||
...args, | ||
@@ -103,2 +111,5 @@ chainId: this.chainId, | ||
}, this.requestOptions); | ||
if (t.prepare) { | ||
request = await t.prepare(request); | ||
} | ||
return request; | ||
@@ -122,3 +133,8 @@ } | ||
const ctx = {}; | ||
const socket = waitForCallback(linkUrl, ctx); | ||
const socket = waitForCallback(linkUrl, ctx).then((data) => { | ||
if (typeof data.rejected === 'string') { | ||
throw new CancelError(`Rejected by wallet: ${data.rejected}`); | ||
} | ||
return data; | ||
}); | ||
const cancel = new Promise((resolve, reject) => { | ||
@@ -147,2 +163,6 @@ t.onRequest(request, (reason) => { | ||
const resolved = await esr.ResolvedSigningRequest.fromPayload(payload, this.requestOptions); | ||
const info = resolved.request.getInfo(); | ||
if (info['fuel_sig']) { | ||
signatures.unshift(info['fuel_sig']); | ||
} | ||
const { serializedTransaction, transaction } = resolved; | ||
@@ -192,3 +212,28 @@ const result = { | ||
const broadcast = options ? options.broadcast !== false : true; | ||
const request = await this.createRequest(args); | ||
// Initialize the loading state of the transport | ||
if (t && t.showLoading) { | ||
t.showLoading(); | ||
} | ||
// eosjs transact compat: upgrade to transaction if args have any header fields | ||
let anyArgs = args; | ||
if (args.actions && | ||
(anyArgs.expiration || | ||
anyArgs.ref_block_num || | ||
anyArgs.ref_block_prefix || | ||
anyArgs.max_net_usage_words || | ||
anyArgs.max_cpu_usage_ms || | ||
anyArgs.delay_sec)) { | ||
args = { | ||
transaction: { | ||
expiration: '1970-01-01T00:00:00', | ||
ref_block_num: 0, | ||
ref_block_prefix: 0, | ||
max_net_usage_words: 0, | ||
max_cpu_usage_ms: 0, | ||
delay_sec: 0, | ||
...anyArgs, | ||
}, | ||
}; | ||
} | ||
const request = await this.createRequest(args, t); | ||
const result = await this.sendRequest(request, t, broadcast); | ||
@@ -195,0 +240,0 @@ return result; |
{ | ||
"name": "anchor-link", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Library for authenticating and signing transactions using the Anchor Link protocol", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -184,2 +184,15 @@ import {SigningRequest} from 'eosio-signing-request' | ||
prepare(request) { | ||
if (this.link.transport.prepare) { | ||
return this.link.transport.prepare(request, this) | ||
} | ||
return Promise.resolve(request) | ||
} | ||
showLoading() { | ||
if (this.link.transport.showLoading) { | ||
return this.link.transport.showLoading() | ||
} | ||
} | ||
public makeSignatureProvider(): ApiInterfaces.SignatureProvider { | ||
@@ -258,2 +271,15 @@ return this.link.makeSignatureProvider([this.publicKey], this) | ||
prepare(request) { | ||
if (this.link.transport.prepare) { | ||
return this.link.transport.prepare(request, this) | ||
} | ||
return Promise.resolve(request) | ||
} | ||
showLoading() { | ||
if (this.link.transport.showLoading) { | ||
return this.link.transport.showLoading() | ||
} | ||
} | ||
public makeSignatureProvider(): ApiInterfaces.SignatureProvider { | ||
@@ -260,0 +286,0 @@ return this.link.makeSignatureProvider([this.publicKey], this) |
@@ -35,2 +35,6 @@ import {SigningRequest} from 'eosio-signing-request' | ||
storage?: LinkStorage | ||
/** Can be implemented to modify request just after it has been created. */ | ||
prepare?(request: SigningRequest, session?: LinkSession): Promise<SigningRequest> | ||
/** Called immediately when the transaction starts */ | ||
showLoading?(): void | ||
} |
@@ -111,2 +111,3 @@ import * as esr from 'eosio-signing-request' | ||
private abiCache = new Map<string, any>() | ||
private pendingAbis = new Map<string, Promise<any>>() | ||
@@ -156,3 +157,9 @@ /** Create a new link instance. */ | ||
if (!rv) { | ||
rv = (await this.rpc.get_abi(account)).abi | ||
let getAbi = this.pendingAbis.get(account) | ||
if (!getAbi) { | ||
getAbi = this.rpc.get_abi(account) | ||
this.pendingAbis.set(account, getAbi) | ||
} | ||
rv = (await getAbi).abi | ||
this.pendingAbis.delete(account) | ||
if (rv) { | ||
@@ -177,5 +184,6 @@ this.abiCache.set(account, rv) | ||
*/ | ||
public async createRequest(args: esr.SigningRequestCreateArguments) { | ||
public async createRequest(args: esr.SigningRequestCreateArguments, transport?: LinkTransport) { | ||
const t = transport || this.transport | ||
// generate unique callback url | ||
const request = await esr.SigningRequest.create( | ||
let request = await esr.SigningRequest.create( | ||
{ | ||
@@ -192,2 +200,5 @@ ...args, | ||
) | ||
if (t.prepare) { | ||
request = await t.prepare(request) | ||
} | ||
return request | ||
@@ -216,3 +227,8 @@ } | ||
const ctx: {cancel?: () => void} = {} | ||
const socket = waitForCallback(linkUrl, ctx) | ||
const socket = waitForCallback(linkUrl, ctx).then((data) => { | ||
if (typeof data.rejected === 'string') { | ||
throw new CancelError(`Rejected by wallet: ${data.rejected}`) | ||
} | ||
return data | ||
}) | ||
const cancel = new Promise<never>((resolve, reject) => { | ||
@@ -243,2 +259,6 @@ t.onRequest(request, (reason) => { | ||
) | ||
const info = resolved.request.getInfo() | ||
if (info['fuel_sig']) { | ||
signatures.unshift(info['fuel_sig']) | ||
} | ||
const {serializedTransaction, transaction} = resolved | ||
@@ -292,3 +312,30 @@ const result: TransactResult = { | ||
const broadcast = options ? options.broadcast !== false : true | ||
const request = await this.createRequest(args) | ||
// Initialize the loading state of the transport | ||
if (t && t.showLoading) { | ||
t.showLoading() | ||
} | ||
// eosjs transact compat: upgrade to transaction if args have any header fields | ||
let anyArgs = args as any | ||
if ( | ||
args.actions && | ||
(anyArgs.expiration || | ||
anyArgs.ref_block_num || | ||
anyArgs.ref_block_prefix || | ||
anyArgs.max_net_usage_words || | ||
anyArgs.max_cpu_usage_ms || | ||
anyArgs.delay_sec) | ||
) { | ||
args = { | ||
transaction: { | ||
expiration: '1970-01-01T00:00:00', | ||
ref_block_num: 0, | ||
ref_block_prefix: 0, | ||
max_net_usage_words: 0, | ||
max_cpu_usage_ms: 0, | ||
delay_sec: 0, | ||
...anyArgs, | ||
}, | ||
} | ||
} | ||
const request = await this.createRequest(args, t) | ||
const result = await this.sendRequest(request, t, broadcast) | ||
@@ -295,0 +342,0 @@ return result |
Sorry, the diff of this file is too big to display
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
2782827
34717