-
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.
- Loading branch information
1 parent
88acf1c
commit e057b7e
Showing
17 changed files
with
1,265 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,40 @@ | ||
import { doLog } from '@paima/utils'; | ||
import type { IVerify } from './IVerify.js'; | ||
|
||
export class MinaCrypto implements IVerify { | ||
verifyAddress = async (address: string): Promise<boolean> => { | ||
// TODO: improve | ||
return await Promise.resolve(/^[a-zA-Z0-9]+$/.test(address)); | ||
}; | ||
verifySignature = async ( | ||
userAddress: string, | ||
message: string, | ||
sigStruct: string | ||
): Promise<boolean> => { | ||
try { | ||
const [field, scalar, ...remainder] = sigStruct.split(';'); | ||
if (!field || !scalar || remainder.length > 0) { | ||
return false; | ||
} | ||
|
||
const Client = require('mina-signer'); | ||
|
||
// type Network = 'mainnet' | 'testnet' | ||
// TODO: unhardcode, but not sure yet where to get this | ||
const signerClient = new Client({ network: 'testnet' }); | ||
|
||
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
Oops, something went wrong.