-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mina/auro wallet support (wip) * use mina provider package and fix hardcoded network * improve verifyAddress * update package-lock.json * fix: move MINA_LOGIN error variant * add 'accountsChanged' listener * use base58check for mina verifyAddress * update package-lock.json
- Loading branch information
1 parent
c0e242c
commit 322b408
Showing
18 changed files
with
1,332 additions
and
370 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,44 @@ | ||
import { doLog } from '@paima/utils'; | ||
import type { IVerify } from './IVerify.js'; | ||
const base58check = require('base58check'); | ||
|
||
export class MinaCrypto implements IVerify { | ||
verifyAddress = async (address: string): Promise<boolean> => { | ||
try { | ||
base58check.decode(address); | ||
} catch (e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
verifySignature = async ( | ||
userAddress: string, | ||
message: string, | ||
sigStruct: string | ||
): Promise<boolean> => { | ||
try { | ||
const [field, scalar, network, ...remainder] = sigStruct.split(';'); | ||
if (!field || !scalar || !network || remainder.length > 0) { | ||
return false; | ||
} | ||
|
||
const Client = require('mina-signer'); | ||
|
||
const signerClient = new Client({ network }); | ||
|
||
const verifyBody = { | ||
data: message, | ||
publicKey: userAddress, | ||
signature: { field, scalar }, | ||
}; | ||
|
||
const verifyResult = signerClient.verifyMessage(verifyBody); | ||
|
||
return verifyResult; | ||
} catch (err) { | ||
doLog('[address-validator] error verifying mina signature:', err); | ||
return 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
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,32 @@ | ||
import type { LoginInfoMap, Result } from '../types.js'; | ||
import { PaimaMiddlewareErrorCode, buildEndpointErrorFxn } from '../errors.js'; | ||
import { MinaConnector } from '@paima/providers'; | ||
import type { ApiForMode, IProvider, WalletMode } from '@paima/providers'; | ||
import { getGameName } from '../state.js'; | ||
import { connectInjected } from './wallet-modes.js'; | ||
|
||
export async function minaLoginWrapper( | ||
loginInfo: LoginInfoMap[WalletMode.Mina] | ||
): Promise<Result<IProvider<ApiForMode<WalletMode.Mina>>>> { | ||
const errorFxn = buildEndpointErrorFxn('minaLoginWrapper'); | ||
|
||
const gameInfo = { | ||
gameName: getGameName(), | ||
gameChainId: undefined, // Not needed because of batcher | ||
}; | ||
const loginResult = await connectInjected( | ||
'minaLoginWrapper', | ||
errorFxn, | ||
PaimaMiddlewareErrorCode.MINA_LOGIN, | ||
loginInfo, | ||
MinaConnector.instance(), | ||
gameInfo | ||
); | ||
if (loginResult.success === false) { | ||
return loginResult; | ||
} | ||
return { | ||
success: true, | ||
result: loginResult.result, | ||
}; | ||
} |
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
Oops, something went wrong.