-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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,24 @@ | ||
--- | ||
'@reown/appkit-adapter-solana': patch | ||
'@reown/appkit-siwx': patch | ||
'@apps/demo': patch | ||
'@apps/gallery': patch | ||
'@apps/laboratory': patch | ||
'@reown/appkit-adapter-ethers': patch | ||
'@reown/appkit-adapter-ethers5': patch | ||
'@reown/appkit-adapter-polkadot': patch | ||
'@reown/appkit-adapter-wagmi': patch | ||
'@reown/appkit': patch | ||
'@reown/appkit-utils': patch | ||
'@reown/appkit-cdn': patch | ||
'@reown/appkit-common': patch | ||
'@reown/appkit-core': patch | ||
'@reown/appkit-experimental': patch | ||
'@reown/appkit-polyfills': patch | ||
'@reown/appkit-scaffold-ui': patch | ||
'@reown/appkit-siwe': patch | ||
'@reown/appkit-ui': patch | ||
'@reown/appkit-wallet': patch | ||
--- | ||
|
||
Adds SIWX Solana verifier |
This file contains 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 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 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 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 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 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,23 @@ | ||
import { SIWXVerifier } from '../core/SIWXVerifier.js' | ||
import type { SIWXSession } from '@reown/appkit-core' | ||
import nacl from 'tweetnacl' | ||
import bs58 from 'bs58' | ||
import { ConstantsUtil } from '@reown/appkit-common' | ||
|
||
export class SolanaVerifier extends SIWXVerifier { | ||
public readonly chainNamespace = ConstantsUtil.CHAIN.SOLANA | ||
|
||
public async verify(session: SIWXSession): Promise<boolean> { | ||
try { | ||
const publicKey = bs58.decode(session.message.accountAddress) | ||
const signature = bs58.decode(session.signature) | ||
const message = new TextEncoder().encode(session.message.toString()) | ||
|
||
const isValid = nacl.sign.detached.verify(message, signature, publicKey) | ||
|
||
return Promise.resolve(isValid) | ||
} catch (error) { | ||
return Promise.resolve(false) | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './EIP155Verifier.js' | ||
export * from './SolanaVerifier.js' |
This file contains 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 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,80 @@ | ||
import { describe, test, expect } from 'vitest' | ||
import { type SIWXSession } from '@reown/appkit-core' | ||
import { mockSession } from '../mocks/mockSession.js' | ||
import { SolanaVerifier } from '../../src/verifiers/SolanaVerifier.js' | ||
|
||
type Case = { | ||
reason: string | ||
session: SIWXSession | ||
expected: boolean | ||
} | ||
|
||
const cases: Case[] = [ | ||
{ | ||
reason: 'valid session', | ||
session: mockSession({ | ||
message: { | ||
accountAddress: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgpU' | ||
}, | ||
signature: | ||
'2ZpgpUKF6RtmbrE8uBmPwRiBqRnsCKiBKkjsPSpf6c64r4XdDoevjhjNX35X7GeuSwwRhmbB2Ro4NfHWAeXWNhDL' | ||
}), | ||
expected: true | ||
}, | ||
{ | ||
reason: 'invalid session with an invalid signature', | ||
session: mockSession({ | ||
message: { | ||
accountAddress: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgpU' | ||
}, | ||
signature: | ||
'3ErkFZkvhSJVR7E1uakGwj8icgfxvRSS6AwW5bq4CZsXPZ83XrT1H9xcCWLvhsYCLYzFc7WSMQEJxGgpZvtgqbdE' | ||
}), | ||
expected: false | ||
}, | ||
{ | ||
reason: 'invalid session with an invalid account address', | ||
session: mockSession({ | ||
message: { | ||
accountAddress: 'C6ydkvKcRdXz3ZTEYy6uWAAyZgyUF49qP4XPdaDB2nqS' | ||
}, | ||
signature: | ||
'2ZpgpUKF6RtmbrE8uBmPwRiBqRnsCKiBKkjsPSpf6c64r4XdDoevjhjNX35X7GeuSwwRhmbB2Ro4NfHWAeXWNhDL' | ||
}), | ||
expected: false | ||
} | ||
] | ||
|
||
describe('SolanaVerifier', () => { | ||
const verifier = new SolanaVerifier() | ||
|
||
test('should have solana as the chain namespace', () => { | ||
expect(verifier.chainNamespace).toBe('solana') | ||
}) | ||
|
||
test('should verify only solana chain id', () => { | ||
expect( | ||
verifier.shouldVerify( | ||
mockSession({ | ||
message: { | ||
chainId: 'solana:mainnet' | ||
} | ||
}) | ||
) | ||
).toBe(true) | ||
|
||
expect( | ||
verifier.shouldVerify( | ||
mockSession({ | ||
message: { | ||
chainId: 'eip155:1' | ||
} | ||
}) | ||
) | ||
).toBe(false) | ||
}) | ||
|
||
test.each(cases)(`should verify $reason`, async ({ session, expected }) => { | ||
expect(await verifier.verify(session)).toBe(expected) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.