mirror of
				https://github.com/Xahau/xahau.js.git
				synced 2025-11-04 04:55:48 +00:00 
			
		
		
		
	Merge branch 'main' into sidechain-2.5
This commit is contained in:
		
							
								
								
									
										7110
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										7110
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										20
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								package.json
									
									
									
									
									
								
							@@ -27,25 +27,25 @@
 | 
			
		||||
    "@types/node": "^14.18.35",
 | 
			
		||||
    "@types/puppeteer": "5.4.6",
 | 
			
		||||
    "@types/ws": "^8.2.0",
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^4.30.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^4.0.0",
 | 
			
		||||
    "@xrplf/eslint-config": "^1.6.0",
 | 
			
		||||
    "@xrplf/prettier-config": "^1.5.0",
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^5.28.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^5.28 .0",
 | 
			
		||||
    "@xrplf/eslint-config": "^1.9.1",
 | 
			
		||||
    "@xrplf/prettier-config": "^1.9.1",
 | 
			
		||||
    "assert": "^2.0.0",
 | 
			
		||||
    "buffer": "^6.0.2",
 | 
			
		||||
    "chai": "^4.3.4",
 | 
			
		||||
    "copyfiles": "^2.4.1",
 | 
			
		||||
    "crypto-browserify": "^3.12.0",
 | 
			
		||||
    "ejs": "^3.0.1",
 | 
			
		||||
    "eslint": "^7.5.0",
 | 
			
		||||
    "eslint": "^8.18.0",
 | 
			
		||||
    "eslint-plugin-array-func": "^3.1.7",
 | 
			
		||||
    "eslint-plugin-consistent-default-export-name": "^0.0.15",
 | 
			
		||||
    "eslint-plugin-eslint-comments": "^3.2.0",
 | 
			
		||||
    "eslint-plugin-import": "^2.24.1",
 | 
			
		||||
    "eslint-plugin-jsdoc": "^37.1.0",
 | 
			
		||||
    "eslint-plugin-import": "^2.26.0",
 | 
			
		||||
    "eslint-plugin-jsdoc": "^39.3.3",
 | 
			
		||||
    "eslint-plugin-node": "^11.1.0",
 | 
			
		||||
    "eslint-plugin-prettier": "^4.0.0",
 | 
			
		||||
    "eslint-plugin-tsdoc": "^0.2.14",
 | 
			
		||||
    "eslint-plugin-prettier": "^4.2.1",
 | 
			
		||||
    "eslint-plugin-tsdoc": "^0.2.16",
 | 
			
		||||
    "eventemitter2": "^6.0.0",
 | 
			
		||||
    "expect": "^29.3.1",
 | 
			
		||||
    "https-browserify": "^1.0.0",
 | 
			
		||||
@@ -76,6 +76,6 @@
 | 
			
		||||
  ],
 | 
			
		||||
  "engines": {
 | 
			
		||||
    "node": ">=12.0.0",
 | 
			
		||||
    "npm": ">=7.0.0 < 8.0.0"
 | 
			
		||||
    "npm": ">=7.0.0 < 9.0.0"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -39,6 +39,7 @@ module.exports = {
 | 
			
		||||
    'jsdoc/require-throws': 'off',
 | 
			
		||||
    'jsdoc/require-jsdoc': 'off',
 | 
			
		||||
    'jsdoc/require-param': 'off',
 | 
			
		||||
    'jsdoc/check-examples': 'off', // Not implemented in eslint 8
 | 
			
		||||
    'tsdoc/syntax': 'off',
 | 
			
		||||
    '@typescript-eslint/no-require-imports': 'off',
 | 
			
		||||
  },
 | 
			
		||||
 
 | 
			
		||||
@@ -80,6 +80,7 @@ module.exports = {
 | 
			
		||||
    'jsdoc/require-description-complete-sentence': 'off',
 | 
			
		||||
    'jsdoc/require-jsdoc': 'off',
 | 
			
		||||
    'jsdoc/check-tag-names': 'off',
 | 
			
		||||
    'jsdoc/check-examples': 'off', // Not implemented in eslint 8
 | 
			
		||||
    'jsdoc/require-returns': 'off',
 | 
			
		||||
    'jsdoc/require-hyphen-before-param-description': 'off',
 | 
			
		||||
    'jsdoc/require-description': 'off',
 | 
			
		||||
 
 | 
			
		||||
@@ -159,20 +159,22 @@ class ShaMapInner extends ShaMapNode {
 | 
			
		||||
   */
 | 
			
		||||
  addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void {
 | 
			
		||||
    assert.ok(index !== undefined)
 | 
			
		||||
    const nibble = index.nibblet(this.depth)
 | 
			
		||||
    const existing = this.branches[nibble]
 | 
			
		||||
    if (index !== undefined) {
 | 
			
		||||
      const nibble = index.nibblet(this.depth)
 | 
			
		||||
      const existing = this.branches[nibble]
 | 
			
		||||
 | 
			
		||||
    if (existing === undefined) {
 | 
			
		||||
      this.setBranch(nibble, leaf || new ShaMapLeaf(index, item))
 | 
			
		||||
    } else if (existing instanceof ShaMapLeaf) {
 | 
			
		||||
      const newInner = new ShaMapInner(this.depth + 1)
 | 
			
		||||
      newInner.addItem(existing.index, undefined, existing)
 | 
			
		||||
      newInner.addItem(index, item, leaf)
 | 
			
		||||
      this.setBranch(nibble, newInner)
 | 
			
		||||
    } else if (existing instanceof ShaMapInner) {
 | 
			
		||||
      existing.addItem(index, item, leaf)
 | 
			
		||||
    } else {
 | 
			
		||||
      throw new Error('invalid ShaMap.addItem call')
 | 
			
		||||
      if (existing === undefined) {
 | 
			
		||||
        this.setBranch(nibble, leaf || new ShaMapLeaf(index, item))
 | 
			
		||||
      } else if (existing instanceof ShaMapLeaf) {
 | 
			
		||||
        const newInner = new ShaMapInner(this.depth + 1)
 | 
			
		||||
        newInner.addItem(existing.index, undefined, existing)
 | 
			
		||||
        newInner.addItem(index, item, leaf)
 | 
			
		||||
        this.setBranch(nibble, newInner)
 | 
			
		||||
      } else if (existing instanceof ShaMapInner) {
 | 
			
		||||
        existing.addItem(index, item, leaf)
 | 
			
		||||
      } else {
 | 
			
		||||
        throw new Error('invalid ShaMap.addItem call')
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -50,6 +50,7 @@ module.exports = {
 | 
			
		||||
    'jsdoc/require-returns': 'off',
 | 
			
		||||
    'jsdoc/require-description-complete-sentence': 'off',
 | 
			
		||||
    'jsdoc/check-tag-names': 'off',
 | 
			
		||||
    'jsdoc/check-examples': 'off', // Not implemented in eslint 8
 | 
			
		||||
    'jsdoc/no-types': 'off',
 | 
			
		||||
    'tsdoc/syntax': 'off',
 | 
			
		||||
    'import/order': 'off',
 | 
			
		||||
 
 | 
			
		||||
@@ -86,15 +86,6 @@ class Wallet {
 | 
			
		||||
  public readonly classicAddress: string
 | 
			
		||||
  public readonly seed?: string
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Alias for wallet.classicAddress.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The wallet's classic address.
 | 
			
		||||
   */
 | 
			
		||||
  public get address(): string {
 | 
			
		||||
    return this.classicAddress
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Creates a new Wallet.
 | 
			
		||||
   *
 | 
			
		||||
@@ -120,6 +111,15 @@ class Wallet {
 | 
			
		||||
    this.seed = opts.seed
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Alias for wallet.classicAddress.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The wallet's classic address.
 | 
			
		||||
   */
 | 
			
		||||
  public get address(): string {
 | 
			
		||||
    return this.classicAddress
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Generates a new Wallet using a generated seed.
 | 
			
		||||
   *
 | 
			
		||||
 
 | 
			
		||||
@@ -74,6 +74,15 @@ export default class WSWrapper extends EventEmitter {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the ready state of the websocket.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The Websocket's ready state.
 | 
			
		||||
   */
 | 
			
		||||
  public get readyState(): number {
 | 
			
		||||
    return this.ws.readyState
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Closes the websocket.
 | 
			
		||||
   *
 | 
			
		||||
@@ -94,13 +103,4 @@ export default class WSWrapper extends EventEmitter {
 | 
			
		||||
  public send(message: string): void {
 | 
			
		||||
    this.ws.send(message)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the ready state of the websocket.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The Websocket's ready state.
 | 
			
		||||
   */
 | 
			
		||||
  public get readyState(): number {
 | 
			
		||||
    return this.ws.readyState
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -212,6 +212,24 @@ export class Connection extends EventEmitter {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Gets the state of the websocket.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The Websocket's ready state.
 | 
			
		||||
   */
 | 
			
		||||
  private get state(): WebsocketState {
 | 
			
		||||
    return this.ws ? this.ws.readyState : WebSocket.CLOSED
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns whether the server should be connected.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns Whether the server should be connected.
 | 
			
		||||
   */
 | 
			
		||||
  private get shouldBeConnected(): boolean {
 | 
			
		||||
    return this.ws !== null
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns whether the websocket is connected.
 | 
			
		||||
   *
 | 
			
		||||
@@ -367,7 +385,7 @@ export class Connection extends EventEmitter {
 | 
			
		||||
    return this.url ?? ''
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // eslint-disable-next-line @typescript-eslint/no-empty-function -- Does nothing on default
 | 
			
		||||
  // eslint-disable-next-line @typescript-eslint/no-empty-function, class-methods-use-this -- Does nothing on default
 | 
			
		||||
  public readonly trace: (id: string, message: string) => void = () => {}
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -410,24 +428,6 @@ export class Connection extends EventEmitter {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Gets the state of the websocket.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The Websocket's ready state.
 | 
			
		||||
   */
 | 
			
		||||
  private get state(): WebsocketState {
 | 
			
		||||
    return this.ws ? this.ws.readyState : WebSocket.CLOSED
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns whether the server should be connected.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns Whether the server should be connected.
 | 
			
		||||
   */
 | 
			
		||||
  private get shouldBeConnected(): boolean {
 | 
			
		||||
    return this.ws !== null
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Handler for what to do once the connection to the server is open.
 | 
			
		||||
   *
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
/* eslint-disable jsdoc/require-jsdoc -- Request has many aliases, but they don't need unique docs */
 | 
			
		||||
/* eslint-disable @typescript-eslint/member-ordering -- TODO: remove when instance methods aren't members */
 | 
			
		||||
/* eslint-disable max-lines -- Client is a large file w/ lots of imports/exports */
 | 
			
		||||
import * as assert from 'assert'
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,26 @@ class InnerNode extends Node {
 | 
			
		||||
    this.empty = true
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the hash of a LeafNode.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns Hash of the LeafNode.
 | 
			
		||||
   */
 | 
			
		||||
  public get hash(): string {
 | 
			
		||||
    if (this.empty) {
 | 
			
		||||
      return HEX_ZERO
 | 
			
		||||
    }
 | 
			
		||||
    let hex = ''
 | 
			
		||||
    for (let iter = 0; iter <= SLOT_MAX; iter++) {
 | 
			
		||||
      const child = this.leaves[iter]
 | 
			
		||||
      const hash: string = child == null ? HEX_ZERO : child.hash
 | 
			
		||||
      hex += hash
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const prefix = HashPrefix.INNER_NODE.toString(HEX)
 | 
			
		||||
    return sha512Half(prefix + hex)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Adds an item to the InnerNode.
 | 
			
		||||
   *
 | 
			
		||||
@@ -99,26 +119,6 @@ class InnerNode extends Node {
 | 
			
		||||
    }
 | 
			
		||||
    return this.leaves[slot]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the hash of a LeafNode.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns Hash of the LeafNode.
 | 
			
		||||
   */
 | 
			
		||||
  public get hash(): string {
 | 
			
		||||
    if (this.empty) {
 | 
			
		||||
      return HEX_ZERO
 | 
			
		||||
    }
 | 
			
		||||
    let hex = ''
 | 
			
		||||
    for (let iter = 0; iter <= SLOT_MAX; iter++) {
 | 
			
		||||
      const child = this.leaves[iter]
 | 
			
		||||
      const hash: string = child == null ? HEX_ZERO : child.hash
 | 
			
		||||
      hex += hash
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const prefix = HashPrefix.INNER_NODE.toString(HEX)
 | 
			
		||||
    return sha512Half(prefix + hex)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default InnerNode
 | 
			
		||||
 
 | 
			
		||||
@@ -28,18 +28,6 @@ class LeafNode extends Node {
 | 
			
		||||
    this.data = data
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Add item to Leaf.
 | 
			
		||||
   *
 | 
			
		||||
   * @param tag - Index of the Node.
 | 
			
		||||
   * @param node - Node to insert.
 | 
			
		||||
   * @throws When called, because LeafNodes cannot addItem.
 | 
			
		||||
   */
 | 
			
		||||
  public addItem(tag: string, node: Node): void {
 | 
			
		||||
    throw new XrplError('Cannot call addItem on a LeafNode')
 | 
			
		||||
    this.addItem(tag, node)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the hash of a LeafNode.
 | 
			
		||||
   *
 | 
			
		||||
@@ -64,6 +52,18 @@ class LeafNode extends Node {
 | 
			
		||||
        throw new XrplError('Tried to hash a SHAMap node of unknown type.')
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Add item to Leaf.
 | 
			
		||||
   *
 | 
			
		||||
   * @param tag - Index of the Node.
 | 
			
		||||
   * @param node - Node to insert.
 | 
			
		||||
   * @throws When called, because LeafNodes cannot addItem.
 | 
			
		||||
   */
 | 
			
		||||
  public addItem(tag: string, node: Node): void {
 | 
			
		||||
    throw new XrplError('Cannot call addItem on a LeafNode')
 | 
			
		||||
    this.addItem(tag, node)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default LeafNode
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,10 @@ import InnerNode from './InnerNode'
 | 
			
		||||
import LeafNode from './LeafNode'
 | 
			
		||||
import { NodeType } from './node'
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SHAMap is the hash structure used to model ledgers.
 | 
			
		||||
 * If the root hash is equivalent, that means all nodes should be equivalent as well.
 | 
			
		||||
 */
 | 
			
		||||
class SHAMap {
 | 
			
		||||
  public root: InnerNode
 | 
			
		||||
 | 
			
		||||
@@ -12,6 +16,15 @@ class SHAMap {
 | 
			
		||||
    this.root = new InnerNode(0)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the hash of the SHAMap.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The hash of the root of the SHAMap.
 | 
			
		||||
   */
 | 
			
		||||
  public get hash(): string {
 | 
			
		||||
    return this.root.hash
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Add an item to the SHAMap.
 | 
			
		||||
   *
 | 
			
		||||
@@ -22,15 +35,6 @@ class SHAMap {
 | 
			
		||||
  public addItem(tag: string, data: string, type: NodeType): void {
 | 
			
		||||
    this.root.addItem(tag, new LeafNode(tag, data, type))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the hash of the SHAMap.
 | 
			
		||||
   *
 | 
			
		||||
   * @returns The hash of the root of the SHAMap.
 | 
			
		||||
   */
 | 
			
		||||
  public get hash(): string {
 | 
			
		||||
    return this.root.hash
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export * from './node'
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,6 @@ export enum NodeType {
 | 
			
		||||
 * Abstract base class for SHAMapNode.
 | 
			
		||||
 */
 | 
			
		||||
export abstract class Node {
 | 
			
		||||
  public abstract addItem(_tag: string, _node: Node): void
 | 
			
		||||
  public abstract get hash(): string
 | 
			
		||||
  public abstract addItem(_tag: string, _node: Node): void
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,10 +14,7 @@
 | 
			
		||||
    "esModuleInterop": true,
 | 
			
		||||
    "suppressImplicitAnyIndexErrors": false,
 | 
			
		||||
    "resolveJsonModule": true,
 | 
			
		||||
    "preserveSymlinks": true,
 | 
			
		||||
    "preserveSymlinks": true
 | 
			
		||||
  },
 | 
			
		||||
  "include": [
 | 
			
		||||
    "src/**/*.ts",
 | 
			
		||||
    "src/**/*.json"
 | 
			
		||||
  ]
 | 
			
		||||
  "include": ["src/**/*.ts", "src/**/*.json"]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user