Compare commits

..

41 Commits

Author SHA1 Message Date
Denis Angell
015f92d9e7 Merge branch 'transia-hooks' into denis-uritoken 2023-06-14 23:10:10 +00:00
Denis Angell
10ea540984 remove unused 2023-06-14 23:09:20 +00:00
Denis Angell
a47d7e34a7 Merge branch 'transia-hooks' into denis-uritoken 2023-06-14 23:02:31 +00:00
Denis Angell
77e475ae2d fix export 2023-06-14 23:01:26 +00:00
Denis Angell
925eee464c Merge branch 'transia-hooks' into denis-uritoken 2023-06-14 22:58:03 +00:00
Denis Angell
3e929eff56 lint 2023-06-14 22:56:35 +00:00
Denis Angell
e1a3594ff3 Merge branch 'transia-hooks' into denis-uritoken 2023-06-14 22:42:07 +00:00
Denis Angell
f570b89d71 update TransactionMetadata 2023-06-14 22:29:21 +00:00
Denis Angell
0b4cd01f94 rename Transactors
revert transactors
2023-06-14 19:30:37 +00:00
Denis Angell
93b15ee9f6 add transactions 2023-06-14 19:30:33 +00:00
Denis Angell
29b718b52e Publish
- @transia/ripple-binary-codec@1.4.6-alpha.1
 - @transia/xrpl@2.7.3-alpha.1
2023-05-29 23:20:48 +00:00
Denis Angell
b127b2e616 add import tx 2023-05-29 23:18:11 +00:00
Denis Angell
f85f35cb4d update definitions.json 2023-05-29 23:14:51 +00:00
Denis Angell
f292d9e716 Publish
- @transia/ripple-address-codec@4.2.8-alpha.0
 - @transia/ripple-binary-codec@1.4.6-alpha.0
 - @transia/ripple-keypairs@1.1.8-alpha.0
 - @transia/xrpl@2.7.3-alpha.0
2023-05-29 17:02:01 +00:00
Denis Angell
c167b3a22d reset version 2023-05-29 17:01:12 +00:00
Denis Angell
baae6b9a9a Publish
- @transia/xrpl@2.7.2-alpha.0
2023-05-29 16:50:36 +00:00
Denis Angell
25ab1d08fc revert version 2023-05-29 16:48:55 +00:00
Denis Angell
9a0e2aa8f8 bump version 2023-05-29 16:47:13 +00:00
Denis Angell
8779ef41d7 Publish
- @transia/ripple-address-codec@4.2.7-alpha.0
 - @transia/ripple-binary-codec@1.4.5-alpha.0
 - @transia/ripple-keypairs@1.1.7-alpha.0
 - @transia/xrpl@2.7.1-alpha.0
2023-05-29 16:42:09 +00:00
Denis Angell
606babe01a add hook executions 2023-05-17 21:42:07 +00:00
Denis Angell
4fbd5383c4 missing fields 2023-05-17 21:32:28 +00:00
Denis Angell
a97c7bb21b rename repo 2023-05-17 21:32:17 +00:00
Denis Angell
c00e36bf50 rename packages 2023-05-17 06:35:54 +00:00
Denis Angell
c24197f202 add fields 2023-05-17 06:28:14 +00:00
Denis Angell
d50417acbc update package.json for @transia 2023-03-28 20:36:54 +00:00
Denis Angell
f8b7c6ab15 Merge branch 'beta' into hooks 2023-03-28 20:33:17 +00:00
Denis Angell
678c5f5fda update definitions
update definitions

update definitions
2023-03-28 20:24:22 +00:00
Denis Angell
6264c5f3f7 update tests 2023-03-28 19:30:48 +00:00
Denis Angell
f80d6e1747 update hook on calcaulator 2023-03-27 21:47:36 +00:00
Denis Angell
df1897be10 fixup unit test 2023-03-27 19:04:31 +00:00
Denis Angell
bcbba483c5 fix error 2023-03-27 18:58:49 +00:00
Denis Angell
0560a5867f lint 2023-03-27 18:57:11 +00:00
Denis Angell
f19466cabe export transaction type map from definitions 2023-03-27 18:31:22 +00:00
Denis Angell
f6a90a31c4 remove network id 2023-03-27 18:30:52 +00:00
Denis Angell
818d12d68c update definitions 2023-03-27 17:45:08 +00:00
Denis Angell
277288f1e9 remove sugar export 2023-03-27 17:17:56 +00:00
Denis Angell
ee59c64b65 ledger entry objects 2023-03-27 17:14:43 +00:00
Denis Angell
d36349e410 add invoke tx 2023-03-27 17:14:33 +00:00
Denis Angell
2e38cf54a8 update hookon transaction types 2023-03-27 17:14:15 +00:00
Denis Angell
3a2a0918f8 update hook
update hook

add test and validation

add estimate fee func

fix estimated fee error

add hook utils
2023-03-27 17:10:35 +00:00
Denis Angell
6d6b5a5863 feature Hooks
update definitions

add network id to base transaction

add set hook

update required

update definitions

make network id required
2023-03-27 17:10:26 +00:00
52 changed files with 2773 additions and 2497 deletions

4430
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -13,10 +13,10 @@
"update:confirm": "npx npm-check-updates --configFileName .ncurc.json -u" "update:confirm": "npx npm-check-updates --configFileName .ncurc.json -u"
}, },
"dependencies": { "dependencies": {
"ripple-address-codec": "file:packages/ripple-address-codec", "@transia/ripple-address-codec": "file:packages/ripple-address-codec",
"ripple-binary-codec": "file:packages/ripple-binary-codec", "@transia/ripple-binary-codec": "file:packages/ripple-binary-codec",
"ripple-keypairs": "file:packages/ripple-keypairs", "@transia/ripple-keypairs": "file:packages/ripple-keypairs",
"xrpl": "file:packages/xrpl" "@transia/xrpl": "file:packages/xrpl"
}, },
"devDependencies": { "devDependencies": {
"@types/brorand": "^1.0.30", "@types/brorand": "^1.0.30",

View File

@@ -1,12 +1,12 @@
{ {
"name": "ripple-address-codec", "name": "ripple-address-codec",
"version": "4.2.6-alpha.0", "version": "4.2.8-alpha.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ripple-address-codec", "name": "ripple-address-codec",
"version": "4.2.6-alpha.0", "version": "4.2.8-alpha.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"base-x": "^3.0.9", "base-x": "^3.0.9",

View File

@@ -1,9 +1,6 @@
{ {
"name": "@transia/ripple-address-codec", "name": "@transia/ripple-address-codec",
"publishConfig": { "version": "4.2.8-alpha.0",
"access": "public"
},
"version": "4.2.6-alpha.0",
"description": "encodes/decodes base58 encoded XRP Ledger identifiers", "description": "encodes/decodes base58 encoded XRP Ledger identifiers",
"files": [ "files": [
"dist/*", "dist/*",

View File

@@ -1,9 +1,6 @@
{ {
"name": "@transia/ripple-binary-codec", "name": "@transia/ripple-binary-codec",
"publishConfig": { "version": "1.4.6-alpha.1",
"access": "public"
},
"version": "1.4.4-alpha.0",
"description": "XRP Ledger binary codec", "description": "XRP Ledger binary codec",
"files": [ "files": [
"dist/*", "dist/*",
@@ -15,12 +12,12 @@
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"@transia/ripple-address-codec": "^4.2.8-alpha.0",
"assert": "^2.0.0", "assert": "^2.0.0",
"big-integer": "^1.6.48", "big-integer": "^1.6.48",
"buffer": "5.6.0", "buffer": "5.6.0",
"create-hash": "^1.2.0", "create-hash": "^1.2.0",
"decimal.js": "^10.2.0", "decimal.js": "^10.2.0"
"ripple-address-codec": "^4.2.5"
}, },
"scripts": { "scripts": {
"build": "tsc -b && copyfiles ./src/enums/definitions.json ./dist/enums/", "build": "tsc -b && copyfiles ./src/enums/definitions.json ./dist/enums/",

View File

@@ -786,6 +786,26 @@
"type": "UInt32" "type": "UInt32"
} }
], ],
[
"FirstNFTokenSequence",
{
"nth": 50,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[
"ImportSequence",
{
"nth": 97,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[ [
"IndexNext", "IndexNext",
{ {
@@ -1496,6 +1516,36 @@
"type": "Amount" "type": "Amount"
} }
], ],
[
"BaseFeeDrops",
{
"nth": 22,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"ReserveBaseDrops",
{
"nth": 23,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"ReserveIncrementDrops",
{
"nth": 24,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[ [
"PublicKey", "PublicKey",
{ {
@@ -2275,6 +2325,8 @@
"telREQUIRES_NETWORK_ID": -385, "telREQUIRES_NETWORK_ID": -385,
"telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384, "telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384,
"telNON_LOCAL_EMITTED_TXN": -383, "telNON_LOCAL_EMITTED_TXN": -383,
"telIMPORT_VL_KEY_NOT_RECOGNISED": -382,
"telCAN_NOT_QUEUE_IMPORT": -381,
"temMALFORMED": -299, "temMALFORMED": -299,
"temBAD_AMOUNT": -298, "temBAD_AMOUNT": -298,
@@ -2346,6 +2398,7 @@
"tefTOO_BIG": -181, "tefTOO_BIG": -181,
"tefNO_TICKET": -180, "tefNO_TICKET": -180,
"tefNFTOKEN_IS_NOT_TRANSFERABLE": -179, "tefNFTOKEN_IS_NOT_TRANSFERABLE": -179,
"tefPAST_IMPORT_SEQ": -178,
"terRETRY": -99, "terRETRY": -99,
"terFUNDS_SPENT": -98, "terFUNDS_SPENT": -98,
@@ -2435,7 +2488,8 @@
"tecXCHAIN_ACCOUNT_CREATE_TOO_MANY": 183, "tecXCHAIN_ACCOUNT_CREATE_TOO_MANY": 183,
"tecXCHAIN_PAYMENT_FAILED": 184, "tecXCHAIN_PAYMENT_FAILED": 184,
"tecXCHAIN_SELF_COMMIT": 185, "tecXCHAIN_SELF_COMMIT": 185,
"tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 186 "tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 186,
"tecLAST_POSSIBLE_ENTRY": 255
}, },
"TRANSACTION_TYPES": { "TRANSACTION_TYPES": {
"Invalid": -1, "Invalid": -1,
@@ -2472,6 +2526,7 @@
"URITokenBuy": 47, "URITokenBuy": 47,
"URITokenCreateSellOffer": 48, "URITokenCreateSellOffer": 48,
"URITokenCancelSellOffer": 49, "URITokenCancelSellOffer": 49,
"Import": 97,
"Invoke": 99, "Invoke": 99,
"EnableAmendment": 100, "EnableAmendment": 100,
"SetFee": 101, "SetFee": 101,

View File

@@ -3,7 +3,7 @@ import {
encodeAccountID, encodeAccountID,
isValidXAddress, isValidXAddress,
xAddressToClassicAddress, xAddressToClassicAddress,
} from 'ripple-address-codec' } from '@transia/ripple-address-codec'
import { Hash160 } from './hash-160' import { Hash160 } from './hash-160'
import { Buffer } from 'buffer/' import { Buffer } from 'buffer/'

View File

@@ -5,7 +5,10 @@ import {
XrplDefinitionsBase, XrplDefinitionsBase,
} from '../enums' } from '../enums'
import { SerializedType, JsonObject } from './serialized-type' import { SerializedType, JsonObject } from './serialized-type'
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec' import {
xAddressToClassicAddress,
isValidXAddress,
} from '@transia/ripple-address-codec'
import { BinaryParser } from '../serdes/binary-parser' import { BinaryParser } from '../serdes/binary-parser'
import { BinarySerializer, BytesList } from '../serdes/binary-serializer' import { BinarySerializer, BytesList } from '../serdes/binary-serializer'
import { Buffer } from 'buffer/' import { Buffer } from 'buffer/'

View File

@@ -1,7 +1,7 @@
const { coreTypes } = require('../src/types') const { coreTypes } = require('../src/types')
const Decimal = require('decimal.js') const Decimal = require('decimal.js')
const { encodeAccountID } = require('ripple-address-codec') const { encodeAccountID } = require('@transia/ripple-address-codec')
const { binary } = require('../src/coretypes') const { binary } = require('../src/coretypes')
const { Amount, Hash160 } = coreTypes const { Amount, Hash160 } = coreTypes
const { makeParser, readJSON } = binary const { makeParser, readJSON } = binary

View File

@@ -1,9 +1,6 @@
{ {
"name": "@transia/ripple-keypairs", "name": "@transia/ripple-keypairs",
"publishConfig": { "version": "1.1.8-alpha.0",
"access": "public"
},
"version": "1.1.6-alpha.0",
"description": "Cryptographic key pairs for the XRP Ledger", "description": "Cryptographic key pairs for the XRP Ledger",
"scripts": { "scripts": {
"build": "tsc -b", "build": "tsc -b",
@@ -20,11 +17,11 @@
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"@transia/ripple-address-codec": "^4.2.8-alpha.0",
"bn.js": "^5.1.1", "bn.js": "^5.1.1",
"brorand": "^1.0.5", "brorand": "^1.0.5",
"elliptic": "^6.5.4", "elliptic": "^6.5.4",
"hash.js": "^1.0.3", "hash.js": "^1.0.3"
"ripple-address-codec": "^4.2.5"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -3,7 +3,7 @@ import brorand = require('brorand')
import * as hashjs from 'hash.js' import * as hashjs from 'hash.js'
import * as elliptic from 'elliptic' import * as elliptic from 'elliptic'
import * as addressCodec from 'ripple-address-codec' import * as addressCodec from '@transia/ripple-address-codec'
import { derivePrivateKey, accountPublicFromPublicGenerator } from './secp256k1' import { derivePrivateKey, accountPublicFromPublicGenerator } from './secp256k1'
import * as utils from './utils' import * as utils from './utils'

View File

@@ -1,5 +1,5 @@
import assert from 'assert' import assert from 'assert'
import * as api from 'ripple-address-codec' import * as api from '@transia/ripple-address-codec'
function toHex(bytes) { function toHex(bytes) {
return Buffer.from(bytes).toString('hex').toUpperCase() return Buffer.from(bytes).toString('hex').toUpperCase()

View File

@@ -1,5 +1,5 @@
import assert from 'assert' import assert from 'assert'
import * as api from 'ripple-address-codec' import * as api from '@transia/ripple-address-codec'
function toHex(bytes: Buffer) { function toHex(bytes: Buffer) {
return Buffer.from(bytes).toString('hex').toUpperCase() return Buffer.from(bytes).toString('hex').toUpperCase()

View File

@@ -1,9 +1,6 @@
{ {
"name": "@transia/xrpl", "name": "@transia/xrpl",
"publishConfig": { "version": "2.7.3-alpha.1",
"access": "public"
},
"version": "2.7.1-alpha.0",
"license": "ISC", "license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser", "description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [ "files": [
@@ -25,14 +22,14 @@
"https-proxy-agent": false "https-proxy-agent": false
}, },
"dependencies": { "dependencies": {
"@transia/ripple-address-codec": "^4.2.8-alpha.0",
"@transia/ripple-binary-codec": "^1.4.6-alpha.1",
"@transia/ripple-keypairs": "^1.1.8-alpha.0",
"bignumber.js": "^9.0.0", "bignumber.js": "^9.0.0",
"bip32": "^2.0.6", "bip32": "^2.0.6",
"bip39": "^3.0.4", "bip39": "^3.0.4",
"https-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"ripple-address-codec": "^4.2.5",
"ripple-binary-codec": "^1.4.3",
"ripple-keypairs": "^1.1.5",
"ws": "^8.2.2" "ws": "^8.2.2"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -1,7 +1,7 @@
import { IncomingMessage } from 'http' import { IncomingMessage } from 'http'
import { request as httpsRequest, RequestOptions } from 'https' import { request as httpsRequest, RequestOptions } from 'https'
import { isValidClassicAddress } from 'ripple-address-codec' import { isValidClassicAddress } from '@transia/ripple-address-codec'
import type { Client } from '../client' import type { Client } from '../client'
import { RippledError, XRPLFaucetError } from '../errors' import { RippledError, XRPLFaucetError } from '../errors'

View File

@@ -1,28 +1,28 @@
/* eslint-disable max-lines -- There are lots of equivalent constructors which make sense to have here. */ /* eslint-disable max-lines -- There are lots of equivalent constructors which make sense to have here. */
import BigNumber from 'bignumber.js'
import { fromSeed } from 'bip32'
import { mnemonicToSeedSync, validateMnemonic } from 'bip39'
import isEqual from 'lodash/isEqual'
import omitBy from 'lodash/omitBy'
import { import {
classicAddressToXAddress, classicAddressToXAddress,
isValidXAddress, isValidXAddress,
xAddressToClassicAddress, xAddressToClassicAddress,
encodeSeed, encodeSeed,
} from 'ripple-address-codec' } from '@transia/ripple-address-codec'
import { import {
decode, decode,
encodeForSigning, encodeForSigning,
encodeForMultisigning, encodeForMultisigning,
encode, encode,
} from 'ripple-binary-codec' } from '@transia/ripple-binary-codec'
import { import {
deriveAddress, deriveAddress,
deriveKeypair, deriveKeypair,
generateSeed, generateSeed,
verify, verify,
sign, sign,
} from 'ripple-keypairs' } from '@transia/ripple-keypairs'
import BigNumber from 'bignumber.js'
import { fromSeed } from 'bip32'
import { mnemonicToSeedSync, validateMnemonic } from 'bip39'
import isEqual from 'lodash/isEqual'
import omitBy from 'lodash/omitBy'
import ECDSA from '../ECDSA' import ECDSA from '../ECDSA'
import { ValidationError, XrplError } from '../errors' import { ValidationError, XrplError } from '../errors'

View File

@@ -1,13 +1,13 @@
import { BigNumber } from 'bignumber.js' import { decodeAccountID } from '@transia/ripple-address-codec'
import { flatMap } from 'lodash'
import { decodeAccountID } from 'ripple-address-codec'
import { import {
decode, decode,
encode, encode,
encodeForSigning, encodeForSigning,
encodeForSigningClaim, encodeForSigningClaim,
} from 'ripple-binary-codec' } from '@transia/ripple-binary-codec'
import { sign as signWithKeypair, verify } from 'ripple-keypairs' import { sign as signWithKeypair, verify } from '@transia/ripple-keypairs'
import { BigNumber } from 'bignumber.js'
import { flatMap } from 'lodash'
import { ValidationError } from '../errors' import { ValidationError } from '../errors'
import { Signer } from '../models/common' import { Signer } from '../models/common'

View File

@@ -1,5 +1,5 @@
import { decode } from '@transia/ripple-binary-codec'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { decode } from 'ripple-binary-codec'
import type { import type {
AccountTxResponse, AccountTxResponse,

View File

@@ -97,14 +97,15 @@ export interface Hook {
* The object that describes the hook in Hooks. * The object that describes the hook in Hooks.
*/ */
Hook: { Hook: {
HookHash?: string
/** /**
* The code that is executed when the hook is triggered. * The code that is executed when the hook is triggered.
*/ */
CreateCode: string CreateCode?: string
/** /**
* The flags that are set on the hook. * The flags that are set on the hook.
*/ */
Flags: number Flags?: number
/** /**
* The transactions that triggers the hook. Represented as a 256Hash * The transactions that triggers the hook. Represented as a 256Hash
*/ */

View File

@@ -1,6 +1,6 @@
/* eslint-disable complexity -- Necessary for validateAccountSet */ /* eslint-disable complexity -- Necessary for validateAccountSet */
import { isValidClassicAddress } from 'ripple-address-codec' import { isValidClassicAddress } from '@transia/ripple-address-codec'
import { ValidationError } from '../../errors' import { ValidationError } from '../../errors'

View File

@@ -1,10 +1,16 @@
/* eslint-disable max-lines-per-function -- Necessary for validateBaseTransaction */ /* eslint-disable max-lines-per-function -- Necessary for validateBaseTransaction */
/* eslint-disable complexity -- Necessary for validateBaseTransaction */ /* eslint-disable complexity -- Necessary for validateBaseTransaction */
/* eslint-disable max-statements -- Necessary for validateBaseTransaction */ /* eslint-disable max-statements -- Necessary for validateBaseTransaction */
import { TRANSACTION_TYPES } from 'ripple-binary-codec' import { TRANSACTION_TYPES } from '@transia/ripple-binary-codec'
import { ValidationError } from '../../errors' import { ValidationError } from '../../errors'
import { Amount, IssuedCurrencyAmount, Memo, Signer } from '../common' import {
Amount,
HookParameter,
IssuedCurrencyAmount,
Memo,
Signer,
} from '../common'
import { onlyHasFields } from '../utils' import { onlyHasFields } from '../utils'
const MEMO_SIZE = 3 const MEMO_SIZE = 3
@@ -163,6 +169,10 @@ export interface BaseTransaction {
* The network id of the transaction. * The network id of the transaction.
*/ */
NetworkID?: number NetworkID?: number
/**
* The hook parameters of the transaction.
*/
HookParameters?: HookParameter[]
} }
/** /**

View File

@@ -0,0 +1,24 @@
import { BaseTransaction, validateBaseTransaction } from './common'
/**
*
*
* @category Transaction Models
*/
export interface Import extends BaseTransaction {
TransactionType: 'Import'
/**
* Hex value representing a VL Blob.
*/
Blob?: string
}
/**
* Verify the form and type of an Import at runtime.
*
* @param tx - An Import Transaction.
* @throws When the Import is Malformed.
*/
export function validateImport(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
}

View File

@@ -14,6 +14,7 @@ export { DepositPreauth } from './depositPreauth'
export { EscrowCancel } from './escrowCancel' export { EscrowCancel } from './escrowCancel'
export { EscrowCreate } from './escrowCreate' export { EscrowCreate } from './escrowCreate'
export { EscrowFinish } from './escrowFinish' export { EscrowFinish } from './escrowFinish'
export { Import } from './import'
export { Invoke } from './invoke' export { Invoke } from './invoke'
export { NFTokenAcceptOffer } from './NFTokenAcceptOffer' export { NFTokenAcceptOffer } from './NFTokenAcceptOffer'
export { NFTokenBurn } from './NFTokenBurn' export { NFTokenBurn } from './NFTokenBurn'
@@ -43,7 +44,16 @@ export {
export { PaymentChannelCreate } from './paymentChannelCreate' export { PaymentChannelCreate } from './paymentChannelCreate'
export { PaymentChannelFund } from './paymentChannelFund' export { PaymentChannelFund } from './paymentChannelFund'
export { SetRegularKey } from './setRegularKey' export { SetRegularKey } from './setRegularKey'
export { SetHook } from './setHook' export { SetHookFlagsInterface, SetHookFlags, SetHook } from './setHook'
export { SignerListSet } from './signerListSet' export { SignerListSet } from './signerListSet'
export { TicketCreate } from './ticketCreate' export { TicketCreate } from './ticketCreate'
export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet' export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
export {
URITokenMintFlagsInterface,
URITokenMintFlags,
URITokenMint,
} from './uriTokenMint'
export { URITokenBurn } from './uriTokenBurn'
export { URITokenCreateSellOffer } from './uriTokenCreateSellOffer'
export { URITokenBuy } from './uriTokenBuy'
export { URITokenCancelSellOffer } from './uriTokenCancelSellOffer'

View File

@@ -13,6 +13,10 @@ export interface Invoke extends BaseTransaction {
* If present, invokes the Hook on the Destination account. * If present, invokes the Hook on the Destination account.
*/ */
Destination?: string Destination?: string
/**
* Hex value representing a VL Blob.
*/
Blob?: string
} }
/** /**

View File

@@ -1,5 +1,19 @@
import { Amount } from '../common' import { Amount } from '../common'
export interface HookExecution {
HookExecution: {
HookAccount: string
HookEmitCount: number
HookExecutionIndex: number
HookHash: string
HookInstructionCount: string
HookResult: number
HookReturnCode: number
HookReturnString: string
HookStateChangeCount: number
}
}
export interface CreatedNode { export interface CreatedNode {
CreatedNode: { CreatedNode: {
LedgerEntryType: string LedgerEntryType: string
@@ -60,6 +74,7 @@ export function isDeletedNode(node: Node): node is DeletedNode {
} }
export interface TransactionMetadata { export interface TransactionMetadata {
HookExecutions?: HookExecution[]
AffectedNodes: Node[] AffectedNodes: Node[]
DeliveredAmount?: Amount DeliveredAmount?: Amount
// "unavailable" possible for transactions before 2014-01-20 // "unavailable" possible for transactions before 2014-01-20

View File

@@ -1,7 +1,30 @@
import { ValidationError } from '../../errors' import { ValidationError } from '../../errors'
import { Hook } from '../common' import { Hook } from '../common'
import { BaseTransaction, validateBaseTransaction } from './common' import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
/**
* Enum representing values for Set Hook Transaction Flags.
*
* @category Transaction Flags
*/
export enum SetHookFlags {
/**
*/
hsfOverride = 0x00000001,
/**
*/
hsfNSDelete = 0x00000010,
/**
*/
hsfCollect = 0x00000100,
}
export interface SetHookFlagsInterface extends GlobalFlags {
hsfOverride?: boolean
hsfNSDelete?: boolean
hsfCollect?: boolean
}
/** /**
* *
@@ -14,6 +37,8 @@ export interface SetHook extends BaseTransaction {
* *
*/ */
Hooks: Hook[] Hooks: Hook[]
Flags?: number | SetHookFlagsInterface
} }
const MAX_HOOKS = 4 const MAX_HOOKS = 4

View File

@@ -13,6 +13,8 @@ import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
import { EscrowCancel, validateEscrowCancel } from './escrowCancel' import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
import { EscrowCreate, validateEscrowCreate } from './escrowCreate' import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
import { EscrowFinish, validateEscrowFinish } from './escrowFinish' import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
import { Import, validateImport } from './import'
import { Invoke, validateInvoke } from './invoke'
import { TransactionMetadata } from './metadata' import { TransactionMetadata } from './metadata'
import { import {
NFTokenAcceptOffer, NFTokenAcceptOffer,
@@ -48,6 +50,17 @@ import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
import { SignerListSet, validateSignerListSet } from './signerListSet' import { SignerListSet, validateSignerListSet } from './signerListSet'
import { TicketCreate, validateTicketCreate } from './ticketCreate' import { TicketCreate, validateTicketCreate } from './ticketCreate'
import { TrustSet, validateTrustSet } from './trustSet' import { TrustSet, validateTrustSet } from './trustSet'
import { URITokenBurn, validateURITokenBurn } from './uriTokenBurn'
import { URITokenBuy, validateURITokenBuy } from './uriTokenBuy'
import {
URITokenCancelSellOffer,
validateURITokenCancelSellOffer,
} from './uriTokenCancelSellOffer'
import {
URITokenCreateSellOffer,
validateURITokenCreateSellOffer,
} from './uriTokenCreateSellOffer'
import { URITokenMint, validateURITokenMint } from './uriTokenMint'
/** /**
* @category Transaction Models * @category Transaction Models
@@ -62,6 +75,8 @@ export type Transaction =
| EscrowCancel | EscrowCancel
| EscrowCreate | EscrowCreate
| EscrowFinish | EscrowFinish
| Import
| Invoke
| NFTokenAcceptOffer | NFTokenAcceptOffer
| NFTokenBurn | NFTokenBurn
| NFTokenCancelOffer | NFTokenCancelOffer
@@ -78,6 +93,11 @@ export type Transaction =
| SignerListSet | SignerListSet
| TicketCreate | TicketCreate
| TrustSet | TrustSet
| URITokenBurn
| URITokenBuy
| URITokenCancelSellOffer
| URITokenMint
| URITokenCreateSellOffer
/** /**
* @category Transaction Models * @category Transaction Models
@@ -142,6 +162,14 @@ export function validate(transaction: Record<string, unknown>): void {
validateEscrowFinish(tx) validateEscrowFinish(tx)
break break
case 'Import':
validateImport(tx)
break
case 'Invoke':
validateInvoke(tx)
break
case 'NFTokenAcceptOffer': case 'NFTokenAcceptOffer':
validateNFTokenAcceptOffer(tx) validateNFTokenAcceptOffer(tx)
break break
@@ -206,6 +234,26 @@ export function validate(transaction: Record<string, unknown>): void {
validateTrustSet(tx) validateTrustSet(tx)
break break
case 'URITokenMint':
validateURITokenMint(tx)
break
case 'URITokenBurn':
validateURITokenBurn(tx)
break
case 'URITokenCreateSellOffer':
validateURITokenCreateSellOffer(tx)
break
case 'URITokenBuy':
validateURITokenBuy(tx)
break
case 'URITokenCancelSellOffer':
validateURITokenCancelSellOffer(tx)
break
default: default:
throw new ValidationError( throw new ValidationError(
`Invalid field TransactionType: ${tx.TransactionType}`, `Invalid field TransactionType: ${tx.TransactionType}`,

View File

@@ -0,0 +1,60 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenBurn} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenBurn = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* TransactionType: 'URITokenBurn',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // TransactionType: 'URITokenBurn',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenBurn transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenBurn extends BaseTransaction {
TransactionType: 'URITokenBurn'
/**
* Identifies the URIToken object to be removed by the transaction.
*/
URITokenID: string
}
/**
* Verify the form and type of an URITokenBurn at runtime.
*
* @param tx - An URITokenBurn Transaction.
* @throws When the URITokenBurn is Malformed.
*/
export function validateURITokenBurn(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.URITokenID == null) {
throw new ValidationError('NFTokenBurn: missing field URITokenID')
}
}

View File

@@ -0,0 +1,83 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenBuy} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenBuy = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* Amount: '1000000',
* TransactionType: 'URITokenBuy',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // Amount: '1000000',
* // TransactionType: 'URITokenBuy',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenBuy transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenBuy extends BaseTransaction {
TransactionType: 'URITokenBuy'
/**
* Identifies the URITokenID of the NFToken object that the
* offer references.
*/
URITokenID: string
/**
* Indicates the amount expected or offered for the Token.
*
* The amount must be non-zero, except when this is a sell
* offer and the asset is XRP. This would indicate that the current
* owner of the token is giving it away free, either to anyone at all,
* or to the account identified by the Destination field.
*/
Amount: Amount
}
/**
* Verify the form and type of an URITokenBuy at runtime.
*
* @param tx - An URITokenBuy Transaction.
* @throws When the URITokenBuy is Malformed.
*/
export function validateURITokenBuy(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Account === tx.Destination) {
throw new ValidationError(
'URITokenBuy: Destination and Account must not be equal',
)
}
if (tx.URITokenID == null) {
throw new ValidationError('URITokenBuy: missing field URITokenID')
}
if (!isAmount(tx.Amount)) {
throw new ValidationError('URITokenBuy: invalid Amount')
}
}

View File

@@ -0,0 +1,65 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenCancelSellOffer} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenCancelSellOffer = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* TransactionType: 'URITokenCancelSellOffer',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // TransactionType: 'URITokenCancelSellOffer',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenCancelSellOffer transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenCancelSellOffer extends BaseTransaction {
TransactionType: 'URITokenCancelSellOffer'
/**
* Identifies the URITokenID of the NFToken object that the
* offer references.
*/
URITokenID: string
}
/**
* Verify the form and type of an URITokenCancelSellOffer at runtime.
*
* @param tx - An URITokenCancelSellOffer Transaction.
* @throws When the URITokenCancelSellOffer is Malformed.
*/
export function validateURITokenCancelSellOffer(
tx: Record<string, unknown>,
): void {
validateBaseTransaction(tx)
if (tx.URITokenID == null) {
throw new ValidationError(
'URITokenCancelSellOffer: missing field URITokenID',
)
}
}

View File

@@ -0,0 +1,93 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenCreateSellOffer} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenCreateSellOffer = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* Amount: '1000000',
* TransactionType: 'URITokenCreateSellOffer',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // Amount: '1000000',
* // TransactionType: 'URITokenCreateSellOffer',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenCreateSellOffer transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenCreateSellOffer extends BaseTransaction {
TransactionType: 'URITokenCreateSellOffer'
/**
* Identifies the URITokenID of the NFToken object that the
* offer references.
*/
URITokenID: string
/**
* Indicates the amount expected or offered for the Token.
*
* The amount must be non-zero, except when this is a sell
* offer and the asset is XRP. This would indicate that the current
* owner of the token is giving it away free, either to anyone at all,
* or to the account identified by the Destination field.
*/
Amount: Amount
/**
* If present, indicates that this offer may only be
* accepted by the specified account. Attempts by other
* accounts to accept this offer MUST fail.
*/
Destination?: string
}
/**
* Verify the form and type of an URITokenCreateSellOffer at runtime.
*
* @param tx - An URITokenCreateSellOffer Transaction.
* @throws When the URITokenCreateSellOffer is Malformed.
*/
export function validateURITokenCreateSellOffer(
tx: Record<string, unknown>,
): void {
validateBaseTransaction(tx)
if (tx.Account === tx.Destination) {
throw new ValidationError(
'URITokenCreateSellOffer: Destination and Account must not be equal',
)
}
if (tx.URITokenID == null) {
throw new ValidationError(
'URITokenCreateSellOffer: missing field URITokenID',
)
}
if (!isAmount(tx.Amount)) {
throw new ValidationError('URITokenCreateSellOffer: invalid Amount')
}
}

View File

@@ -0,0 +1,92 @@
import { ValidationError } from '../../errors'
import { isHex } from '../utils'
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
/**
* Transaction Flags for an URITokenMint Transaction.
*
* @category Transaction Flags
*/
export enum URITokenMintFlags {
/**
* If set, indicates that the minted token may be burned by the issuer even
* if the issuer does not currently hold the token. The current holder of
* the token may always burn it.
*/
tfBurnable = 0x00000001,
}
/**
* Map of flags to boolean values representing {@link URITokenMint} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenMint = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URI: '697066733A2F2F434944',
* TransactionType: 'URITokenMint',
* Flags: {
* tfBurnable: true,
* },
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URI: '697066733A2F2F434944',
* // TransactionType: 'URITokenMint',
* // Flags: 0,
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
export interface URITokenMintFlagsInterface extends GlobalFlags {
tfBurnable?: boolean
}
/**
* An URITokenMint transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenMint extends BaseTransaction {
TransactionType: 'URITokenMint'
Flags?: number | URITokenMintFlagsInterface
/**
* URI that points to the data and/or metadata associated with the NFT.
* This field need not be an HTTP or HTTPS URL; it could be an IPFS URI, a
* magnet link, immediate data encoded as an RFC2379 "data" URL, or even an
* opaque issuer-specific encoding. The URI is NOT checked for validity, but
* the field is limited to a maximum length of 256 bytes.
*
* This field must be hex-encoded. You can use `convertStringToHex` to
* convert this field to the proper encoding.
*/
URI: string
Digest?: string
}
/**
* Verify the form and type of an URITokenMint at runtime.
*
* @param tx - An URITokenMint Transaction.
* @throws When the URITokenMint is Malformed.
*/
export function validateURITokenMint(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (typeof tx.URI === 'string' && !isHex(tx.URI)) {
throw new ValidationError('URITokenMint: URI must be in hex format')
}
}

View File

@@ -2,6 +2,7 @@
/* eslint-disable no-bitwise -- flags require bitwise operations */ /* eslint-disable no-bitwise -- flags require bitwise operations */
import { ValidationError } from '../../errors' import { ValidationError } from '../../errors'
import { Hook } from '../common'
import { import {
AccountRootFlagsInterface, AccountRootFlagsInterface,
AccountRootFlags, AccountRootFlags,
@@ -20,6 +21,7 @@ import {
PaymentChannelClaimFlagsInterface, PaymentChannelClaimFlagsInterface,
PaymentChannelClaimFlags, PaymentChannelClaimFlags,
} from '../transactions/paymentChannelClaim' } from '../transactions/paymentChannelClaim'
import { SetHookFlagsInterface, SetHookFlags } from '../transactions/setHook'
import type { Transaction } from '../transactions/transaction' import type { Transaction } from '../transactions/transaction'
import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet' import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet'
@@ -75,6 +77,15 @@ export function setTransactionFlagsToNumber(tx: Transaction): void {
case 'TrustSet': case 'TrustSet':
tx.Flags = convertTrustSetFlagsToNumber(tx.Flags) tx.Flags = convertTrustSetFlagsToNumber(tx.Flags)
return return
case 'SetHook':
tx.Flags = convertSetHookFlagsToNumber(tx.Flags)
tx.Hooks.forEach((hook: Hook) => {
hook.Hook.Flags = convertSetHookFlagsToNumber(
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- idk
hook.Hook.Flags as SetHookFlagsInterface,
)
})
return
default: default:
tx.Flags = 0 tx.Flags = 0
} }
@@ -108,6 +119,10 @@ function convertTrustSetFlagsToNumber(flags: TrustSetFlagsInterface): number {
return reduceFlags(flags, TrustSetFlags) return reduceFlags(flags, TrustSetFlags)
} }
function convertSetHookFlagsToNumber(flags: SetHookFlagsInterface): number {
return reduceFlags(flags, SetHookFlags)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum // eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum
function reduceFlags(flags: GlobalFlags, flagEnum: any): number { function reduceFlags(flags: GlobalFlags, flagEnum: any): number {
return Object.keys(flags).reduce((resultFlags, flag) => { return Object.keys(flags).reduce((resultFlags, flag) => {

View File

@@ -1,5 +1,8 @@
import {
xAddressToClassicAddress,
isValidXAddress,
} from '@transia/ripple-address-codec'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
import type { Client } from '..' import type { Client } from '..'
import { ValidationError, XrplError } from '../errors' import { ValidationError, XrplError } from '../errors'

View File

@@ -1,4 +1,4 @@
import { decode, encode } from 'ripple-binary-codec' import { decode, encode } from '@transia/ripple-binary-codec'
import type { Client, SubmitRequest, SubmitResponse, Wallet } from '..' import type { Client, SubmitRequest, SubmitResponse, Wallet } from '..'
import { ValidationError, XrplError } from '../errors' import { ValidationError, XrplError } from '../errors'

View File

@@ -1,4 +1,7 @@
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec' import {
xAddressToClassicAddress,
isValidXAddress,
} from '@transia/ripple-address-codec'
/** /**
* If an address is an X-Address, converts it to a classic address. * If an address is an X-Address, converts it to a classic address.

View File

@@ -1,5 +1,5 @@
import { classicAddressToXAddress } from 'ripple-address-codec' import { classicAddressToXAddress } from '@transia/ripple-address-codec'
import { deriveKeypair, deriveAddress } from 'ripple-keypairs' import { deriveKeypair, deriveAddress } from '@transia/ripple-keypairs'
/** /**
* Derive an X-Address from a public key and a destination tag. * Derive an X-Address from a public key and a destination tag.

View File

@@ -3,8 +3,8 @@
/* eslint-disable no-bitwise -- this file mimics behavior in rippled. It uses /* eslint-disable no-bitwise -- this file mimics behavior in rippled. It uses
bitwise operators for and-ing numbers with a mask and bit shifting. */ bitwise operators for and-ing numbers with a mask and bit shifting. */
import { decode, encode } from '@transia/ripple-binary-codec'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { decode, encode } from 'ripple-binary-codec'
import { ValidationError, XrplError } from '../../errors' import { ValidationError, XrplError } from '../../errors'
import type { Ledger } from '../../models/ledger' import type { Ledger } from '../../models/ledger'

View File

@@ -3,8 +3,8 @@
/* eslint-disable no-bitwise -- this file mimics behavior in rippled. It uses /* eslint-disable no-bitwise -- this file mimics behavior in rippled. It uses
bitwise operators for and-ing numbers with a mask and bit shifting. */ bitwise operators for and-ing numbers with a mask and bit shifting. */
import { decodeAccountID } from '@transia/ripple-address-codec'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { decodeAccountID } from 'ripple-address-codec'
import hashLedger, { import hashLedger, {
hashLedgerHeader, hashLedgerHeader,

View File

@@ -4,9 +4,11 @@
* This module contains the transaction types and the function to calculate the hook on * This module contains the transaction types and the function to calculate the hook on
*/ */
// eslint-disable-next-line @typescript-eslint/no-require-imports -- Required import {
import createHash = require('create-hash') TRANSACTION_TYPES,
import { TRANSACTION_TYPES, TRANSACTION_TYPE_MAP } from 'ripple-binary-codec' TRANSACTION_TYPE_MAP,
} from '@transia/ripple-binary-codec'
// import createHash = require('create-hash')
import { XrplError } from '../errors' import { XrplError } from '../errors'
import { HookParameter } from '../models/common' import { HookParameter } from '../models/common'
@@ -42,7 +44,7 @@ export function calculateHookOn(arr: Array<keyof TTS>): string {
`invalid transaction type '${String(nth)}' in HookOn array`, `invalid transaction type '${String(nth)}' in HookOn array`,
) )
} }
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Required
const tts: Record<string, number> = TRANSACTION_TYPE_MAP const tts: Record<string, number> = TRANSACTION_TYPE_MAP
let value = BigInt(hash) let value = BigInt(hash)
// eslint-disable-next-line no-bitwise -- Required // eslint-disable-next-line no-bitwise -- Required
@@ -56,32 +58,12 @@ export function calculateHookOn(arr: Array<keyof TTS>): string {
return hash.toUpperCase() return hash.toUpperCase()
} }
/** function isHex(value: string): boolean {
* Calculate the sha256 of a string return /^[0-9A-F]+$/iu.test(value)
*
* @param string - the string to calculate the sha256
* @returns the sha256
*/
export async function sha256(string: string): Promise<string> {
const hash = createHash('sha256')
hash.update(string)
const hashBuffer = hash.digest()
const hashArray = Array.from(new Uint8Array(hashBuffer))
const hashHex = hashArray
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- Required
.map((bytes) => bytes.toString(16).padStart(2, '0'))
.join('')
return hashHex
} }
/** function hexValue(value: string): string {
* Calculate the hex of a namespace return Buffer.from(value, 'utf8').toString('hex').toUpperCase()
*
* @param namespace - the namespace to calculate the hex
* @returns the hex
*/
export async function hexNamespace(namespace: string): Promise<string> {
return (await sha256(namespace)).toUpperCase()
} }
/** /**
@@ -93,20 +75,21 @@ export async function hexNamespace(namespace: string): Promise<string> {
export function hexHookParameters(data: HookParameter[]): HookParameter[] { export function hexHookParameters(data: HookParameter[]): HookParameter[] {
const hookParameters: HookParameter[] = [] const hookParameters: HookParameter[] = []
for (const parameter of data) { for (const parameter of data) {
let hookPName = parameter.HookParameter.HookParameterName
let hookPValue = parameter.HookParameter.HookParameterValue
if (!isHex(hookPName)) {
hookPName = hexValue(hookPName)
}
if (!isHex(hookPValue)) {
hookPValue = hexValue(hookPValue)
}
hookParameters.push({ hookParameters.push({
HookParameter: { HookParameter: {
HookParameterName: Buffer.from( HookParameterName: hookPName,
parameter.HookParameter.HookParameterName, HookParameterValue: hookPValue,
'utf8',
)
.toString('hex')
.toUpperCase(),
HookParameterValue: Buffer.from(
parameter.HookParameter.HookParameterValue,
'utf8',
)
.toString('hex')
.toUpperCase(),
}, },
}) })
} }

View File

@@ -13,9 +13,9 @@ import {
isValidClassicAddress, isValidClassicAddress,
isValidXAddress, isValidXAddress,
xAddressToClassicAddress, xAddressToClassicAddress,
} from 'ripple-address-codec' } from '@transia/ripple-address-codec'
import * as rbc from 'ripple-binary-codec' import * as rbc from '@transia/ripple-binary-codec'
import { verify as verifyKeypairSignature } from 'ripple-keypairs' import { verify as verifyKeypairSignature } from '@transia/ripple-keypairs'
import { LedgerEntry } from '../models/ledger' import { LedgerEntry } from '../models/ledger'
import { Response } from '../models/methods' import { Response } from '../models/methods'
@@ -40,7 +40,7 @@ import {
hashEscrow, hashEscrow,
hashPaymentChannel, hashPaymentChannel,
} from './hashes' } from './hashes'
import { calculateHookOn, hexNamespace, hexHookParameters, TTS } from './hooks' import { calculateHookOn, hexHookParameters, TTS } from './hooks'
import parseNFTokenID from './parseNFTokenID' import parseNFTokenID from './parseNFTokenID'
import { import {
percentToTransferRate, percentToTransferRate,
@@ -224,7 +224,6 @@ export {
createCrossChainPayment, createCrossChainPayment,
parseNFTokenID, parseNFTokenID,
calculateHookOn, calculateHookOn,
hexNamespace,
hexHookParameters, hexHookParameters,
TTS, TTS,
} }

View File

@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-magic-numbers -- Doing hex string parsing. */ /* eslint-disable @typescript-eslint/no-magic-numbers -- Doing hex string parsing. */
import { encodeAccountID } from '@transia/ripple-address-codec'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { encodeAccountID } from 'ripple-address-codec'
import { XrplError } from '../errors' import { XrplError } from '../errors'

View File

@@ -1,5 +1,5 @@
import { encodeForSigningClaim } from 'ripple-binary-codec' import { encodeForSigningClaim } from '@transia/ripple-binary-codec'
import { sign } from 'ripple-keypairs' import { sign } from '@transia/ripple-keypairs'
import { xrpToDrops } from './xrpConversion' import { xrpToDrops } from './xrpConversion'

View File

@@ -1,5 +1,5 @@
import { encodeForSigningClaim } from 'ripple-binary-codec' import { encodeForSigningClaim } from '@transia/ripple-binary-codec'
import { verify } from 'ripple-keypairs' import { verify } from '@transia/ripple-keypairs'
import { xrpToDrops } from './xrpConversion' import { xrpToDrops } from './xrpConversion'

View File

@@ -1,5 +1,5 @@
import { decode } from '@transia/ripple-binary-codec'
import { assert } from 'chai' import { assert } from 'chai'
import { decode } from 'ripple-binary-codec'
import { import {
AccountSet, AccountSet,

View File

@@ -1,5 +1,5 @@
import { decode } from '@transia/ripple-binary-codec'
import { assert } from 'chai' import { assert } from 'chai'
import { decode } from 'ripple-binary-codec'
import { import {
AccountSet, AccountSet,

View File

@@ -1,6 +1,6 @@
import { Client } from '@transia/xrpl'
import { assert } from 'chai' import { assert } from 'chai'
import _ from 'lodash' import _ from 'lodash'
import { Client } from 'xrpl'
import { import {
convertStringToHex, convertStringToHex,

View File

@@ -1,7 +1,7 @@
import { decode } from '@transia/ripple-binary-codec'
import { assert } from 'chai' import { assert } from 'chai'
import omit from 'lodash/omit' import omit from 'lodash/omit'
import throttle from 'lodash/throttle' import throttle from 'lodash/throttle'
import { decode } from 'ripple-binary-codec'
import { import {
Client, Client,

View File

@@ -1,8 +1,8 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { encode } from '@transia/ripple-binary-codec'
import { assert } from 'chai' import { assert } from 'chai'
import { encode } from 'ripple-binary-codec'
import { OfferCreate, Transaction, ValidationError } from '../../src' import { OfferCreate, Transaction, ValidationError } from '../../src'
import { import {

View File

@@ -1,11 +1,6 @@
import { assert } from 'chai' import { assert } from 'chai'
import { import { calculateHookOn, hexHookParameters, TTS } from '../../src'
calculateHookOn,
hexNamespace,
hexHookParameters,
TTS,
} from '../../src'
describe('test hook on', function () { describe('test hook on', function () {
it('invalid', function () { it('invalid', function () {
@@ -31,16 +26,6 @@ describe('test hook on', function () {
}) })
}) })
describe('test hook namespace', function () {
it('basic', async function () {
const result = await hexNamespace('starter')
assert.equal(
result,
'4FF9961269BF7630D32E15276569C94470174A5DA79FA567C0F62251AA9A36B9',
)
})
})
describe('test hook parameters', function () { describe('test hook parameters', function () {
it('basic', async function () { it('basic', async function () {
const parameters = [ const parameters = [

View File

@@ -1,5 +1,5 @@
import { decode } from '@transia/ripple-binary-codec'
import { assert } from 'chai' import { assert } from 'chai'
import { decode } from 'ripple-binary-codec'
import { NFTokenMint, Payment, Transaction } from '../../src' import { NFTokenMint, Payment, Transaction } from '../../src'
import ECDSA from '../../src/ECDSA' import ECDSA from '../../src/ECDSA'

View File

@@ -1,5 +1,5 @@
import { decode, encode } from '@transia/ripple-binary-codec'
import { assert } from 'chai' import { assert } from 'chai'
import { decode, encode } from 'ripple-binary-codec'
import { Transaction, ValidationError } from '../../src' import { Transaction, ValidationError } from '../../src'
import Wallet from '../../src/Wallet' import Wallet from '../../src/Wallet'