@hsuite/native-connect-angular 2.1.4 → 2.1.5

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.
@@ -7,7 +7,7 @@ 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';
@@ -3303,15 +3303,9 @@ class HederaSigner {
3303
3303
  },
3304
3304
  expiry: 300, // 5 minutes in seconds
3305
3305
  });
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`.
3312
3306
  return {
3313
- signedPayload: String(result.signedTransaction ||
3314
- result.signatureMap ||
3307
+ signedPayload: String(result.signatureMap ||
3308
+ result.signedTransaction ||
3315
3309
  JSON.stringify(result)),
3316
3310
  metadata: { result },
3317
3311
  };
@@ -3452,29 +3446,61 @@ class HederaSigner {
3452
3446
  * @returns Promise resolving to signature and metadata
3453
3447
  */
3454
3448
  async signMessage(params) {
3455
- // Extract network name from networkId (mainnet or testnet)
3456
- const network = params.networkId.includes('mainnet') ? 'mainnet' : 'testnet';
3449
+ // params.networkId IS the CAIP-2 chain id the session was approved for —
3450
+ // use it verbatim (substring sniffing mapped e.g. previewnet to testnet,
3451
+ // mis-routing the request AND mis-labelling the signed bytes).
3452
+ const caipChainId = params.networkId;
3457
3453
  // Format account ID in HIP-30 format
3458
- const signerAccountId = `hedera:${network}:${params.accountAddress}`;
3454
+ const signerAccountId = `${caipChainId}:${params.accountAddress}`;
3455
+ const encoding = params.encoding ?? 'utf-8';
3459
3456
  try {
3460
3457
  // Use 5-minute expiry to give users time to review and approve
3461
- const result = await params.client.request({
3458
+ const result = (await params.client.request({
3462
3459
  topic: params.topic,
3463
- chainId: `hedera:${network}`,
3460
+ chainId: caipChainId,
3464
3461
  request: {
3465
3462
  method: 'hedera_signMessage',
3466
3463
  params: {
3467
3464
  signerAccountId,
3468
- message: params.message, // Can be base64 or utf-8
3465
+ message: params.message,
3469
3466
  },
3470
3467
  },
3471
3468
  expiry: 300, // 5 minutes in seconds
3472
- });
3469
+ }));
3470
+ // The Hedera WalletConnect spec returns the signature as a base64
3471
+ // `proto.SignatureMap` under `signatureMap` (NOT `{ signature, publicKey }`),
3472
+ // signed over `\x19Hedera Signed Message:\n<len><msg>` — a DIFFERENT layout
3473
+ // from the native `hsc:` path's domain-separated blob. Decode it into the
3474
+ // §21.3 result shape and tag `signingScheme: 'hedera-wc'` (the map shape IS
3475
+ // that spec) so a verifier reconstructs the Hedera-standard bytes instead
3476
+ // of the HSuite blob. Without this, WalletConnect-signed auth challenges
3477
+ // are unverifiable and smart-host login silently fails while the native
3478
+ // path works.
3479
+ if (result.signatureMap) {
3480
+ const decoded = await decodeHederaSignatureMap(result.signatureMap);
3481
+ return {
3482
+ signature: decoded.signature,
3483
+ publicKey: decoded.publicKey ?? result.publicKey,
3484
+ algorithm: decoded.algorithm,
3485
+ encoding,
3486
+ caipChainId,
3487
+ signingScheme: 'hedera-wc',
3488
+ metadata: { result },
3489
+ };
3490
+ }
3491
+ // Fallback for non-standard wallets that return a flat `{ signature }`.
3492
+ // No spec shape to infer a byte layout from, so only a scheme the wallet
3493
+ // itself DECLARES (validated) is forwarded — guessing one would send the
3494
+ // verifier reconstructing bytes that were never signed.
3495
+ if (typeof result.signature !== 'string' || result.signature.length === 0) {
3496
+ throw new Error('wallet returned no signature');
3497
+ }
3473
3498
  return {
3474
- signature: String(result.signatureMap ||
3475
- result.signature ||
3476
- JSON.stringify(result)),
3499
+ signature: result.signature,
3477
3500
  publicKey: result.publicKey,
3501
+ caipChainId,
3502
+ encoding,
3503
+ signingScheme: isAuthSigningScheme(result.signingScheme) ? result.signingScheme : undefined,
3478
3504
  metadata: { result },
3479
3505
  };
3480
3506
  }
@@ -3874,22 +3900,42 @@ class XrplSigner {
3874
3900
  * @returns Promise resolving to signature and metadata
3875
3901
  */
3876
3902
  async signMessage(params) {
3903
+ // params.networkId IS the CAIP-2 chain id — it is what this request is
3904
+ // addressed to (`chainId` below), so it is what the wallet binds into the
3905
+ // signed blob. Re-deriving it by substring sniffing loses e.g. devnet.
3906
+ const caipChainId = params.networkId;
3907
+ const encoding = params.encoding ?? 'utf-8';
3877
3908
  try {
3878
3909
  // Use 5-minute expiry to give users time to review and approve
3879
- const result = await params.client.request({
3910
+ const result = (await params.client.request({
3880
3911
  topic: params.topic,
3881
3912
  chainId: params.networkId,
3882
3913
  request: {
3883
3914
  method: 'xrpl_signMessage',
3884
3915
  params: {
3885
- message: params.message, // Can be base64 or utf-8
3916
+ message: params.message,
3917
+ // Transmitted so the wallet decodes the same bytes this result
3918
+ // claims were signed — echoing an encoding the wallet never saw
3919
+ // would let the two sides sign and verify different byte strings.
3920
+ encoding,
3886
3921
  },
3887
3922
  },
3888
3923
  expiry: 300, // 5 minutes in seconds
3889
- });
3924
+ }));
3925
+ if (!result.signature) {
3926
+ throw new Error('wallet returned no signature');
3927
+ }
3928
+ // §21.3 verification fields: caipChainId binds the signed bytes to the
3929
+ // chain. The scheme is whatever the wallet DECLARES (an unknown value
3930
+ // degrades to undefined = the legacy `hsuite-domain` default, which is
3931
+ // also exactly what non-declaring older wallets signed).
3890
3932
  return {
3891
- signature: result.signature || JSON.stringify(result),
3933
+ signature: result.signature,
3892
3934
  publicKey: result.publicKey,
3935
+ algorithm: result.algorithm,
3936
+ encoding,
3937
+ caipChainId,
3938
+ signingScheme: isAuthSigningScheme(result.signingScheme) ? result.signingScheme : undefined,
3893
3939
  metadata: { result },
3894
3940
  };
3895
3941
  }
@@ -5953,8 +5999,14 @@ class P2PSessionManager {
5953
5999
  ledgerId: options.ledgerId,
5954
6000
  networkId: options.networkId,
5955
6001
  });
6002
+ // Fail closed: an empty signature is never a success. Coercing it to ''
6003
+ // would flow all the way into the smart-host verify POST and fail there
6004
+ // with a far less actionable error.
6005
+ if (!response.signature) {
6006
+ throw new Error('Wallet returned no signature for ledger/signMessage');
6007
+ }
5956
6008
  return {
5957
- signature: response.signature || '',
6009
+ signature: response.signature,
5958
6010
  publicKey: response.publicKey,
5959
6011
  algorithm: response.algorithm,
5960
6012
  encoding: response.encoding,
@@ -6704,9 +6756,16 @@ class P2PNativeProvider extends BaseWalletProvider {
6704
6756
  ledgerId: options.ledgerId,
6705
6757
  networkId: options.networkId,
6706
6758
  });
6759
+ // §21.3: forward the session manager's full result — dropping caipChainId
6760
+ // here breaks smart-host verification (the verifier needs the chain
6761
+ // binding to reconstruct the domain-separated signed bytes).
6707
6762
  return {
6708
6763
  signature: result.signature,
6709
6764
  publicKey: result.publicKey,
6765
+ algorithm: result.algorithm,
6766
+ encoding: result.encoding,
6767
+ caipChainId: result.caipChainId,
6768
+ messageLength: result.messageLength,
6710
6769
  metadata: result.metadata,
6711
6770
  };
6712
6771
  }
@@ -12154,6 +12213,12 @@ class SmartSessionService {
12154
12213
  caipChainId: signResult.caipChainId,
12155
12214
  ledgerId: account.ledgerId,
12156
12215
  networkId: account.networkId,
12216
+ // Only sent when it deviates from the legacy default (absent = native
12217
+ // `hsc:` domain-separated signing): a dApp-only upgrade must not add
12218
+ // unknown fields to the verify POST of already-deployed hosts.
12219
+ signingScheme: signResult.signingScheme && signResult.signingScheme !== 'hsuite-domain'
12220
+ ? signResult.signingScheme
12221
+ : undefined,
12157
12222
  };
12158
12223
  return firstValueFrom(this.http.post(`${this.baseUrl}${this.verifyEndpoint}`, payload));
12159
12224
  }