Compare commits

..

28 Commits

Author SHA1 Message Date
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
29 changed files with 2182 additions and 2604 deletions

4128
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -1,9 +1,6 @@
{
"name": "@transia/ripple-binary-codec",
"publishConfig": {
"access": "public"
},
"version": "1.4.4-alpha.3",
"version": "1.4.6-alpha.0",
"description": "XRP Ledger binary codec",
"files": [
"dist/*",
@@ -15,7 +12,7 @@
"test": "test"
},
"dependencies": {
"@transia/ripple-address-codec": "^4.2.6-alpha.0",
"@transia/ripple-address-codec": "^4.2.8-alpha.0",
"assert": "^2.0.0",
"big-integer": "^1.6.48",
"buffer": "5.6.0",
@@ -42,6 +39,5 @@
"prettier": "@xrplf/prettier-config",
"engines": {
"node": ">= 10"
},
"gitHead": "943142cb73821de7a4662cc660c5693a3ec2ff81"
}
}

View File

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

View File

@@ -1,9 +1,6 @@
{
"name": "@transia/ripple-keypairs",
"publishConfig": {
"access": "public"
},
"version": "1.1.6-alpha.3",
"version": "1.1.8-alpha.0",
"description": "Cryptographic key pairs for the XRP Ledger",
"scripts": {
"build": "tsc -b",
@@ -20,7 +17,7 @@
"test": "test"
},
"dependencies": {
"@transia/ripple-address-codec": "^4.2.6-alpha.0",
"@transia/ripple-address-codec": "^4.2.8-alpha.0",
"bn.js": "^5.1.1",
"brorand": "^1.0.5",
"elliptic": "^6.5.4",
@@ -34,6 +31,5 @@
"prettier": "@xrplf/prettier-config",
"engines": {
"node": ">= 10"
},
"gitHead": "943142cb73821de7a4662cc660c5693a3ec2ff81"
}
}

View File

@@ -1,9 +1,6 @@
{
"name": "@transia/xrpl",
"publishConfig": {
"access": "public"
},
"version": "2.7.1-alpha.6",
"version": "2.7.3-alpha.0",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [
@@ -25,9 +22,9 @@
"https-proxy-agent": false
},
"dependencies": {
"@transia/ripple-address-codec": "^4.2.6-alpha.0",
"@transia/ripple-binary-codec": "^1.4.4-alpha.3",
"@transia/ripple-keypairs": "^1.1.6-alpha.3",
"@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",
"bignumber.js": "^9.0.0",
"bip32": "^2.0.6",
"bip39": "^3.0.4",
@@ -83,6 +80,5 @@
"readmeFilename": "README.md",
"engines": {
"node": ">=10.13.0"
},
"gitHead": "943142cb73821de7a4662cc660c5693a3ec2ff81"
}
}

View File

@@ -1,4 +1,15 @@
/* 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 {
classicAddressToXAddress,
isValidXAddress,
xAddressToClassicAddress,
encodeSeed,
} from '@transia/ripple-address-codec'
import {
decode,
encodeForSigning,
@@ -12,17 +23,6 @@ import {
verify,
sign,
} 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 {
classicAddressToXAddress,
isValidXAddress,
xAddressToClassicAddress,
encodeSeed,
} from '@transia/ripple-address-codec'
import ECDSA from '../ECDSA'
import { ValidationError, XrplError } from '../errors'

View File

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

View File

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

View File

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

View File

@@ -170,7 +170,7 @@ export interface BaseTransaction {
*/
NetworkID?: number
/**
* The hook parameters of the transaction
* The hook parameters of the transaction.
*/
HookParameters?: HookParameter[]
}

View File

@@ -43,16 +43,7 @@ export {
export { PaymentChannelCreate } from './paymentChannelCreate'
export { PaymentChannelFund } from './paymentChannelFund'
export { SetRegularKey } from './setRegularKey'
export { SetHook } from './setHook'
export { SetHookFlagsInterface, SetHookFlags, SetHook } from './setHook'
export { SignerListSet } from './signerListSet'
export { TicketCreate } from './ticketCreate'
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.
*/
Destination?: string
/**
* Hex value representing a VL Blob.
*/
Blob?: string
}
/**

View File

@@ -1,5 +1,19 @@
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 {
CreatedNode: {
LedgerEntryType: string
@@ -29,20 +43,6 @@ export interface DeletedNode {
export type Node = CreatedNode | ModifiedNode | DeletedNode
export interface HookExecution {
HookExecution: {
HookAccount: string
HookEmitCount: number
HookExecutionIndex: number
HookHash: string
HookInstructionCount: string
HookResult: number
HookReturnCode: number
HookReturnString: string
HookStateChangeCount: number
}
}
/**
* A typeguard to check if a node is a CreatedNode.
*
@@ -74,10 +74,10 @@ export function isDeletedNode(node: Node): node is DeletedNode {
}
export interface TransactionMetadata {
HookExecutions: HookExecution[]
AffectedNodes: Node[]
DeliveredAmount?: Amount
// "unavailable" possible for transactions before 2014-01-20
HookExecutions: HookExecution[]
delivered_amount?: Amount | 'unavailable'
TransactionIndex: number
TransactionResult: string

View File

@@ -1,7 +1,30 @@
import { ValidationError } from '../../errors'
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[]
Flags?: number | SetHookFlagsInterface
}
const MAX_HOOKS = 4

View File

@@ -49,17 +49,6 @@ import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
import { SignerListSet, validateSignerListSet } from './signerListSet'
import { TicketCreate, validateTicketCreate } from './ticketCreate'
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
@@ -91,11 +80,6 @@ export type Transaction =
| SignerListSet
| TicketCreate
| TrustSet
| URITokenBurn
| URITokenBuy
| URITokenCancelSellOffer
| URITokenMint
| URITokenCreateSellOffer
/**
* @category Transaction Models
@@ -228,26 +212,6 @@ export function validate(transaction: Record<string, unknown>): void {
validateTrustSet(tx)
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:
throw new ValidationError(
`Invalid field TransactionType: ${tx.TransactionType}`,

View File

@@ -1,60 +0,0 @@
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

@@ -1,83 +0,0 @@
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

@@ -1,65 +0,0 @@
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

@@ -1,93 +0,0 @@
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

@@ -1,92 +0,0 @@
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

@@ -20,6 +20,7 @@ import {
PaymentChannelClaimFlagsInterface,
PaymentChannelClaimFlags,
} from '../transactions/paymentChannelClaim'
import { SetHookFlagsInterface, SetHookFlags } from '../transactions/setHook'
import type { Transaction } from '../transactions/transaction'
import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet'
@@ -75,6 +76,15 @@ export function setTransactionFlagsToNumber(tx: Transaction): void {
case 'TrustSet':
tx.Flags = convertTrustSetFlagsToNumber(tx.Flags)
return
case 'SetHook':
tx.Flags = convertSetHookFlagsToNumber(tx.Flags)
tx.Hooks.forEach((h) => {
h.Hook.Flags = convertSetHookFlagsToNumber(
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- idk
h.Hook.Flags as SetHookFlagsInterface,
)
})
return
default:
tx.Flags = 0
}
@@ -108,6 +118,10 @@ function convertTrustSetFlagsToNumber(flags: TrustSetFlagsInterface): number {
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
function reduceFlags(flags: GlobalFlags, flagEnum: any): number {
return Object.keys(flags).reduce((resultFlags, flag) => {

View File

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

View File

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

View File

@@ -3,8 +3,8 @@
/* eslint-disable no-bitwise -- this file mimics behavior in rippled. It uses
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 { decode, encode } from '@transia/ripple-binary-codec'
import { ValidationError, XrplError } from '../../errors'
import type { Ledger } from '../../models/ledger'

View File

@@ -86,6 +86,14 @@ export async function hexNamespace(namespace: string): Promise<string> {
return (await sha256(namespace)).toUpperCase()
}
function isHex(value: string): boolean {
return /^[0-9A-F]+$/iu.test(value)
}
function hexValue(value: string): string {
return Buffer.from(value, 'utf8').toString('hex').toUpperCase()
}
/**
* Calculate the hex of the hook parameters
*
@@ -95,31 +103,21 @@ export async function hexNamespace(namespace: string): Promise<string> {
export function hexHookParameters(data: HookParameter[]): HookParameter[] {
const hookParameters: HookParameter[] = []
for (const parameter of data) {
let nameValue
let valueValue
// eslint-disable-next-line require-unicode-regexp -- Required
if (/^[0-9a-fA-F]{2,}$/.exec(parameter.HookParameter.HookParameterName)) {
nameValue = parameter.HookParameter.HookParameterName
} else {
nameValue = Buffer.from(parameter.HookParameter.HookParameterName, 'utf8')
.toString('hex')
.toUpperCase()
let hookPName = parameter.HookParameter.HookParameterName
let hookPValue = parameter.HookParameter.HookParameterValue
if (!isHex(hookPName)) {
hookPName = hexValue(hookPName)
}
// eslint-disable-next-line require-unicode-regexp -- Required
if (/^[0-9a-fA-F]{2,}$/.exec(parameter.HookParameter.HookParameterValue)) {
valueValue = parameter.HookParameter.HookParameterValue
} else {
valueValue = Buffer.from(
parameter.HookParameter.HookParameterValue,
'utf8',
)
.toString('hex')
.toUpperCase()
if (!isHex(hookPValue)) {
hookPValue = hexValue(hookPValue)
}
hookParameters.push({
HookParameter: {
HookParameterName: String(nameValue),
HookParameterValue: String(valueValue),
HookParameterName: hookPName,
HookParameterValue: hookPValue,
},
})
}

View File

@@ -1,5 +1,3 @@
import * as rbc from '@transia/ripple-binary-codec'
import { verify as verifyKeypairSignature } from '@transia/ripple-keypairs'
import {
classicAddressToXAddress,
decodeAccountID,
@@ -16,6 +14,8 @@ import {
isValidXAddress,
xAddressToClassicAddress,
} from '@transia/ripple-address-codec'
import * as rbc from '@transia/ripple-binary-codec'
import { verify as verifyKeypairSignature } from '@transia/ripple-keypairs'
import { LedgerEntry } from '../models/ledger'
import { Response } from '../models/methods'

View File

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