connext
Advanced tools
Comparing version 3.0.11 to 3.0.12
@@ -70,3 +70,5 @@ import { WithdrawalParameters, ChannelManagerChannelDetails, Sync, ThreadState, ThreadStateUpdate, HubConfig } from './types'; | ||
config(): Promise<HubConfig>; | ||
redeem(secret: string): Promise<PurchasePaymentHubResponse>; | ||
redeem(secret: string): Promise<PurchasePaymentHubResponse & { | ||
amount: Payment; | ||
}>; | ||
} | ||
@@ -143,6 +145,6 @@ export declare abstract class IWeb3TxWrapper { | ||
user: string; | ||
contractAddress: string; | ||
hubAddress: Address; | ||
tokenAddress: Address; | ||
ethNetworkId?: string; | ||
contractAddress?: string; | ||
hubAddress?: Address; | ||
tokenAddress?: Address; | ||
tokenName?: string; | ||
@@ -149,0 +151,0 @@ gasMultiple?: number; |
@@ -524,6 +524,6 @@ "use strict"; | ||
return { | ||
contractAddress: config.channelManagerAddress, | ||
hubAddress: config.hubWalletAddress, | ||
tokenAddress: config.tokenAddress, | ||
ethNetworkId: config.ethNetworkId, | ||
contractAddress: config.channelManagerAddress.toLowerCase(), | ||
hubAddress: config.hubWalletAddress.toLowerCase(), | ||
tokenAddress: config.tokenAddress.toLowerCase(), | ||
ethNetworkId: config.ethNetworkId.toLowerCase(), | ||
}; | ||
@@ -638,6 +638,5 @@ } | ||
this.hub = opts.hub || new HubAPIClient(this.opts.user, new networking_1.Networking(this.opts.hubUrl), this.opts.tokenName); | ||
//const hubConfig = await this.hub.config() | ||
//console.log(`Received config from hub: ${JSON.stringify(hubConfig,null,2)}`) | ||
opts.hubAddress = opts.hubAddress || ''; //hubConfig.hubAddress | ||
opts.contractAddress = opts.contractAddress || ''; //hubConfig.contractAddress | ||
opts.user = opts.user.toLowerCase(); | ||
opts.hubAddress = opts.hubAddress.toLowerCase(); | ||
opts.contractAddress = opts.contractAddress.toLowerCase(); | ||
this.validator = new validator_1.Validator(opts.web3, opts.hubAddress); | ||
@@ -787,4 +786,4 @@ this.contract = opts.contract || new ChannelManager(opts.web3, opts.contractAddress, opts.gasMultiple || 1.5); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (state.user != this.opts.user || | ||
state.contractAddress != this.opts.contractAddress) { | ||
if (state.user.toLowerCase() != this.opts.user.toLowerCase() || | ||
state.contractAddress.toLowerCase() != this.opts.contractAddress.toLowerCase()) { | ||
throw new Error(`Refusing to sign channel state update which changes user or contract: ` + | ||
@@ -791,0 +790,0 @@ `expected user: ${this.opts.user}, expected contract: ${this.opts.contractAddress} ` + |
import { AbstractController } from "./AbstractController"; | ||
import { Payment } from "@src/types"; | ||
export declare class RedeemController extends AbstractController { | ||
redeem: (secret: string) => Promise<{ | ||
purchaseId: string; | ||
amount: Payment<string>; | ||
}>; | ||
} |
@@ -22,5 +22,6 @@ "use strict"; | ||
try { | ||
const res = yield this.hub.redeem(secret); | ||
this.connext.syncController.handleHubSync(res.sync); | ||
return { purchaseId: res.purchaseId }; | ||
const { purchaseId, sync, amount } = yield this.hub.redeem(secret); | ||
this.connext.syncController.handleHubSync(sync); | ||
// get amount of purchase | ||
return { purchaseId, amount }; | ||
} | ||
@@ -27,0 +28,0 @@ catch (e) { |
@@ -358,2 +358,5 @@ "use strict"; | ||
return; | ||
// do not invalidate any states without a timeout | ||
if (channel.timeout == 0) | ||
return; | ||
// Wait until all the hub's sync results have been handled before checking | ||
@@ -360,0 +363,0 @@ // if we need to invalidate (the current state might be invalid, but the |
@@ -52,3 +52,5 @@ import { IWeb3TxWrapper } from '../Connext'; | ||
config(): Promise<HubConfig>; | ||
redeem(secret: string): Promise<PurchasePaymentHubResponse>; | ||
redeem(secret: string): Promise<PurchasePaymentHubResponse & { | ||
amount: Payment; | ||
}>; | ||
getChannel(): Promise<ChannelRow>; | ||
@@ -55,0 +57,0 @@ getActiveThreads(): Promise<ThreadState[]>; |
@@ -225,3 +225,7 @@ "use strict"; | ||
}, | ||
}] } | ||
}] }, | ||
amount: { | ||
amountWei: '0', | ||
amountToken: '1', | ||
} | ||
}; | ||
@@ -228,0 +232,0 @@ }); |
@@ -495,3 +495,3 @@ "use strict"; | ||
assertThreadSigner(threadState) { | ||
if (this.utils.recoverSignerFromThreadState(threadState, threadState.sigA) !== threadState.sender) { | ||
if (this.utils.recoverSignerFromThreadState(threadState, threadState.sigA) !== threadState.sender.toLowerCase()) { | ||
throw new Error(`Thread state is not correctly signed. threadState: ${JSON.stringify(threadState)}`); | ||
@@ -498,0 +498,0 @@ } |
{ | ||
"name": "connext", | ||
"description": "Shared code between wallet and hub", | ||
"version": "3.0.11", | ||
"version": "3.0.12", | ||
"main": "dist", | ||
@@ -6,0 +6,0 @@ "devDependencies": { |
@@ -101,3 +101,3 @@ import { WithdrawalParameters, ChannelManagerChannelDetails, Sync, ThreadState, addSigToThreadState, ThreadStateUpdate, channelUpdateToUpdateRequest, ThreadHistoryItem, HubConfig, SyncResult } from './types' | ||
config(): Promise<HubConfig> | ||
redeem(secret: string): Promise<PurchasePaymentHubResponse> | ||
redeem(secret: string): Promise<PurchasePaymentHubResponse & { amount: Payment }> | ||
} | ||
@@ -302,3 +302,3 @@ | ||
async redeem(secret: string): Promise<PurchasePaymentHubResponse> { | ||
async redeem(secret: string): Promise<PurchasePaymentHubResponse & { amount: Payment}> { | ||
try { | ||
@@ -760,6 +760,6 @@ const response = await this.networking.post( | ||
user: string | ||
contractAddress: string | ||
hubAddress: Address | ||
tokenAddress: Address | ||
ethNetworkId?: string | ||
contractAddress?: string | ||
hubAddress?: Address | ||
tokenAddress?: Address | ||
tokenName?: string | ||
@@ -784,6 +784,6 @@ gasMultiple?: number | ||
return { | ||
contractAddress: config.channelManagerAddress, | ||
hubAddress: config.hubWalletAddress, | ||
tokenAddress: config.tokenAddress, | ||
ethNetworkId: config.ethNetworkId, | ||
contractAddress: config.channelManagerAddress.toLowerCase(), | ||
hubAddress: config.hubWalletAddress.toLowerCase(), | ||
tokenAddress: config.tokenAddress.toLowerCase(), | ||
ethNetworkId: config.ethNetworkId.toLowerCase(), | ||
} | ||
@@ -916,8 +916,6 @@ } | ||
//const hubConfig = await this.hub.config() | ||
//console.log(`Received config from hub: ${JSON.stringify(hubConfig,null,2)}`) | ||
opts.user = opts.user.toLowerCase() | ||
opts.hubAddress = opts.hubAddress.toLowerCase() | ||
opts.contractAddress = opts.contractAddress.toLowerCase() | ||
opts.hubAddress = opts.hubAddress || ''//hubConfig.hubAddress | ||
opts.contractAddress = opts.contractAddress || ''//hubConfig.contractAddress | ||
this.validator = new Validator(opts.web3, opts.hubAddress) | ||
@@ -1074,4 +1072,4 @@ this.contract = opts.contract || new ChannelManager(opts.web3, opts.contractAddress, opts.gasMultiple || 1.5) | ||
if ( | ||
state.user != this.opts.user || | ||
state.contractAddress != this.opts.contractAddress | ||
state.user.toLowerCase() != this.opts.user.toLowerCase() || | ||
state.contractAddress.toLowerCase()!= (this.opts.contractAddress as any).toLowerCase() | ||
) { | ||
@@ -1078,0 +1076,0 @@ throw new Error( |
import { AbstractController } from "./AbstractController"; | ||
import Web3 = require('web3') | ||
import { UpdateRequest, PaymentArgs, Payment } from "@src/types"; | ||
export class RedeemController extends AbstractController { | ||
public redeem = async (secret: string): Promise<{ purchaseId: string }> => { | ||
public redeem = async (secret: string): Promise<{ purchaseId: string, amount: Payment }> => { | ||
// check that the secret was generated as a hex | ||
@@ -12,5 +13,6 @@ if (!Web3.utils.isHex(secret)) { | ||
try { | ||
const res = await this.hub.redeem(secret) | ||
this.connext.syncController.handleHubSync(res.sync) | ||
return { purchaseId: res.purchaseId } | ||
const { purchaseId, sync, amount } = await this.hub.redeem(secret) | ||
this.connext.syncController.handleHubSync(sync) | ||
// get amount of purchase | ||
return { purchaseId, amount } | ||
} catch (e) { | ||
@@ -17,0 +19,0 @@ throw new Error(`Error redeeming payment with secret: ${secret}. ` + e.message) |
@@ -417,2 +417,6 @@ import { assertUnreachable } from '../lib/utils' | ||
return | ||
// do not invalidate any states without a timeout | ||
if (channel.timeout == 0) | ||
return | ||
@@ -419,0 +423,0 @@ // Wait until all the hub's sync results have been handled before checking |
@@ -192,3 +192,3 @@ import { mkHash, getWithdrawalArgs, getExchangeArgs } from '.' | ||
async redeem(secret: string): Promise<PurchasePaymentHubResponse> { | ||
async redeem(secret: string): Promise<PurchasePaymentHubResponse & { amount: Payment }> { | ||
// NOTE: by default assumes this is redeemers first payment | ||
@@ -213,3 +213,7 @@ // if this is not what you are testing against, must use | ||
}, | ||
}]} | ||
}]}, | ||
amount: { | ||
amountWei: '0', | ||
amountToken: '1', | ||
} | ||
} | ||
@@ -216,0 +220,0 @@ } |
@@ -632,3 +632,3 @@ import { subOrZero, objMap } from './StateGenerator' | ||
public assertThreadSigner(threadState: ThreadState): void { | ||
if (this.utils.recoverSignerFromThreadState(threadState, threadState.sigA) !== threadState.sender) { | ||
if (this.utils.recoverSignerFromThreadState(threadState, threadState.sigA) !== threadState.sender.toLowerCase()) { | ||
throw new Error(`Thread state is not correctly signed. threadState: ${JSON.stringify(threadState)}`) | ||
@@ -635,0 +635,0 @@ } |
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
26975
1438181
312