-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support strium login #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
impelcrypto
wants to merge
3
commits into
master
Choose a base branch
from
feat/support-strium-login
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/app-sdk/src/interface/public-utilities/raw-digest-sign/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { ProviderInterface } from ':core/provider/interface.js' | ||
| import { requestSignRawDigest } from './index.js' | ||
|
|
||
| describe('requestSignRawDigest', () => { | ||
| const address = '0x1234567890abcdef1234567890abcdef12345678' as const | ||
| const digest = `0x${'ab'.repeat(32)}` as const | ||
|
|
||
| const makeProvider = (returnValue: string): ProviderInterface => | ||
| ({ | ||
| request: vi.fn().mockResolvedValue(returnValue), | ||
| }) as unknown as ProviderInterface | ||
|
|
||
| it('forwards a 32-byte digest to wallet_signRawDigest', async () => { | ||
| const provider = makeProvider('0xdeadbeef') | ||
|
|
||
| const signature = await requestSignRawDigest({ | ||
| provider, | ||
| digest, | ||
| address, | ||
| }) | ||
|
|
||
| expect(provider.request).toHaveBeenCalledWith({ | ||
| method: 'wallet_signRawDigest', | ||
| params: [digest, address], | ||
| }) | ||
| expect(signature).toBe('0xdeadbeef') | ||
| }) | ||
|
|
||
| it('rejects digests that are not exactly 32 bytes', async () => { | ||
| const provider = makeProvider('0xdeadbeef') | ||
|
|
||
| await expect( | ||
| requestSignRawDigest({ | ||
| provider, | ||
| digest: '0x1234' as `0x${string}`, | ||
| address, | ||
| }), | ||
| ).rejects.toThrow('digest must be a 32-byte hex string') | ||
| expect(provider.request).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('rejects non-hex digests of the right length', async () => { | ||
| const provider = makeProvider('0xdeadbeef') | ||
|
|
||
| await expect( | ||
| requestSignRawDigest({ | ||
| provider, | ||
| digest: `0x${'zz'.repeat(32)}` as `0x${string}`, | ||
| address, | ||
| }), | ||
| ).rejects.toThrow('digest must be a 32-byte hex string') | ||
| }) | ||
| }) |
46 changes: 46 additions & 0 deletions
46
packages/app-sdk/src/interface/public-utilities/raw-digest-sign/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { type Address, type Hex } from 'viem' | ||
|
|
||
| import { ProviderInterface } from ':core/provider/interface.js' | ||
|
|
||
| export type RequestSignRawDigestType = { | ||
| provider: ProviderInterface | ||
| /** 32-byte signing digest (0x + 64 hex chars) */ | ||
| digest: Hex | ||
| address: Address | ||
| } | ||
|
|
||
| const DIGEST_PATTERN = /^0x[0-9a-fA-F]{64}$/ | ||
|
|
||
| /** | ||
| * Asks the popup to raw-sign a 32-byte digest with the user's embedded | ||
| * wallet (EOA) — plain secp256k1 ECDSA over the exact digest bytes, with no | ||
| * EIP-191 prefix and no re-hashing. | ||
| * | ||
| * The signature bytes vary across calls (MPC signing is non-deterministic), | ||
| * but `ecrecover(digest, signature)` always yields the same signer address. | ||
| * Callers should rely on the recovered key, never on signature stability. | ||
| * | ||
| * Typical use cases: recovering a stable user address via ecrecover, and | ||
| * signing externally-computed digests such as Substrate extrinsic payloads | ||
| * for ethereum-type (AccountId20) chains. | ||
| */ | ||
| const requestSignRawDigestFn = async ({ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do |
||
| provider, | ||
| digest, | ||
| address, | ||
| }: RequestSignRawDigestType): Promise<Hex> => { | ||
| if (!DIGEST_PATTERN.test(digest)) { | ||
| throw new Error( | ||
| 'digest must be a 32-byte hex string (0x followed by 64 hex chars)', | ||
| ) | ||
| } | ||
|
|
||
| const signature = (await provider.request({ | ||
| method: 'wallet_signRawDigest', | ||
| params: [digest, address], | ||
| })) as Hex | ||
|
|
||
| return signature | ||
| } | ||
|
|
||
| export const requestSignRawDigest = requestSignRawDigestFn | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am getting error when using Example digest. I am running local Startale app from branch
feat/support-strium-login