You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate-address.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.generateAddressAPI = void 0;
  7. const ripple_address_codec_1 = require("ripple-address-codec");
  8. const ripple_keypairs_1 = __importDefault(require("ripple-keypairs"));
  9. const common_1 = require("../common");
  10. function generateAddressAPI(options = {}) {
  11. common_1.validate.generateAddress({ options });
  12. try {
  13. const generateSeedOptions = {
  14. algorithm: options.algorithm
  15. };
  16. if (options.entropy) {
  17. generateSeedOptions.entropy = Uint8Array.from(options.entropy);
  18. }
  19. const secret = ripple_keypairs_1.default.generateSeed(generateSeedOptions);
  20. const keypair = ripple_keypairs_1.default.deriveKeypair(secret);
  21. const classicAddress = ripple_keypairs_1.default.deriveAddress(keypair.publicKey);
  22. const returnValue = {
  23. xAddress: ripple_address_codec_1.classicAddressToXAddress(classicAddress, false, options && options.test),
  24. secret
  25. };
  26. if (options.includeClassicAddress) {
  27. returnValue.classicAddress = classicAddress;
  28. returnValue.address = classicAddress;
  29. }
  30. return returnValue;
  31. }
  32. catch (error) {
  33. throw new common_1.errors.UnexpectedError(error.message);
  34. }
  35. }
  36. exports.generateAddressAPI = generateAddressAPI;
  37. //# sourceMappingURL=generate-address.js.map