mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-05 16:58:01 +00:00
amendment-xls34d
add transfer rate Update definitions.json update test error text update validation error fix undefined validation switch claim signing order, update claim object update workflow docker tests (paychan + escrow) add ic gateway (test) add faucet update sdk fixup git-workflow
This commit is contained in:
@@ -11,6 +11,7 @@ import { STObject } from './types/st-object'
|
||||
import { JsonObject } from './types/serialized-type'
|
||||
import { Buffer } from 'buffer/'
|
||||
import * as bigInt from 'big-integer'
|
||||
import { Amount } from './types/amount'
|
||||
|
||||
/**
|
||||
* Construct a BinaryParser
|
||||
@@ -93,9 +94,9 @@ function signingData(
|
||||
/**
|
||||
* Interface describing fields required for a Claim
|
||||
*/
|
||||
interface ClaimObject extends JsonObject {
|
||||
interface ClaimObject {
|
||||
channel: string
|
||||
amount: string | number
|
||||
amount: Amount
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,13 +106,19 @@ interface ClaimObject extends JsonObject {
|
||||
* @returns the serialized object with appropriate prefix
|
||||
*/
|
||||
function signingClaimData(claim: ClaimObject): Buffer {
|
||||
const num = bigInt(String(claim.amount))
|
||||
const prefix = HashPrefix.paymentChannelClaim
|
||||
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
||||
const amount = coreTypes.UInt64.from(num).toBytes()
|
||||
|
||||
if (typeof claim.amount === 'object') {
|
||||
const amount = coreTypes.Amount.from(claim.amount).toBytes()
|
||||
const bytesList = new BytesList()
|
||||
bytesList.put(prefix)
|
||||
bytesList.put(channel)
|
||||
bytesList.put(amount)
|
||||
return bytesList.toBytes()
|
||||
}
|
||||
const num = bigInt(String(claim.amount))
|
||||
const bytesList = new BytesList()
|
||||
|
||||
const amount = coreTypes.UInt64.from(num).toBytes()
|
||||
bytesList.put(prefix)
|
||||
bytesList.put(channel)
|
||||
bytesList.put(amount)
|
||||
|
||||
@@ -761,6 +761,16 @@
|
||||
"type": "UInt32"
|
||||
}
|
||||
],
|
||||
[
|
||||
"LockCount",
|
||||
{
|
||||
"nth": 47,
|
||||
"isVLEncoded": false,
|
||||
"isSerialized": true,
|
||||
"isSigningField": true,
|
||||
"type": "UInt32"
|
||||
}
|
||||
],
|
||||
[
|
||||
"IndexNext",
|
||||
{
|
||||
@@ -1421,6 +1431,16 @@
|
||||
"type": "Amount"
|
||||
}
|
||||
],
|
||||
[
|
||||
"LockedBalance",
|
||||
{
|
||||
"nth": 21,
|
||||
"isVLEncoded": false,
|
||||
"isSerialized": true,
|
||||
"isSigningField": true,
|
||||
"type": "Amount"
|
||||
}
|
||||
],
|
||||
[
|
||||
"PublicKey",
|
||||
{
|
||||
@@ -2298,7 +2318,8 @@
|
||||
"tecCANT_ACCEPT_OWN_NFTOKEN_OFFER": 158,
|
||||
"tecINSUFFICIENT_FUNDS": 159,
|
||||
"tecOBJECT_NOT_FOUND": 160,
|
||||
"tecINSUFFICIENT_PAYMENT": 161
|
||||
"tecINSUFFICIENT_PAYMENT": 161,
|
||||
"tecPRECISION_LOSS": 162
|
||||
},
|
||||
"TRANSACTION_TYPES": {
|
||||
"Invalid": -1,
|
||||
|
||||
@@ -120,7 +120,7 @@ describe('Signing data', function () {
|
||||
].join(''),
|
||||
)
|
||||
})
|
||||
test('can create claim blob', function () {
|
||||
test('can create native claim blob', function () {
|
||||
const channel =
|
||||
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
|
||||
const amount = '1000'
|
||||
@@ -137,4 +137,27 @@ describe('Signing data', function () {
|
||||
].join(''),
|
||||
)
|
||||
})
|
||||
test('can create ic claim blob', function () {
|
||||
const channel =
|
||||
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
|
||||
const amount = {
|
||||
issuer: 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN',
|
||||
currency: 'USD',
|
||||
value: '10',
|
||||
}
|
||||
const json = { channel, amount }
|
||||
const actual = encodeForSigningClaim(json)
|
||||
expect(actual).toBe(
|
||||
[
|
||||
// hash prefix
|
||||
'434C4D00',
|
||||
// channel ID
|
||||
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1',
|
||||
// amount as a uint64
|
||||
'D4C38D7EA4C680000000000000000000000000005553440000000000C0A5ABEF',
|
||||
// amount as a uint64
|
||||
'242802EFED4B041E8F2D4A8CC86AE3D1',
|
||||
].join(''),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user