phantom / docs

31 stars 17 forks source link

Cannot sign Solana transactions with signMessage #182

Open trevormil opened 6 months ago

trevormil commented 6 months ago

Discussed in https://github.com/orgs/phantom/discussions/181

Originally posted by **trevormil** February 21, 2024 ### Summary I am building a dApp that supports signing my Cosmos SDK blockchain's transactions as plaintext messages with Phantom Wallet. Certain transactions work, but some like the following fail with the error "Oops! You cannot sign solana transactions using sign message". Why could this be? What in this specific JSON is causing the error to be treated as a Solana transaction? I am pretty sure it was working a little bit ago (maybe a new version update triggered something?) ``` {"account_number":"13","chain_id":"bitbadges_1-2","fee":{"amount":[{"amount":"0","denom":"badge"}],"gas":"115584"},"memo":"","msg0":{"type":"badges/UniversalUpdateCollection","value":{"badgeMetadataTimeline":[{"badgeMetadata":[{"badgeIds":[{"end":"18446744073709551615","start":"1"}],"customData":"","uri":"ipfs://QmQKn1G41gcVEZPenXjtTTQfQJnx5Q6fDtZrcSNJvBqxUs"}],"timelineTimes":[{"end":"18446744073709551615","start":"1"}]}],"badgesToCreate":[{"amount":"1","badgeIds":[{"end":"10000","start":"1"}],"ownershipTimes":[{"end":"18446744073709551615","start":"1"}]}],"balancesType":"Standard","collectionApprovals":[],"collectionId":"0","collectionMetadataTimeline":[{"collectionMetadata":{"customData":"","uri":"ipfs://QmfCSNLayKfnaGQFZ5jFgKJoirsg9Uptp4djMU3sQ3itH3"},"timelineTimes":[{"end":"18446744073709551615","start":"1"}]}],"collectionPermissions":{"canArchiveCollection":[],"canCreateMoreBadges":[],"canDeleteCollection":[],"canUpdateBadgeMetadata":[],"canUpdateCollectionApprovals":[],"canUpdateCollectionMetadata":[],"canUpdateCustomData":[],"canUpdateManager":[],"canUpdateOffChainBalancesMetadata":[],"canUpdateStandards":[]},"creator":"cosmos1zd5dsage58jfrgmsu377pk6w0q5zhc67fn4gsl","customDataTimeline":[],"defaultBalances":{"autoApproveSelfInitiatedIncomingTransfers":true,"autoApproveSelfInitiatedOutgoingTransfers":true,"balances":[],"incomingApprovals":[{"amountTrackerId":"default-incoming-allowed","approvalCriteria":{"approvalAmounts":{"overallApprovalAmount":"0","perFromAddressApprovalAmount":"0","perInitiatedByAddressApprovalAmount":"0","perToAddressApprovalAmount":"0"},"maxNumTransfers":{"overallMaxNumTransfers":"0","perFromAddressMaxNumTransfers":"0","perInitiatedByAddressMaxNumTransfers":"0","perToAddressMaxNumTransfers":"0"},"merkleChallenge":{"customData":"","expectedProofLength":"0","maxUsesPerLeaf":"0","root":"","uri":"","useCreatorAddressAsLeaf":false},"mustOwnBadges":[],"predeterminedBalances":{"incrementedBalances":{"incrementBadgeIdsBy":"0","incrementOwnershipTimesBy":"0","startBalances":[]},"manualBalances":[],"orderCalculationMethod":{"useMerkleChallengeLeafIndex":false,"useOverallNumTransfers":false,"usePerFromAddressNumTransfers":false,"usePerInitiatedByAddressNumTransfers":false,"usePerToAddressNumTransfers":false}},"requireFromDoesNotEqualInitiatedBy":false,"requireFromEqualsInitiatedBy":false},"approvalId":"default-incoming-allowed","badgeIds":[{"end":"18446744073709551615","start":"1"}],"challengeTrackerId":"default-incoming-allowed","customData":"","fromListId":"All","initiatedByListId":"All","ownershipTimes":[{"end":"18446744073709551615","start":"1"}],"transferTimes":[{"end":"18446744073709551615","start":"1"}],"uri":""}],"outgoingApprovals":[],"userPermissions":{"canUpdateAutoApproveSelfInitiatedIncomingTransfers":[],"canUpdateAutoApproveSelfInitiatedOutgoingTransfers":[],"canUpdateIncomingApprovals":[],"canUpdateOutgoingApprovals":[]}},"isArchivedTimeline":[],"managerTimeline":[{"manager":"cosmos1zd5dsage58jfrgmsu377pk6w0q5zhc67fn4gsl","timelineTimes":[{"end":"18446744073709551615","start":"1"}]}],"offChainBalancesMetadataTimeline":[],"standardsTimeline":[],"updateBadgeMetadataTimeline":true,"updateCollectionApprovals":true,"updateCollectionMetadataTimeline":true,"updateCollectionPermissions":true,"updateCustomDataTimeline":true,"updateIsArchivedTimeline":true,"updateManagerTimeline":true,"updateOffChainBalancesMetadataTimeline":true,"updateStandardsTimeline":true}},"sequence":"4"} ``` ### Example _No response_ ### Steps to Reproduce Sign the message below using Phantom's sign message ``` const message = payload.jsonToSign; const encodedMessage = new TextEncoder().encode(message); const signedMessage = await solanaProvider.request({ method: "signMessage", params: { message: encodedMessage, display: "utf8" } }); ``` ``` {"account_number":"13","chain_id":"bitbadges_1-2","fee":{"amount":[{"amount":"0","denom":"badge"}],"gas":"115584"},"memo":"","msg0":{"type":"badges/UniversalUpdateCollection","value":{"badgeMetadataTimeline":[{"badgeMetadata":[{"badgeIds":[{"end":"18446744073709551615","start":"1"}],"customData":"","uri":"ipfs://QmQKn1G41gcVEZPenXjtTTQfQJnx5Q6fDtZrcSNJvBqxUs"}],"timelineTimes":[{"end":"18446744073709551615","start":"1"}]}],"badgesToCreate":[{"amount":"1","badgeIds":[{"end":"10000","start":"1"}],"ownershipTimes":[{"end":"18446744073709551615","start":"1"}]}],"balancesType":"Standard","collectionApprovals":[],"collectionId":"0","collectionMetadataTimeline":[{"collectionMetadata":{"customData":"","uri":"ipfs://QmfCSNLayKfnaGQFZ5jFgKJoirsg9Uptp4djMU3sQ3itH3"},"timelineTimes":[{"end":"18446744073709551615","start":"1"}]}],"collectionPermissions":{"canArchiveCollection":[],"canCreateMoreBadges":[],"canDeleteCollection":[],"canUpdateBadgeMetadata":[],"canUpdateCollectionApprovals":[],"canUpdateCollectionMetadata":[],"canUpdateCustomData":[],"canUpdateManager":[],"canUpdateOffChainBalancesMetadata":[],"canUpdateStandards":[]},"creator":"cosmos1zd5dsage58jfrgmsu377pk6w0q5zhc67fn4gsl","customDataTimeline":[],"defaultBalances":{"autoApproveSelfInitiatedIncomingTransfers":true,"autoApproveSelfInitiatedOutgoingTransfers":true,"balances":[],"incomingApprovals":[{"amountTrackerId":"default-incoming-allowed","approvalCriteria":{"approvalAmounts":{"overallApprovalAmount":"0","perFromAddressApprovalAmount":"0","perInitiatedByAddressApprovalAmount":"0","perToAddressApprovalAmount":"0"},"maxNumTransfers":{"overallMaxNumTransfers":"0","perFromAddressMaxNumTransfers":"0","perInitiatedByAddressMaxNumTransfers":"0","perToAddressMaxNumTransfers":"0"},"merkleChallenge":{"customData":"","expectedProofLength":"0","maxUsesPerLeaf":"0","root":"","uri":"","useCreatorAddressAsLeaf":false},"mustOwnBadges":[],"predeterminedBalances":{"incrementedBalances":{"incrementBadgeIdsBy":"0","incrementOwnershipTimesBy":"0","startBalances":[]},"manualBalances":[],"orderCalculationMethod":{"useMerkleChallengeLeafIndex":false,"useOverallNumTransfers":false,"usePerFromAddressNumTransfers":false,"usePerInitiatedByAddressNumTransfers":false,"usePerToAddressNumTransfers":false}},"requireFromDoesNotEqualInitiatedBy":false,"requireFromEqualsInitiatedBy":false},"approvalId":"default-incoming-allowed","badgeIds":[{"end":"18446744073709551615","start":"1"}],"challengeTrackerId":"default-incoming-allowed","customData":"","fromListId":"All","initiatedByListId":"All","ownershipTimes":[{"end":"18446744073709551615","start":"1"}],"transferTimes":[{"end":"18446744073709551615","start":"1"}],"uri":""}],"outgoingApprovals":[],"userPermissions":{"canUpdateAutoApproveSelfInitiatedIncomingTransfers":[],"canUpdateAutoApproveSelfInitiatedOutgoingTransfers":[],"canUpdateIncomingApprovals":[],"canUpdateOutgoingApprovals":[]}},"isArchivedTimeline":[],"managerTimeline":[{"manager":"cosmos1zd5dsage58jfrgmsu377pk6w0q5zhc67fn4gsl","timelineTimes":[{"end":"18446744073709551615","start":"1"}]}],"offChainBalancesMetadataTimeline":[],"standardsTimeline":[],"updateBadgeMetadataTimeline":true,"updateCollectionApprovals":true,"updateCollectionMetadataTimeline":true,"updateCollectionPermissions":true,"updateCustomDataTimeline":true,"updateIsArchivedTimeline":true,"updateManagerTimeline":true,"updateOffChainBalancesMetadataTimeline":true,"updateStandardsTimeline":true}},"sequence":"4"} ``` ### Phantom Version 24.2.0 ### Is there an existing discussion for this? - [X] I have searched the existing discussions
Cognacy commented 3 months ago

hey there! Are you able to solve this? I'm having a similar issue as well.

trevormil commented 3 months ago

hey there! Are you able to solve this? I'm having a similar issue as well.

@Cognacy Hey. So, the problem is that Phantom does not support Solana message signatures of messages >~1000 characters. The error message "cannot sign with signMessage" is pretty misleading. They said they would fix this (see discussion linked below). I just implemented a workaround so that my messages were always under 1000 characters.

https://github.com/orgs/phantom/discussions/181

From further research, I believe this may be a Solana limitation, not a Phantom one, but not 100% sure....

https://docs.solanalabs.com/cli/examples/sign-offchain-message