phantasma-sdk-ts 0.2.9 → 0.2.11

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.
@@ -62,6 +62,53 @@ class Transaction {
62
62
  sigs.push(sig);
63
63
  this.signatures = sigs;
64
64
  }
65
+ VerifySignature(address) {
66
+ // Verify that at least one stored signature matches the given address for the unsigned tx bytes.
67
+ if (!this.signatures || this.signatures.length === 0) {
68
+ return false;
69
+ }
70
+ const addr = typeof address === 'string' ? index_js_3.Address.FromText(address) : address;
71
+ const message = this.ToByteAray(false);
72
+ for (const sig of this.signatures) {
73
+ if (sig.Verify(message, addr)) {
74
+ return true;
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+ VerifySignatures(addresses) {
80
+ // Verify which of the provided addresses signed this transaction (no public-key recovery).
81
+ if (!this.signatures || this.signatures.length === 0 || !addresses || addresses.length === 0) {
82
+ return { ok: false, matched: [] };
83
+ }
84
+ const message = this.ToByteAray(false);
85
+ const matched = new Set();
86
+ for (const address of addresses) {
87
+ const addr = typeof address === 'string' ? index_js_3.Address.FromText(address) : address;
88
+ for (const sig of this.signatures) {
89
+ if (sig.Verify(message, addr)) {
90
+ matched.add(addr.Text);
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ const result = Array.from(matched);
96
+ return { ok: result.length > 0, matched: result };
97
+ }
98
+ GetUnsignedBytes() {
99
+ // Expose unsigned bytes for diagnostics and SDK-level verification helpers.
100
+ return this.ToByteAray(false);
101
+ }
102
+ GetSignatureInfo() {
103
+ // Return signature metadata without exposing signature contents.
104
+ if (!this.signatures || this.signatures.length === 0) {
105
+ return [];
106
+ }
107
+ return this.signatures.map((sig) => ({
108
+ kind: sig.Kind,
109
+ length: sig.Bytes ? sig.Bytes.length : 0,
110
+ }));
111
+ }
65
112
  ToByteAray(withSignature) {
66
113
  let writer = new index_js_3.PBinaryWriter();
67
114
  writer.writeString(this.nexusName);
@@ -123,7 +123,7 @@ class PBinaryReader {
123
123
  return null;
124
124
  case index_js_1.SignatureKind.Ed25519:
125
125
  let len = this.readVarInt();
126
- signature.Bytes = (0, index_js_2.stringToUint8Array)(this.read(len));
126
+ signature.Bytes = new Uint8Array(this.readBytes(len));
127
127
  break;
128
128
  case index_js_1.SignatureKind.ECDSA:
129
129
  curve = this.readByte();
@@ -5,7 +5,7 @@ import { Decoder, ScriptBuilder } from '../vm/index.js';
5
5
  import { bytesToHex, hexToBytes, getDifficulty, uint8ArrayToStringDefault } from '../utils/index.js';
6
6
  import hexEncoding from 'crypto-js/enc-hex.js';
7
7
  import SHA256 from 'crypto-js/sha256.js';
8
- import { Base16, PBinaryReader, PBinaryWriter, PhantasmaKeys } from '../types/index.js';
8
+ import { Address, Base16, PBinaryReader, PBinaryWriter, PhantasmaKeys } from '../types/index.js';
9
9
  import { getWifFromPrivateKey } from './utils.js';
10
10
  const curve = new eddsa('ed25519');
11
11
  export class Transaction {
@@ -56,6 +56,53 @@ export class Transaction {
56
56
  sigs.push(sig);
57
57
  this.signatures = sigs;
58
58
  }
59
+ VerifySignature(address) {
60
+ // Verify that at least one stored signature matches the given address for the unsigned tx bytes.
61
+ if (!this.signatures || this.signatures.length === 0) {
62
+ return false;
63
+ }
64
+ const addr = typeof address === 'string' ? Address.FromText(address) : address;
65
+ const message = this.ToByteAray(false);
66
+ for (const sig of this.signatures) {
67
+ if (sig.Verify(message, addr)) {
68
+ return true;
69
+ }
70
+ }
71
+ return false;
72
+ }
73
+ VerifySignatures(addresses) {
74
+ // Verify which of the provided addresses signed this transaction (no public-key recovery).
75
+ if (!this.signatures || this.signatures.length === 0 || !addresses || addresses.length === 0) {
76
+ return { ok: false, matched: [] };
77
+ }
78
+ const message = this.ToByteAray(false);
79
+ const matched = new Set();
80
+ for (const address of addresses) {
81
+ const addr = typeof address === 'string' ? Address.FromText(address) : address;
82
+ for (const sig of this.signatures) {
83
+ if (sig.Verify(message, addr)) {
84
+ matched.add(addr.Text);
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ const result = Array.from(matched);
90
+ return { ok: result.length > 0, matched: result };
91
+ }
92
+ GetUnsignedBytes() {
93
+ // Expose unsigned bytes for diagnostics and SDK-level verification helpers.
94
+ return this.ToByteAray(false);
95
+ }
96
+ GetSignatureInfo() {
97
+ // Return signature metadata without exposing signature contents.
98
+ if (!this.signatures || this.signatures.length === 0) {
99
+ return [];
100
+ }
101
+ return this.signatures.map((sig) => ({
102
+ kind: sig.Kind,
103
+ length: sig.Bytes ? sig.Bytes.length : 0,
104
+ }));
105
+ }
59
106
  ToByteAray(withSignature) {
60
107
  let writer = new PBinaryWriter();
61
108
  writer.writeString(this.nexusName);
@@ -117,7 +117,7 @@ export class PBinaryReader {
117
117
  return null;
118
118
  case SignatureKind.Ed25519:
119
119
  let len = this.readVarInt();
120
- signature.Bytes = stringToUint8Array(this.read(len));
120
+ signature.Bytes = new Uint8Array(this.readBytes(len));
121
121
  break;
122
122
  case SignatureKind.ECDSA:
123
123
  curve = this.readByte();
@@ -1,5 +1,5 @@
1
1
  import { ISerializable, Signature } from '../interfaces/index.js';
2
- import { PBinaryReader, PBinaryWriter, PhantasmaKeys } from '../types/index.js';
2
+ import { Address, PBinaryReader, PBinaryWriter, PhantasmaKeys } from '../types/index.js';
3
3
  export declare class Transaction implements ISerializable {
4
4
  script: string;
5
5
  nexusName: string;
@@ -14,6 +14,16 @@ export declare class Transaction implements ISerializable {
14
14
  sign(wif: string): void;
15
15
  signWithPrivateKey(privateKey: string): void;
16
16
  signWithKeys(keys: PhantasmaKeys): void;
17
+ VerifySignature(address: Address | string): boolean;
18
+ VerifySignatures(addresses: Array<Address | string>): {
19
+ ok: boolean;
20
+ matched: string[];
21
+ };
22
+ GetUnsignedBytes(): Uint8Array;
23
+ GetSignatureInfo(): Array<{
24
+ kind: number;
25
+ length: number;
26
+ }>;
17
27
  ToByteAray(withSignature: boolean): Uint8Array;
18
28
  UnserializeData(reader: PBinaryReader): void;
19
29
  SerializeData(writer: PBinaryWriter): void;
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../../../src/core/tx/Transaction.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAc,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAU,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIxF,qBAAa,WAAY,YAAW,aAAa;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;WAEC,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,WAAW;gBAM1D,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EAAE,sBAAsB;IACtC,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,MAAM;IAUV,IAAI,CAAC,GAAG,EAAE,MAAM;IAehB,kBAAkB,CAAC,UAAU,EAAE,MAAM;IAYrC,YAAY,CAAC,IAAI,EAAE,aAAa;IAYhC,UAAU,CAAC,aAAa,EAAE,OAAO,GAAG,UAAU;IAmB9C,eAAe,CAAC,MAAM,EAAE,aAAa;IAcrC,aAAa,CAAC,MAAM,EAAE,aAAa;IAYnC,QAAQ,CAAC,aAAa,EAAE,OAAO,GAAG,MAAM;IA8CxC,eAAe,CAAC,aAAa,EAAE,OAAO,GAAG,MAAM;IAI/C,OAAO;IAMP,eAAe,CAAC,UAAU,EAAE,MAAM;IAkCzC,OAAO,CAAC,OAAO;IASR,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,WAAW;WAkBzC,WAAW,CAAC,UAAU,EAAE,UAAU;CAMjD"}
1
+ {"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../../../src/core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,EAAE,OAAO,GAAG,MAAM;IA8CxC,eAAe,CAAC,aAAa,EAAE,OAAO,GAAG,MAAM;IAI/C,OAAO;IAMP,eAAe,CAAC,UAAU,EAAE,MAAM;IAkCzC,OAAO,CAAC,OAAO;IASR,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,WAAW;WAkBzC,WAAW,CAAC,UAAU,EAAE,UAAU;CAMjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core/tx/utils.ts"],"names":[],"mappings":"AAuBA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASrD;AAED,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAWxC;AAED,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAY/C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAUvC;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAQnE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAMnF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core/tx/utils.ts"],"names":[],"mappings":"AAsBA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASrD;AAED,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAWxC;AAED,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAY/C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAUvC;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAQnE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAMnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phantasma-sdk-ts",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Typescript SDK for interacting with the Phantasma Chain",
5
5
  "author": "Phantasma Team",
6
6
  "main": "dist/cjs/index.js",
@@ -74,7 +74,6 @@
74
74
  "crypto-js": "^4.2.0",
75
75
  "csharp-binary-stream": "^1.1.0",
76
76
  "elliptic": "^6.6.1",
77
- "ethereumjs-wallet": "^1.0.2",
78
77
  "tiny-secp256k1": "^2.2.4",
79
78
  "wif": "^2.0.6"
80
79
  },