@nimiq/fastspot-api
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -8,7 +8,15 @@ import { RequestAsset, SwapAsset, Estimate, PreSwap, ContractWithEstimate, Swap, Limits, AssetList } from './types'; | ||
export declare function confirmSwap(swap: PreSwap, redeem: { | ||
asset: SwapAsset; | ||
asset: SwapAsset.NIM | SwapAsset.BTC; | ||
address: string; | ||
} | { | ||
asset: SwapAsset.EUR; | ||
kty: string; | ||
crv: string; | ||
x: string; | ||
y?: string; | ||
}, refund: { | ||
asset: SwapAsset; | ||
asset: SwapAsset.NIM | SwapAsset.BTC; | ||
address: string; | ||
} | { | ||
asset: SwapAsset.EUR; | ||
}): Promise<Swap>; | ||
@@ -15,0 +23,0 @@ export declare function getSwap(id: string): Promise<PreSwap | Swap>; |
@@ -0,1 +1,2 @@ | ||
import { SwapAsset, } from './types'; | ||
import { validateRequestPairs, convertFromData, convertToData, convertContract, convertSwap, convertLimits, coinsToUnits, } from './helpers'; | ||
@@ -58,4 +59,11 @@ let API_URL; | ||
confirm: true, | ||
beneficiary: { [redeem.asset]: redeem.address }, | ||
refund: { [refund.asset]: refund.address }, | ||
beneficiary: redeem.asset === SwapAsset.EUR | ||
? { [redeem.asset]: { | ||
kty: redeem.kty, | ||
crv: redeem.crv, | ||
x: redeem.x, | ||
...(redeem.y ? { y: redeem.y } : {}), | ||
} } | ||
: { [redeem.asset]: redeem.address }, | ||
refund: { [refund.asset]: 'address' in refund ? refund.address : '' }, | ||
}); | ||
@@ -62,0 +70,0 @@ return convertSwap(result); |
@@ -14,3 +14,3 @@ import { SwapAsset, } from './types'; | ||
break; | ||
default: throw new Error('Invalid asset'); | ||
default: throw new Error(`Invalid asset ${asset}`); | ||
} | ||
@@ -42,6 +42,30 @@ const parts = value.toString().split('.'); | ||
export function convertContract(contract) { | ||
let htlc; | ||
switch (contract.asset) { | ||
case SwapAsset.NIM: | ||
htlc = { | ||
address: contract.intermediary.address, | ||
timeoutBlock: contract.intermediary.timeoutBlock, | ||
data: contract.intermediary.data, | ||
}; | ||
break; | ||
case SwapAsset.BTC: | ||
htlc = { | ||
address: contract.intermediary.p2wsh, | ||
script: contract.intermediary.scriptBytes, | ||
}; | ||
break; | ||
case SwapAsset.EUR: | ||
htlc = { | ||
address: contract.intermediary.contractId || contract.id, | ||
}; | ||
break; | ||
default: throw new Error(`Invalid asset ${contract.asset}`); | ||
} | ||
return { | ||
asset: contract.asset, | ||
refundAddress: contract.refund.address, | ||
redeemAddress: contract.recipient.address, | ||
redeemAddress: contract.asset === SwapAsset.EUR | ||
? JSON.stringify(contract.recipient) | ||
: contract.recipient.address, | ||
amount: coinsToUnits(contract.asset, contract.amount), | ||
@@ -51,11 +75,3 @@ timeout: contract.timeout, | ||
status: contract.status, | ||
...(contract.asset === SwapAsset.NIM ? { | ||
htlc: contract.intermediary, | ||
} : {}), | ||
...(contract.asset === SwapAsset.BTC ? { | ||
htlc: { | ||
address: contract.intermediary.p2wsh, | ||
script: contract.intermediary.scriptBytes, | ||
}, | ||
} : {}), | ||
htlc, | ||
}; | ||
@@ -62,0 +78,0 @@ } |
@@ -50,3 +50,8 @@ export declare enum SwapAsset { | ||
}; | ||
recipient: { | ||
recipient: T extends SwapAsset.EUR ? { | ||
kty: string; | ||
crv: string; | ||
x: string; | ||
y?: string; | ||
} : { | ||
address: string; | ||
@@ -67,2 +72,4 @@ }; | ||
scriptBytes: string; | ||
} : T extends SwapAsset.EUR ? { | ||
contractId?: string; | ||
} : never; | ||
@@ -136,2 +143,6 @@ }; | ||
}; | ||
export declare type EurHtlcDetails = { | ||
address: string; | ||
}; | ||
export declare type HtlcDetails = NimHtlcDetails | BtcHtlcDetails | EurHtlcDetails; | ||
export declare type Contract<T extends SwapAsset> = { | ||
@@ -145,3 +156,3 @@ asset: T; | ||
status: string; | ||
htlc: T extends SwapAsset.NIM ? NimHtlcDetails : T extends SwapAsset.BTC ? BtcHtlcDetails : never; | ||
htlc: T extends SwapAsset.NIM ? NimHtlcDetails : T extends SwapAsset.BTC ? BtcHtlcDetails : T extends SwapAsset.EUR ? EurHtlcDetails : never; | ||
}; | ||
@@ -148,0 +159,0 @@ export declare type ContractWithEstimate<T extends SwapAsset> = Estimate & { |
{ | ||
"name": "@nimiq/fastspot-api", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Typescript library to interact with the Fastspot API", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:nimiq/fastspot-api.git", |
27973
481