mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
update definitions
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
"UInt512": 23,
|
||||
"Issue": 24,
|
||||
"XChainBridge": 25,
|
||||
"XChainAttestationBatch": 26,
|
||||
"Transaction": 10001,
|
||||
"LedgerEntry": 10002,
|
||||
"Validation": 10003,
|
||||
@@ -1967,16 +1966,6 @@
|
||||
"type": "XChainBridge"
|
||||
}
|
||||
],
|
||||
[
|
||||
"XChainAttestationBatch",
|
||||
{
|
||||
"nth": 1,
|
||||
"isVLEncoded": false,
|
||||
"isSerialized": true,
|
||||
"isSigningField": true,
|
||||
"type": "XChainAttestationBatch"
|
||||
}
|
||||
],
|
||||
[
|
||||
"TransactionMetaData",
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@ import { UInt32 } from './uint-32'
|
||||
import { UInt64 } from './uint-64'
|
||||
import { UInt8 } from './uint-8'
|
||||
import { Vector256 } from './vector-256'
|
||||
import { XChainAttestationBatch } from './xchain-attestation-batch'
|
||||
import { XChainBridge } from './xchain-bridge'
|
||||
|
||||
const coreTypes = {
|
||||
@@ -40,7 +39,6 @@ const coreTypes = {
|
||||
UInt32,
|
||||
UInt64,
|
||||
Vector256,
|
||||
XChainAttestationBatch,
|
||||
XChainBridge,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
import { BinaryParser } from '../serdes/binary-parser'
|
||||
|
||||
import { JsonObject, SerializedType } from './serialized-type'
|
||||
import { Buffer } from 'buffer/'
|
||||
import { XChainBridge, XChainBridgeObject } from './xchain-bridge'
|
||||
import { STArray } from './st-array'
|
||||
|
||||
/**
|
||||
* Interface for JSON objects that represent cross-chain attestations
|
||||
*/
|
||||
interface XChainAttestationBatchObject extends JsonObject {
|
||||
XChainBridge: XChainBridgeObject
|
||||
XChainClaimAttestationBatch: JsonObject[]
|
||||
XChainCreateAccountAttestationBatch: JsonObject[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for XChainAttestationBatchObject
|
||||
*/
|
||||
function isXChainAttestationBatchObject(
|
||||
arg,
|
||||
): arg is XChainAttestationBatchObject {
|
||||
const keys = Object.keys(arg).sort()
|
||||
return (
|
||||
keys.length === 3 &&
|
||||
keys[0] === 'XChainBridge' &&
|
||||
keys[1] === 'XChainClaimAttestationBatch' &&
|
||||
keys[2] === 'XChainCreateAccountAttestationBatch'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for serializing/deserializing XChainAttestationBatchs
|
||||
*/
|
||||
class XChainAttestationBatch extends SerializedType {
|
||||
static readonly ZERO_XCHAIN_ATTESTATION_BATCH: XChainAttestationBatch =
|
||||
new XChainAttestationBatch(
|
||||
Buffer.concat([
|
||||
Buffer.from([0x14]),
|
||||
Buffer.alloc(40),
|
||||
Buffer.from([0x14]),
|
||||
Buffer.alloc(40),
|
||||
]),
|
||||
)
|
||||
|
||||
static readonly TYPE_ORDER: { name: string; type: typeof SerializedType }[] =
|
||||
[
|
||||
{ name: 'XChainBridge', type: XChainBridge },
|
||||
{ name: 'XChainClaimAttestationBatch', type: STArray },
|
||||
{ name: 'XChainCreateAccountAttestationBatch', type: STArray },
|
||||
]
|
||||
|
||||
constructor(bytes: Buffer) {
|
||||
super(bytes ?? XChainAttestationBatch.ZERO_XCHAIN_ATTESTATION_BATCH.bytes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a cross-chain bridge from a JSON
|
||||
*
|
||||
* @param value XChainAttestationBatch or JSON to parse into a XChainAttestationBatch
|
||||
* @returns A XChainAttestationBatch object
|
||||
*/
|
||||
static from<T extends XChainAttestationBatch | XChainAttestationBatchObject>(
|
||||
value: T,
|
||||
): XChainAttestationBatch {
|
||||
if (value instanceof XChainAttestationBatch) {
|
||||
return value
|
||||
}
|
||||
|
||||
if (isXChainAttestationBatchObject(value)) {
|
||||
const bytes: Array<Buffer> = []
|
||||
this.TYPE_ORDER.forEach((item) => {
|
||||
const { name, type } = item
|
||||
const object = type.from(value[name])
|
||||
bytes.push(object.toBytes())
|
||||
})
|
||||
return new XChainAttestationBatch(Buffer.concat(bytes))
|
||||
}
|
||||
|
||||
throw new Error('Invalid type to construct a XChainAttestationBatch')
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a XChainAttestationBatch from a BinaryParser
|
||||
*
|
||||
* @param parser BinaryParser to read the XChainAttestationBatch from
|
||||
* @returns A XChainAttestationBatch object
|
||||
*/
|
||||
static fromParser(parser: BinaryParser): XChainAttestationBatch {
|
||||
const bytes: Array<Buffer> = []
|
||||
|
||||
this.TYPE_ORDER.forEach((item) => {
|
||||
const { type } = item
|
||||
const object = type.fromParser(parser)
|
||||
bytes.push(object.toBytes())
|
||||
})
|
||||
|
||||
return new XChainAttestationBatch(Buffer.concat(bytes))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JSON representation of this XChainAttestationBatch
|
||||
*
|
||||
* @returns the JSON interpretation of this.bytes
|
||||
*/
|
||||
toJSON(): XChainAttestationBatchObject {
|
||||
const parser = new BinaryParser(this.toString())
|
||||
const json = {}
|
||||
XChainAttestationBatch.TYPE_ORDER.forEach((item) => {
|
||||
const { name, type } = item
|
||||
const object = type.fromParser(parser).toJSON()
|
||||
json[name] = object
|
||||
})
|
||||
return json as XChainAttestationBatchObject
|
||||
}
|
||||
}
|
||||
|
||||
export { XChainAttestationBatch, XChainAttestationBatchObject }
|
||||
Reference in New Issue
Block a user