@exodus/bip322-js 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +13 -13
  3. package/dist/BIP322.d.ts +2 -33
  4. package/dist/BIP322.js +23 -103
  5. package/dist/BIP322.js.map +1 -0
  6. package/dist/Signer.d.ts +1 -20
  7. package/dist/Signer.js +32 -97
  8. package/dist/Signer.js.map +1 -0
  9. package/dist/Verifier.d.ts +0 -39
  10. package/dist/Verifier.js +60 -175
  11. package/dist/Verifier.js.map +1 -0
  12. package/dist/bitcoinjs/DecodeScriptSignature.d.ts +0 -1
  13. package/dist/bitcoinjs/DecodeScriptSignature.js +1 -7
  14. package/dist/bitcoinjs/DecodeScriptSignature.js.map +1 -0
  15. package/dist/bitcoinjs/index.d.ts +1 -2
  16. package/dist/bitcoinjs/index.js +1 -5
  17. package/dist/bitcoinjs/index.js.map +1 -0
  18. package/dist/helpers/Address.d.ts +2 -49
  19. package/dist/helpers/Address.js +57 -156
  20. package/dist/helpers/Address.js.map +1 -0
  21. package/dist/helpers/BIP137.d.ts +0 -21
  22. package/dist/helpers/BIP137.js +6 -61
  23. package/dist/helpers/BIP137.js.map +1 -0
  24. package/dist/helpers/VarInt.d.ts +0 -17
  25. package/dist/helpers/VarInt.js +11 -40
  26. package/dist/helpers/VarInt.js.map +1 -0
  27. package/dist/helpers/VarStr.d.ts +0 -17
  28. package/dist/helpers/VarStr.js +5 -32
  29. package/dist/helpers/VarStr.js.map +1 -0
  30. package/dist/helpers/Witness.d.ts +0 -18
  31. package/dist/helpers/Witness.js +10 -47
  32. package/dist/helpers/Witness.js.map +1 -0
  33. package/dist/helpers/index.d.ts +5 -6
  34. package/dist/helpers/index.js +5 -16
  35. package/dist/helpers/index.js.map +1 -0
  36. package/dist/index.d.ts +5 -5
  37. package/dist/index.js +5 -17
  38. package/dist/index.js.map +1 -0
  39. package/package.json +53 -44
@@ -1,70 +1,33 @@
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
- // Import dependencies
7
- const VarInt_1 = __importDefault(require("./VarInt"));
8
- const VarStr_1 = __importDefault(require("./VarStr"));
9
- /**
10
- * Class that implement witness data serialization and deserialization.
11
- */
1
+ import VarInt from './VarInt.js';
2
+ import VarStr from './VarStr.js';
12
3
  class Witness {
13
- /**
14
- * Encode array of witness into its base-64 encoded format.
15
- * Follows the encoding scheme found in buidl-python:
16
- * https://github.com/buidl-bitcoin/buidl-python/blob/d79e9808e8ca60975d315be41293cb40d968626d/buidl/witness.py#L35
17
- * @param witnesses Array of witness data
18
- * @returns Base-64 encoded witness data
19
- */
20
4
  static serialize(witnesses) {
21
- // The first element to be included is the length of the witness array as VarInt
22
- let witnessStack = VarInt_1.default.encode(witnesses.length);
23
- // Then, for each witness array,
5
+ let witnessStack = VarInt.encode(witnesses.length);
24
6
  witnesses.forEach((witness) => {
25
- // Append each witness as a VarStr to the witness stack
26
- witnessStack = Buffer.concat([witnessStack, VarStr_1.default.encode(Buffer.from(witness))]);
7
+ witnessStack = Buffer.concat([witnessStack, VarStr.encode(Buffer.from(witness))]);
27
8
  });
28
- // Return the base-64 encoded witness stack
29
9
  return witnessStack.toString('base64');
30
10
  }
31
- /**
32
- * Decode encoded witness data, either as a base-64 encoded string or as a decoded string in a buffer, into an array of witness.
33
- * Follows the decoding scheme found in buidl-python:
34
- * https://github.com/buidl-bitcoin/buidl-python/blob/d79e9808e8ca60975d315be41293cb40d968626d/buidl/witness.py#L62
35
- * @param encodedWitness Base-64 encoded witness data, or encoded witness data that have already been decoded
36
- * @returns Decoded witness data
37
- */
38
11
  static deserialize(encodedWitness) {
39
- // Store the decoded witness stack
40
- let witnessDecoded = [];
41
- // Preprocess the encodedWitness if needed
12
+ const witnessDecoded = [];
42
13
  let witnessToDecode;
43
14
  if (typeof encodedWitness === 'string') {
44
- // Decode the encoded witness if it is a string (assuming it is encoded using base-64)
45
15
  witnessToDecode = Buffer.from(encodedWitness, 'base64');
46
16
  }
47
17
  else {
48
18
  witnessToDecode = encodedWitness;
49
19
  }
50
- // Read a VarInt which indicate the number of elements within the original witness array
51
- const witnessCount = VarInt_1.default.decode(witnessToDecode);
52
- // Slice the VarInt in front of the witness buffer before decoding each witness
53
- const varIntLength = VarInt_1.default.encode(witnessCount).byteLength;
20
+ const witnessCount = VarInt.decode(witnessToDecode);
21
+ const varIntLength = VarInt.encode(witnessCount).byteLength;
54
22
  witnessToDecode = witnessToDecode.subarray(varIntLength);
55
- // Loop for each witness encoded
56
23
  for (let i = 0; i < witnessCount; i++) {
57
- // Read a VarStr from the remaining buffer
58
- const witness = VarStr_1.default.decode(witnessToDecode);
59
- // Append the decoded witness to witnessDecoded
24
+ const witness = VarStr.decode(witnessToDecode);
60
25
  witnessDecoded.push(witness);
61
- // Slice the read witness off witnessToDecode before next iteration
62
- const witnessLength = VarStr_1.default.encode(witness).byteLength;
26
+ const witnessLength = VarStr.encode(witness).byteLength;
63
27
  witnessToDecode = witnessToDecode.subarray(witnessLength);
64
28
  }
65
- // Return deserialized witness data
66
29
  return witnessDecoded;
67
30
  }
68
31
  }
69
- exports.default = Witness;
32
+ export default Witness;
70
33
  //# sourceMappingURL=Witness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Witness.js","sourceRoot":"","sources":["../../src/helpers/Witness.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,MAAM,MAAM,aAAa,CAAA;AAKhC,MAAM,OAAO;IAQJ,MAAM,CAAC,SAAS,CAAC,SAAuB;QAE7C,IAAI,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAElD,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAE5B,YAAY,GAAG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from "./VarStr";
5
- import Witness from "./Witness";
6
- export { Address, BIP137, VarInt, VarStr, Witness };
1
+ export { default as Address } from './Address.js';
2
+ export { default as VarInt } from './VarInt.js';
3
+ export { default as BIP137 } from './BIP137.js';
4
+ export { default as Witness } from './Witness.js';
5
+ export { default as VarStr } from './VarStr.js';
@@ -1,17 +1,6 @@
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.Witness = exports.VarStr = exports.VarInt = exports.BIP137 = exports.Address = void 0;
7
- const Address_1 = __importDefault(require("./Address"));
8
- exports.Address = Address_1.default;
9
- const BIP137_1 = __importDefault(require("./BIP137"));
10
- exports.BIP137 = BIP137_1.default;
11
- const VarInt_1 = __importDefault(require("./VarInt"));
12
- exports.VarInt = VarInt_1.default;
13
- const VarStr_1 = __importDefault(require("./VarStr"));
14
- exports.VarStr = VarStr_1.default;
15
- const Witness_1 = __importDefault(require("./Witness"));
16
- exports.Witness = Witness_1.default;
1
+ export { default as Address } from './Address.js';
2
+ export { default as VarInt } from './VarInt.js';
3
+ export { default as BIP137 } from './BIP137.js';
4
+ export { default as Witness } from './Witness.js';
5
+ export { default as VarStr } from './VarStr.js';
17
6
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import BIP322 from "./BIP322";
2
- import Signer from "./Signer";
3
- import Verifier from "./Verifier";
4
- import { Witness, Address, BIP137 } from "./helpers";
5
- export { BIP322, Signer, Verifier, Witness, Address, BIP137 };
1
+ export { default as BIP322 } from './BIP322.js';
2
+ export { default as Signer } from './Signer.js';
3
+ export { Witness, Address } from './helpers/index.js';
4
+ export { default as Verifier } from './Verifier.js';
5
+ export { BIP137 } from './helpers/index.js';
package/dist/index.js CHANGED
@@ -1,18 +1,6 @@
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.BIP137 = exports.Address = exports.Witness = exports.Verifier = exports.Signer = exports.BIP322 = void 0;
7
- // Import modules to be exported
8
- const BIP322_1 = __importDefault(require("./BIP322"));
9
- exports.BIP322 = BIP322_1.default;
10
- const Signer_1 = __importDefault(require("./Signer"));
11
- exports.Signer = Signer_1.default;
12
- const Verifier_1 = __importDefault(require("./Verifier"));
13
- exports.Verifier = Verifier_1.default;
14
- const helpers_1 = require("./helpers");
15
- Object.defineProperty(exports, "Witness", { enumerable: true, get: function () { return helpers_1.Witness; } });
16
- Object.defineProperty(exports, "Address", { enumerable: true, get: function () { return helpers_1.Address; } });
17
- Object.defineProperty(exports, "BIP137", { enumerable: true, get: function () { return helpers_1.BIP137; } });
1
+ export { default as BIP322 } from './BIP322.js';
2
+ export { default as Signer } from './Signer.js';
3
+ export { Witness, Address } from './helpers/index.js';
4
+ export { default as Verifier } from './Verifier.js';
5
+ export { BIP137 } from './helpers/index.js';
18
6
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA"}
package/package.json CHANGED
@@ -1,46 +1,55 @@
1
1
  {
2
- "name": "@exodus/bip322-js",
3
- "version": "1.1.0",
4
- "description": "A Javascript library that provides utility functions related to the BIP-322 signature scheme",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "publishConfig": {
8
- "access": "restricted"
9
- },
10
- "scripts": {
11
- "build": "tsc",
12
- "doc": "typedoc src/index.ts",
13
- "prepack": "npm run build",
14
- "test": "jest",
15
- "test:coverage": "nyc --reporter=text --reporter=text-summary --reporter=lcov npm test"
16
- },
17
- "keywords": [
18
- "bip322",
19
- "bitcoinjs",
20
- "javascript",
21
- "typescript",
22
- "no-WASM"
23
- ],
24
- "author": "Ken Sze <acken2@outlook.com>",
25
- "repository": "https://github.com/ExodusMovement/bip322-js/",
26
- "license": "MIT",
27
- "devDependencies": {
28
- "@babel/core": "^7.22.20",
29
- "@babel/preset-env": "^7.22.20",
30
- "@babel/preset-flow": "^7.22.15",
31
- "@babel/preset-typescript": "^7.22.15",
32
- "@types/node": "^20.2.5",
33
- "@types/secp256k1": "^4.0.3",
34
- "babel-jest": "^29.7.0",
35
- "jest": "^29.7.0",
36
- "nyc": "^15.1.0",
37
- "typedoc": "^0.24.8",
38
- "typescript": "^5.1.3"
39
- },
40
- "dependencies": {
41
- "@exodus/secp256k1": "4.0.2-exodus.0",
42
- "@exodus/bitcoinjs-lib": "^6.1.6",
43
- "bitcoinjs-message": "^2.2.0",
44
- "ecpair": "^2.0.1"
45
- }
2
+ "name": "@exodus/bip322-js",
3
+ "version": "1.2.1",
4
+ "description": "A Javascript library that provides utility functions related to the BIP-322 signature scheme",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "publishConfig": {
9
+ "access": "restricted"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "CHANGELOG.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "lint": "eslint",
18
+ "lint:fix": "run lint --fix",
19
+ "doc": "typedoc src/index.ts",
20
+ "prepack": "npm run build",
21
+ "test": "run -T exodus-test --jest --esbuild",
22
+ "prepublishOnly": "yarn run -T build --scope @exodus/bip322-js"
23
+ },
24
+ "keywords": [
25
+ "bip322",
26
+ "bitcoinjs",
27
+ "javascript",
28
+ "typescript",
29
+ "no-WASM"
30
+ ],
31
+ "author": "Exodus Movement, Inc.",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
35
+ },
36
+ "license": "MIT",
37
+ "devDependencies": {
38
+ "@types/create-hash": "^1",
39
+ "@types/node": "^20.2.5",
40
+ "typedoc": "^0.24.8",
41
+ "typescript": "^5.1.3"
42
+ },
43
+ "dependencies": {
44
+ "@exodus/bitcoinerlab-secp256k1": "^1.0.5-exodus.1",
45
+ "@exodus/bitcoinjs": "^1.1.0",
46
+ "@exodus/secp256k1": "^4.0.2-exodus.0",
47
+ "bitcoinjs-message": "^2.2.0",
48
+ "create-hash": "^1.2.0"
49
+ },
50
+ "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/libraries/bip322-js",
51
+ "bugs": {
52
+ "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abip322-js"
53
+ },
54
+ "gitHead": "6a40d50082582568d68206d8926737eea560fa50"
46
55
  }