@hsuite/native-connect-angular 2.1.4 → 2.1.6

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.
package/dist/LICENSE ADDED
@@ -0,0 +1,146 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree
8
+ to them as both strict obligations and conditions to all
9
+ your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the
14
+ software to do everything you might do with the software
15
+ that would otherwise infringe the licensor's copyright
16
+ in it for any permitted purpose. However, you may
17
+ only distribute the software according to [Distribution
18
+ License](#distribution-license) and make changes or new works
19
+ based on the software according to [Changes and New Works
20
+ License](#changes-and-new-works-license).
21
+
22
+ ## Distribution License
23
+
24
+ The licensor grants you an additional copyright license
25
+ to distribute copies of the software. Your license
26
+ to distribute covers distributing the software with
27
+ changes and new works permitted by [Changes and New Works
28
+ License](#changes-and-new-works-license).
29
+
30
+ ## Notices
31
+
32
+ You must ensure that anyone who gets a copy of any part of
33
+ the software from you also gets a copy of these terms or the
34
+ URL for them above, as well as copies of any plain-text lines
35
+ beginning with `Required Notice:` that the licensor provided
36
+ with the software. For example:
37
+
38
+ > Required Notice: Copyright HSuite (https://hsuite.finance)
39
+
40
+ ## Changes and New Works License
41
+
42
+ The licensor grants you an additional copyright license to
43
+ make changes and new works based on the software for any
44
+ permitted purpose.
45
+
46
+ ## Patent License
47
+
48
+ The licensor grants you a patent license for the software that
49
+ covers patent claims the licensor can license, or becomes able
50
+ to license, that you would infringe by using the software.
51
+
52
+ ## Noncommercial Purposes
53
+
54
+ Any noncommercial purpose is a permitted purpose.
55
+
56
+ ## Personal Uses
57
+
58
+ Personal use for research, experiment, and testing for
59
+ the benefit of public knowledge, personal study, private
60
+ entertainment, hobby projects, amateur pursuits, or religious
61
+ observance, without any anticipated commercial application,
62
+ is use for a permitted purpose.
63
+
64
+ ## Noncommercial Organizations
65
+
66
+ Use by any charitable organization, educational institution,
67
+ public research organization, public safety or health
68
+ organization, environmental protection organization,
69
+ or government institution is use for a permitted purpose
70
+ regardless of the source of funding or obligations resulting
71
+ from the funding.
72
+
73
+ ## Fair Use
74
+
75
+ You may have "fair use" rights for the software under the
76
+ law. These terms do not limit them.
77
+
78
+ ## No Other Rights
79
+
80
+ These terms do not allow you to sublicense or transfer any of
81
+ your licenses to anyone else, or prevent the licensor from
82
+ granting licenses to anyone else. These terms do not imply
83
+ any other licenses.
84
+
85
+ ## Patent Defense
86
+
87
+ If you make any written claim that the software infringes or
88
+ contributes to infringement of any patent, your patent license
89
+ for the software granted under these terms ends immediately. If
90
+ your company makes such a claim, your patent license ends
91
+ immediately for work on behalf of your company.
92
+
93
+ ## Violations
94
+
95
+ The first time you are notified in writing that you have
96
+ violated any of these terms, or done anything with the software
97
+ not covered by your licenses, your licenses can nonetheless
98
+ continue if you come into full compliance with these terms,
99
+ and take practical steps to correct past violations, within
100
+ 32 days of receiving notice. Otherwise, all your licenses
101
+ end immediately.
102
+
103
+ ## No Liability
104
+
105
+ ***As far as the law allows, the software comes as is, without
106
+ any warranty or condition, and the licensor will not be liable
107
+ to you for any damages arising out of these terms or the use
108
+ or nature of the software, under any kind of legal claim.***
109
+
110
+ ## Definitions
111
+
112
+ The **licensor** is the entity offering these terms, and the
113
+ **software** is the software the licensor makes available under
114
+ these terms.
115
+
116
+ **You** refers to the individual or entity agreeing to these
117
+ terms.
118
+
119
+ **Your company** is any legal entity, sole proprietorship,
120
+ or other kind of organization that you work for, plus all
121
+ organizations that have control over, are under the control of,
122
+ or are under common control with that organization. **Control**
123
+ means ownership of substantially all the assets of an entity,
124
+ or the power to direct its management and policies by vote,
125
+ contract, or otherwise. Control can be direct or indirect.
126
+
127
+ **Your licenses** are all the licenses granted to you for the
128
+ software under these terms.
129
+
130
+ **Use** means anything you do with the software requiring one
131
+ of your licenses.
132
+
133
+ ---
134
+
135
+ Required Notice: Copyright 2024-2025 HSuite (https://hsuite.finance)
136
+
137
+ ## Commercial Licensing
138
+
139
+ For commercial use of HSuite Native Connect, please contact:
140
+ - Email: licensing@hsuite.finance
141
+ - Website: https://hsuite.finance/licensing
142
+
143
+ Commercial licenses are available for:
144
+ - Integration into commercial products
145
+ - Enterprise deployments
146
+ - Reselling or redistribution as part of commercial offerings
@@ -7,11 +7,12 @@ import { Platform, IonicModule } from '@ionic/angular';
7
7
  import { IonButton, IonIcon, IonBadge, IonSpinner, AlertController, ToastController, ModalController, IonContent, IonText, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonList, IonItem, IonLabel } from '@ionic/angular/standalone';
8
8
  import { addIcons } from 'ionicons';
9
9
  import { addOutline, addCircleOutline, linkOutline, chevronDownOutline, personOutline, peopleOutline, alertCircleOutline, walletOutline, closeOutline, phonePortraitOutline, checkmarkCircle, qrCodeOutline, openOutline, extensionPuzzleOutline, checkmarkOutline, copyOutline, timeOutline, arrowBackOutline, closeCircleOutline, checkmarkCircleOutline, refreshOutline, syncOutline, flashOutline, cloudOutline, wifiOutline, fingerPrintOutline, globeOutline, hourglassOutline } from 'ionicons/icons';
10
- import { getLogger, ChannelClient, encodeChannelInvite, LocalDiscoveryService, XrplTransactionEncoder } from '@hsuite/native-connect-sdk';
10
+ import { getLogger, ChannelClient, encodeChannelInvite, LocalDiscoveryService, decodeHederaSignatureMap, isAuthSigningScheme, XrplTransactionEncoder } from '@hsuite/native-connect-sdk';
11
11
  export { HederaTransactionEncoder, XrplTransactionEncoder } from '@hsuite/native-connect-sdk';
12
12
  import { WalletConnectModal } from '@walletconnect/modal';
13
13
  import SignClient from '@walletconnect/sign-client';
14
14
  import { toObservable } from '@angular/core/rxjs-interop';
15
+ import { copyToClipboard } from '@hsuite/native-connect-ui';
15
16
  import * as QRCode from 'qrcode';
16
17
  import { Subscription, firstValueFrom, catchError, from, switchMap, throwError } from 'rxjs';
17
18
  import { HttpClient, HttpErrorResponse } from '@angular/common/http';
@@ -3303,12 +3304,12 @@ class HederaSigner {
3303
3304
  },
3304
3305
  expiry: 300, // 5 minutes in seconds
3305
3306
  });
3306
- // #482: prefer the full signed transaction. When the wallet returns a
3307
- // `signedTransaction` (base64 proto.TransactionList), `signedPayload` carries a
3308
- // complete signed protobuf the consuming dApp can relay directly (server-side
3309
- // broadcast) instead of reassembling one from a bare SignatureMap with
3310
- // @hashgraph/sdk. Fall back to `signatureMap` for HIP-820 wallets that only
3311
- // return the sign-only shape (back-compat). Raw `result` stays under `metadata.result`.
3307
+ // Prefer the FULL signed transaction (base64 proto.TransactionList) when the
3308
+ // wallet provides it: `signedPayload` then carries a complete signed protobuf
3309
+ // the consuming dApp can relay directly (server-side broadcast), instead of a
3310
+ // bare SignatureMap it would have to reassemble with @hashgraph/sdk. Fall back
3311
+ // to `signatureMap` for HIP-820 wallets that only return the sign-only shape
3312
+ // (back-compat). Raw `result` is always preserved under `metadata.result`.
3312
3313
  return {
3313
3314
  signedPayload: String(result.signedTransaction ||
3314
3315
  result.signatureMap ||
@@ -3452,29 +3453,61 @@ class HederaSigner {
3452
3453
  * @returns Promise resolving to signature and metadata
3453
3454
  */
3454
3455
  async signMessage(params) {
3455
- // Extract network name from networkId (mainnet or testnet)
3456
- const network = params.networkId.includes('mainnet') ? 'mainnet' : 'testnet';
3456
+ // params.networkId IS the CAIP-2 chain id the session was approved for —
3457
+ // use it verbatim (substring sniffing mapped e.g. previewnet to testnet,
3458
+ // mis-routing the request AND mis-labelling the signed bytes).
3459
+ const caipChainId = params.networkId;
3457
3460
  // Format account ID in HIP-30 format
3458
- const signerAccountId = `hedera:${network}:${params.accountAddress}`;
3461
+ const signerAccountId = `${caipChainId}:${params.accountAddress}`;
3462
+ const encoding = params.encoding ?? 'utf-8';
3459
3463
  try {
3460
3464
  // Use 5-minute expiry to give users time to review and approve
3461
- const result = await params.client.request({
3465
+ const result = (await params.client.request({
3462
3466
  topic: params.topic,
3463
- chainId: `hedera:${network}`,
3467
+ chainId: caipChainId,
3464
3468
  request: {
3465
3469
  method: 'hedera_signMessage',
3466
3470
  params: {
3467
3471
  signerAccountId,
3468
- message: params.message, // Can be base64 or utf-8
3472
+ message: params.message,
3469
3473
  },
3470
3474
  },
3471
3475
  expiry: 300, // 5 minutes in seconds
3472
- });
3476
+ }));
3477
+ // The Hedera WalletConnect spec returns the signature as a base64
3478
+ // `proto.SignatureMap` under `signatureMap` (NOT `{ signature, publicKey }`),
3479
+ // signed over `\x19Hedera Signed Message:\n<len><msg>` — a DIFFERENT layout
3480
+ // from the native `hsc:` path's domain-separated blob. Decode it into the
3481
+ // §21.3 result shape and tag `signingScheme: 'hedera-wc'` (the map shape IS
3482
+ // that spec) so a verifier reconstructs the Hedera-standard bytes instead
3483
+ // of the HSuite blob. Without this, WalletConnect-signed auth challenges
3484
+ // are unverifiable and smart-host login silently fails while the native
3485
+ // path works.
3486
+ if (result.signatureMap) {
3487
+ const decoded = await decodeHederaSignatureMap(result.signatureMap);
3488
+ return {
3489
+ signature: decoded.signature,
3490
+ publicKey: decoded.publicKey ?? result.publicKey,
3491
+ algorithm: decoded.algorithm,
3492
+ encoding,
3493
+ caipChainId,
3494
+ signingScheme: 'hedera-wc',
3495
+ metadata: { result },
3496
+ };
3497
+ }
3498
+ // Fallback for non-standard wallets that return a flat `{ signature }`.
3499
+ // No spec shape to infer a byte layout from, so only a scheme the wallet
3500
+ // itself DECLARES (validated) is forwarded — guessing one would send the
3501
+ // verifier reconstructing bytes that were never signed.
3502
+ if (typeof result.signature !== 'string' || result.signature.length === 0) {
3503
+ throw new Error('wallet returned no signature');
3504
+ }
3473
3505
  return {
3474
- signature: String(result.signatureMap ||
3475
- result.signature ||
3476
- JSON.stringify(result)),
3506
+ signature: result.signature,
3477
3507
  publicKey: result.publicKey,
3508
+ caipChainId,
3509
+ encoding,
3510
+ signingScheme: isAuthSigningScheme(result.signingScheme) ? result.signingScheme : undefined,
3478
3511
  metadata: { result },
3479
3512
  };
3480
3513
  }
@@ -3874,22 +3907,42 @@ class XrplSigner {
3874
3907
  * @returns Promise resolving to signature and metadata
3875
3908
  */
3876
3909
  async signMessage(params) {
3910
+ // params.networkId IS the CAIP-2 chain id — it is what this request is
3911
+ // addressed to (`chainId` below), so it is what the wallet binds into the
3912
+ // signed blob. Re-deriving it by substring sniffing loses e.g. devnet.
3913
+ const caipChainId = params.networkId;
3914
+ const encoding = params.encoding ?? 'utf-8';
3877
3915
  try {
3878
3916
  // Use 5-minute expiry to give users time to review and approve
3879
- const result = await params.client.request({
3917
+ const result = (await params.client.request({
3880
3918
  topic: params.topic,
3881
3919
  chainId: params.networkId,
3882
3920
  request: {
3883
3921
  method: 'xrpl_signMessage',
3884
3922
  params: {
3885
- message: params.message, // Can be base64 or utf-8
3923
+ message: params.message,
3924
+ // Transmitted so the wallet decodes the same bytes this result
3925
+ // claims were signed — echoing an encoding the wallet never saw
3926
+ // would let the two sides sign and verify different byte strings.
3927
+ encoding,
3886
3928
  },
3887
3929
  },
3888
3930
  expiry: 300, // 5 minutes in seconds
3889
- });
3931
+ }));
3932
+ if (!result.signature) {
3933
+ throw new Error('wallet returned no signature');
3934
+ }
3935
+ // §21.3 verification fields: caipChainId binds the signed bytes to the
3936
+ // chain. The scheme is whatever the wallet DECLARES (an unknown value
3937
+ // degrades to undefined = the legacy `hsuite-domain` default, which is
3938
+ // also exactly what non-declaring older wallets signed).
3890
3939
  return {
3891
- signature: result.signature || JSON.stringify(result),
3940
+ signature: result.signature,
3892
3941
  publicKey: result.publicKey,
3942
+ algorithm: result.algorithm,
3943
+ encoding,
3944
+ caipChainId,
3945
+ signingScheme: isAuthSigningScheme(result.signingScheme) ? result.signingScheme : undefined,
3893
3946
  metadata: { result },
3894
3947
  };
3895
3948
  }
@@ -5953,8 +6006,14 @@ class P2PSessionManager {
5953
6006
  ledgerId: options.ledgerId,
5954
6007
  networkId: options.networkId,
5955
6008
  });
6009
+ // Fail closed: an empty signature is never a success. Coercing it to ''
6010
+ // would flow all the way into the smart-host verify POST and fail there
6011
+ // with a far less actionable error.
6012
+ if (!response.signature) {
6013
+ throw new Error('Wallet returned no signature for ledger/signMessage');
6014
+ }
5956
6015
  return {
5957
- signature: response.signature || '',
6016
+ signature: response.signature,
5958
6017
  publicKey: response.publicKey,
5959
6018
  algorithm: response.algorithm,
5960
6019
  encoding: response.encoding,
@@ -6704,9 +6763,16 @@ class P2PNativeProvider extends BaseWalletProvider {
6704
6763
  ledgerId: options.ledgerId,
6705
6764
  networkId: options.networkId,
6706
6765
  });
6766
+ // §21.3: forward the session manager's full result — dropping caipChainId
6767
+ // here breaks smart-host verification (the verifier needs the chain
6768
+ // binding to reconstruct the domain-separated signed bytes).
6707
6769
  return {
6708
6770
  signature: result.signature,
6709
6771
  publicKey: result.publicKey,
6772
+ algorithm: result.algorithm,
6773
+ encoding: result.encoding,
6774
+ caipChainId: result.caipChainId,
6775
+ messageLength: result.messageLength,
6710
6776
  metadata: result.metadata,
6711
6777
  };
6712
6778
  }
@@ -8818,84 +8884,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
8818
8884
  args: [{ providedIn: 'root' }]
8819
8885
  }] });
8820
8886
 
8821
- /**
8822
- * HSuite Native Connect
8823
- * Copyright 2024-2025 HSuite (https://hsuite.finance)
8824
- *
8825
- * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
8826
- *
8827
- * This file is part of HSuite Native Connect. For commercial licensing,
8828
- * visit https://hsuite.finance/licensing
8829
- */
8830
- /**
8831
- * @file SDK-local clipboard helper. Behavior-identical port of
8832
- * `copyToClipboard` from `@hsuite/native-connect-ui` (logging dropped): the
8833
- * connection modal's QR step was the ONLY thing pulling the entire ui
8834
- * design-system package into dApp builds — a utility function is not a
8835
- * reason to depend on 80+ components. Standalone dApps (ecosystem DEX) can
8836
- * now build without ui entirely.
8837
- */
8838
- /**
8839
- * Copy text to the clipboard: modern Clipboard API first, `execCommand`
8840
- * textarea fallback second (covers non-secure contexts and some PWA cases).
8841
- *
8842
- * @param text - Text to copy
8843
- * @returns True if the copy succeeded
8844
- */
8845
- async function copyToClipboard(text) {
8846
- if (navigator.clipboard?.writeText) {
8847
- try {
8848
- await navigator.clipboard.writeText(text);
8849
- return true;
8850
- }
8851
- catch {
8852
- // Clipboard API failed (permission denied, not in a secure context,
8853
- // etc.) — fall through to the legacy method.
8854
- }
8855
- }
8856
- return copyToClipboardFallback(text);
8857
- }
8858
- function copyToClipboardFallback(text) {
8859
- if (typeof document === 'undefined') {
8860
- return false;
8861
- }
8862
- const textarea = document.createElement('textarea');
8863
- // Style to make it invisible but still selectable.
8864
- textarea.value = text;
8865
- textarea.style.position = 'fixed';
8866
- textarea.style.left = '-9999px';
8867
- textarea.style.top = '-9999px';
8868
- textarea.style.opacity = '0';
8869
- textarea.style.pointerEvents = 'none';
8870
- textarea.setAttribute('readonly', ''); // Prevent mobile keyboard
8871
- textarea.setAttribute('aria-hidden', 'true');
8872
- document.body.appendChild(textarea);
8873
- try {
8874
- // iOS requires special handling: select via a range instead of select().
8875
- const isIOS = /ipad|iphone|ipod/i.test(navigator.userAgent);
8876
- if (isIOS) {
8877
- const range = document.createRange();
8878
- range.selectNodeContents(textarea);
8879
- const selection = window.getSelection();
8880
- if (selection) {
8881
- selection.removeAllRanges();
8882
- selection.addRange(range);
8883
- }
8884
- textarea.setSelectionRange(0, text.length);
8885
- }
8886
- else {
8887
- textarea.select();
8888
- }
8889
- return document.execCommand('copy');
8890
- }
8891
- catch {
8892
- return false;
8893
- }
8894
- finally {
8895
- document.body.removeChild(textarea);
8896
- }
8897
- }
8898
-
8899
8887
  /**
8900
8888
  * HSuite Native Connect
8901
8889
  * Copyright 2024-2025 HSuite (https://hsuite.finance)
@@ -12154,6 +12142,12 @@ class SmartSessionService {
12154
12142
  caipChainId: signResult.caipChainId,
12155
12143
  ledgerId: account.ledgerId,
12156
12144
  networkId: account.networkId,
12145
+ // Only sent when it deviates from the legacy default (absent = native
12146
+ // `hsc:` domain-separated signing): a dApp-only upgrade must not add
12147
+ // unknown fields to the verify POST of already-deployed hosts.
12148
+ signingScheme: signResult.signingScheme && signResult.signingScheme !== 'hsuite-domain'
12149
+ ? signResult.signingScheme
12150
+ : undefined,
12157
12151
  };
12158
12152
  return firstValueFrom(this.http.post(`${this.baseUrl}${this.verifyEndpoint}`, payload));
12159
12153
  }