Skip to content

Commit

Permalink
test: stx_signMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Feb 7, 2025
1 parent 2562313 commit 5ad59a3
Show file tree
Hide file tree
Showing 26 changed files with 1,971 additions and 1,062 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@
"@hirosystems/token-metadata-api-client": "1.2.0",
"@hookform/resolvers": "3.9.1",
"@leather.io/analytics": "2.0.1",
"@leather.io/bitcoin": "0.19.18",
"@leather.io/bitcoin": "0.19.19",
"@leather.io/constants": "0.15.5",
"@leather.io/crypto": "1.6.34",
"@leather.io/crypto": "1.6.35",
"@leather.io/models": "0.25.1",
"@leather.io/query": "2.26.19",
"@leather.io/stacks": "1.5.19",
"@leather.io/tokens": "0.12.10",
"@leather.io/ui": "1.48.2",
"@leather.io/utils": "0.25.1",
"@leather.io/query": "2.26.21",
"@leather.io/stacks": "1.5.20",
"@leather.io/tokens": "0.12.11",
"@leather.io/ui": "1.48.3",
"@leather.io/utils": "0.25.2",
"@ledgerhq/hw-transport-webusb": "6.27.19",
"@noble/hashes": "1.5.0",
"@noble/secp256k1": "2.1.0",
Expand All @@ -173,7 +173,7 @@
"@sentry/tracing": "7.106.0",
"@stacks/auth": "7.0.2",
"@stacks/common": "7.0.2",
"@stacks/connect": "7.4.0",
"@stacks/connect-jwt": "npm:@stacks/connect@7.4.0",
"@stacks/encryption": "7.0.2",
"@stacks/network": "7.0.2",
"@stacks/network-v6": "npm:@stacks/[email protected]",
Expand Down Expand Up @@ -266,20 +266,20 @@
"@actions/core": "1.10.1",
"@chromatic-com/storybook": "3.2.2",
"@leather.io/eslint-config": "0.7.0",
"@leather.io/panda-preset": " 0.8.9",
"@leather.io/panda-preset": "0.8.10",
"@leather.io/prettier-config": "0.6.0",
"@leather.io/rpc": "2.5.5",
"@leather.io/rpc": "2.5.6",
"@ls-lint/ls-lint": "2.2.3",
"@mdx-js/loader": "3.0.0",
"@pandacss/dev": "0.46.1",
"@playwright/test": "1.48.2",
"@playwright/test": "1.50.1",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.13",
"@redux-devtools/cli": "4.0.0",
"@redux-devtools/remote": "0.9.3",
"@schemastore/web-manifest": "0.0.6",
"@sentry/react": "8.26.0",
"@sentry/webpack-plugin": "2.17.0",
"@stacks/connect-react": "22.2.0",
"@stacks/connect-react-jwt": "npm:@stacks/connect-react@22.2.0",
"@stacks/stacks-blockchain-api-types": "7.8.2",
"@storybook/addon-docs": "8.4.4",
"@storybook/addon-essentials": "8.4.4",
Expand Down
2,822 changes: 1,803 additions & 1,019 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/common/psbt/requests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TransactionInput } from '@scure/btc-signer/psbt';
import { PsbtPayload } from '@stacks/connect';
import { PsbtPayload } from '@stacks/connect-jwt';
import { decodeToken } from 'jsontokens';

import type { Money } from '@leather.io/models';
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/publish-subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Transaction } from '@scure/btc-signer';
import type { SignatureData } from '@stacks/connect';
import type { SignatureData } from '@stacks/connect-jwt';
import type { StacksTransactionWire } from '@stacks/transactions';
import type { StacksTransaction } from '@stacks/transactions-v6';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { SignatureData } from '@stacks/connect-jwt';
import isEqual from 'lodash.isequal';

import type { UnsignedMessage } from '@shared/signature/signature-types';
Expand All @@ -6,7 +7,7 @@ import { GlobalAppEvents, appEvents } from '@app/common/publish-subscribe';

export async function listenForStacksMessageSigning(
unsignedMessage: UnsignedMessage
): Promise<any> {
): Promise<SignatureData> {
return new Promise((resolve, reject) => {
function stacksMessageSignedHandler(msg: GlobalAppEvents['ledgerStacksMessageSigned']) {
if (isEqual(msg.unsignedMessage, unsignedMessage)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function StacksMessageSigning({
return (
<MessageSigningRequestLayout>
<MessageSigningHeader name={origin} origin={origin} />

{isUtf8MessageType(messageType) && payload.messageType === 'utf8' && (
<StacksSignatureRequestMessageContent
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createDelay } from '@shared/utils';

import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

export const improveUxWithShortDelayAsStacksSigningIsSoFast = createDelay(1000);
export const improveUxWithShortDelayAsStacksSigningIsSoFast = createDelay(600);

export function useMessageSignerStacksSoftwareWallet() {
const account = useCurrentStacksAccount();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { SignatureData } from '@stacks/connect';
import { SignatureData } from '@stacks/connect-jwt';

import { logger } from '@shared/logger';
import { UnsignedMessage } from '@shared/signature/signature-types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function useRpcStacksMessagePayload() {
appName,
} satisfies Utf8Payload;
}

if (isStructuredMessageType(messageType)) {
if (!domain) return null;

Expand Down Expand Up @@ -96,7 +97,10 @@ export function useRpcSignStacksMessage() {
tabId,
makeRpcSuccessResponse('stx_signMessage', {
id: requestId,
result: { signature: messageSignature.signature },
result: {
signature: messageSignature.signature,
publicKey: messageSignature.publicKey,
},
})
);
closeWindow();
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/swap/providers/use-stacks-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';

import { bytesToHex } from '@stacks/common';
import { type ContractCallPayload, TransactionTypes } from '@stacks/connect';
import { type ContractCallPayload, TransactionTypes } from '@stacks/connect-jwt';
import { PostConditionMode } from '@stacks/transactions';
import { serializeCV } from '@stacks/transactions-v6';
import type { RouteQuote } from 'bitflow-sdk';
Expand Down
2 changes: 1 addition & 1 deletion src/app/store/transactions/contract-call-v6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hexToBytes } from '@stacks/common';
import type { ContractCallPayload } from '@stacks/connect';
import type { ContractCallPayload } from '@stacks/connect-jwt';
import {
AnchorMode,
BytesReader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function rpcSignStacksMessage(
requestParams.push(['network', message.params.network.toString()]);
}

if (isDefined(message.params.domain)) {
if (isDefined('domain' in message.params && message.params.domain)) {
requestParams.push([
'domain',
(message.params as StxSignMessageRequestParamsStructured).domain.toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/inpage/inpage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StacksProvider } from '@stacks/connect';
import type { StacksProvider } from '@stacks/connect-jwt';

import { type LeatherRpcMethodMap, type RpcParameter, RpcRequest } from '@leather.io/rpc';

Expand Down
2 changes: 1 addition & 1 deletion src/shared/actions/finalize-message-signature-format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignatureData } from '@stacks/connect';
import { SignatureData } from '@stacks/connect-jwt';

import { ExternalMethods, MESSAGE_SOURCE, SignatureResponseMessage } from '@shared/message-types';

Expand Down
2 changes: 1 addition & 1 deletion src/shared/actions/finalize-message-signature.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignatureData } from '@stacks/connect';
import { SignatureData } from '@stacks/connect-jwt';

import { closeWindow } from '@shared/utils';

Expand Down
2 changes: 1 addition & 1 deletion src/shared/actions/finalize-psbt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PsbtData } from '@stacks/connect';
import { PsbtData } from '@stacks/connect-jwt';

import { ExternalMethods, MESSAGE_SOURCE, PsbtResponseMessage } from '@shared/message-types';
import { closeWindow } from '@shared/utils';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/crypto/sign-message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type PrivateKey, bytesToHex } from '@stacks/common';
import { SignatureData } from '@stacks/connect';
import { SignatureData } from '@stacks/connect-jwt';
import { hashMessage } from '@stacks/encryption';
import {
ClarityValue,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/message-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
PsbtData,
SignatureData,
SponsoredFinishedTxPayload,
} from '@stacks/connect';
} from '@stacks/connect-jwt';
import { PublicProfile } from '@stacks/profile';

export const MESSAGE_SOURCE = 'stacks-wallet' as const;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/legacy-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ContractDeployPayload as ConnectContractDeployPayload,
ProfileUpdatePayload as ConnectProfileUpdatePayload,
STXTransferPayload as ConnectSTXTransferPayload,
} from '@stacks/connect';
} from '@stacks/connect-jwt';
import type { StacksNetwork } from '@stacks/network';
import type { PostCondition, PostConditionWire } from '@stacks/transactions';
import { decodeToken } from 'jsontokens';
Expand Down
2 changes: 1 addition & 1 deletion test-app/src/common/use-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo } from 'react';

import { AppState, defaultState } from '@common/context';
import { AppConfig, UserSession } from '@stacks/auth';
import { AuthOptions } from '@stacks/connect';
import { AuthOptions } from '@stacks/connect-jwt';

export function useAuth() {
const [state, setState] = React.useState<AppState>(defaultState());
Expand Down
2 changes: 1 addition & 1 deletion test-app/src/components/bitcoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AppContext } from '@common/context';
import { stacksTestnetNetwork } from '@common/utils';
import * as btc from '@scure/btc-signer';
import { bytesToHex, hexToBytes } from '@stacks/common';
import { PsbtData, PsbtRequestOptions } from '@stacks/connect';
import { PsbtData, PsbtRequestOptions } from '@stacks/connect-jwt';
import { useConnect } from '@stacks/connect-react';
import { StacksNetwork } from '@stacks/network';
import { styled } from 'leather-styles/jsx';
Expand Down
2 changes: 1 addition & 1 deletion test-app/src/components/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';

import { useAuth } from '@common/use-auth';
import { stacksMainnetNetwork, stacksTestnetNetwork } from '@common/utils';
import { openProfileUpdateRequestPopup } from '@stacks/connect';
import { openProfileUpdateRequestPopup } from '@stacks/connect-jwt';
import { StacksNetwork } from '@stacks/network';
import { PublicPersonProfile, PublicProfile } from '@stacks/profile';
import { TestAppSelectors } from '@tests/selectors/test-app.selectors';
Expand Down
21 changes: 11 additions & 10 deletions test-app/src/components/signature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@common/utils';
import { sha256 } from '@noble/hashes/sha256';
import { bytesToHex } from '@noble/hashes/utils';
import { SignatureData } from '@stacks/connect';
import { SignatureData } from '@stacks/connect-jwt';
import { useConnect } from '@stacks/connect-react';
import { hashMessage, verifyMessageSignatureRsv } from '@stacks/encryption';
import { StacksNetwork } from '@stacks/network';
Expand Down Expand Up @@ -166,14 +166,19 @@ export const Signature = () => {
setCurrentStructuredData({ message, domain });

// ClarityValue -> Uint8Array -> Buffer -> string (hex)
const stringMessage = Buffer.from(serializeCV(message)).toString('hex');
const stringDomain = Buffer.from(serializeCV(domain)).toString('hex');
const stringMessage = serializeCV(message);
const stringDomain = serializeCV(domain);

await window.btc?.request('stx_signMessage', {
const result = await (window as any).LeatherProvider?.request('stx_signMessage', {
message: stringMessage,
messageType: 'structured',
domain: stringDomain,
});
if ('error' in result) {
console.error(result.error);
}

setSignatureStructured(result.result);
};

const sip18Test = [
Expand All @@ -196,14 +201,10 @@ export const Signature = () => {
</styled.span>
</styled.span>
)}
<styled.button mt={3} onClick={() => signMessage(signatureMessage, stacksMainnetNetwork)}>
<styled.button mt={3} onClick={() => signMessage(signatureMessage)}>
Signature (Mainnet)
</styled.button>
<styled.button
mt={3}
ml={3}
onClick={() => signMessage(signatureMessage, stacksTestnetNetwork)}
>
<styled.button mt={3} ml={3} onClick={() => signMessage(signatureMessage)}>
Signature (Testnet)
</styled.button>
<br />
Expand Down
Loading

0 comments on commit 5ad59a3

Please sign in to comment.