phantasma-sdk-ts 0.2.10 → 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);
@@ -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);
@@ -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,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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,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO;IAenD,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE;IAoBxF,gBAAgB,IAAI,UAAU;IAK9B,gBAAgB,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAW3D,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phantasma-sdk-ts",
3
- "version": "0.2.10",
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",