Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
fix: support for login request without challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Jan 18, 2023
1 parent f65c6db commit 63890b3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ document.getElementById('account-address-btn')!.onclick = async () => {
document.getElementById('persona-data-btn')!.onclick = async () => {
clearResults()

const result = await sdk.request(requestBuilder(login()))
const result = await sdk.request(requestBuilder(login.withoutChallenge()))

displayResults(result)
}
Expand All @@ -100,7 +100,7 @@ document.getElementById('send-tx-btn')!.onclick = async () => {
sdk
.request(
requestBuilder(
requestItem.login(),
requestItem.login.withoutChallenge(),
requestItem.ongoingAccounts.withoutProofOfOwnership()
)
)
Expand Down
25 changes: 17 additions & 8 deletions lib/IO/request-items/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ export type Login = {
}

type NotAllowedKeys = Partial<{
usePersona: any
login: any
persona: any
loginWithoutChallenge: any
loginWithChallenge: any
}>

export const login =
(challenge?: string) =>
<I>(input: I extends NotAllowedKeys ? never : I) => ({
...input,
login: { challenge },
})
export const login = {
withoutChallenge:
() =>
<I>(input: I extends NotAllowedKeys ? never : I) => ({
...input,
loginWithoutChallenge: {},
}),
withChallenge:
(challenge: string) =>
<I>(input: I extends NotAllowedKeys ? never : I) => ({
...input,
loginWithChallenge: { challenge },
}),
}
5 changes: 4 additions & 1 deletion lib/IO/request-items/ongoing-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export type OngoingAccounts = {
}
}

type RequiredKeys = { usePersona: any } | { login: any }
type RequiredKeys =
| { usePersona: any }
| { loginWithoutChallenge: any }
| { loginWithChallenge: any }

type NotAllowedKeys = Partial<{
ongoingAccounts: any
Expand Down
9 changes: 8 additions & 1 deletion lib/IO/transform-method-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const requestTypeMapper = new Map<string, string>()
requestMethodRequestType.ongoingAccountsWithoutProofOfOwnership,
RequestTypeSchema.ongoingAccountsRead.value
)
.set(requestMethodRequestType.login, RequestTypeSchema.loginRead.value)
.set(
requestMethodRequestType.loginWithChallenge,
RequestTypeSchema.loginRead.value
)
.set(
requestMethodRequestType.loginWithoutChallenge,
RequestTypeSchema.loginRead.value
)
.set(
requestMethodRequestType.usePersona,
RequestTypeSchema.usePersonaRead.value
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/transform-method-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ describe('transformMethodInput', () => {
it('should return correct transformed value', () => {
;[
{
actual: requestItem.login('abc'),
actual: requestItem.login.withChallenge('abc'),
expected: {
requestType: RequestTypeSchema.loginRead.value,
challenge: 'abc',
},
},
{
actual: requestItem.login(),
actual: requestItem.login.withoutChallenge(),
expected: {
requestType: RequestTypeSchema.loginRead.value,
},
Expand Down
6 changes: 3 additions & 3 deletions lib/methods/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const requestMethodRequestType = {
'ongoingAccountsWithoutProofOfOwnership',
ongoingAccountsWithProofOfOwnership: 'ongoingAccountsWithProofOfOwnership',
usePersona: 'usePersona',
login: 'login',
// loginWithChallenge: 'loginWithChallenge',
loginWithoutChallenge: 'loginWithoutChallenge',
loginWithChallenge: 'loginWithChallenge',
oneTimePersonaData: 'oneTimePersonaData',
ongoingPersonaData: 'ongoingPersonaData',
} as const
Expand All @@ -22,7 +22,7 @@ type RequestItems = {
[requestMethodRequestType.ongoingAccountsWithoutProofOfOwnership]: OngoingAccounts['WithoutProofOfOwnership']
// [requestMethodRequestType.ongoingAccountsWithProofOfOwnership]: OngoingAccounts['WithProofOfOwnership']
// [requestMethodRequestType.usePersona]: UsePersona
[requestMethodRequestType.login]: Login['WithoutChallenge']
[requestMethodRequestType.loginWithoutChallenge]: Login['WithoutChallenge']
// [requestMethodRequestType.loginWithChallenge]: Login['WithChallenge']
// [requestMethodRequestType.oneTimePersonaData]: OneTimePersonaData
// [requestMethodRequestType.ongoingPersonaData]: OngoingPersonaData
Expand Down

0 comments on commit 63890b3

Please sign in to comment.