-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add proof of ownership request
- Loading branch information
1 parent
893bce1
commit 8c24675
Showing
9 changed files
with
230 additions
and
87 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
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
53 changes: 53 additions & 0 deletions
53
packages/dapp-toolkit/src/modules/wallet-request/data-request/builders/proof-of-ownership.ts
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,53 @@ | ||
import { produce } from 'immer' | ||
import { object, InferOutput, union, string, array, optional } from 'valibot' | ||
|
||
export type ProofOfOwnershipRequestBuilder = { | ||
accounts: (value: string[]) => ProofOfOwnershipRequestBuilder | ||
identity: (value: string) => ProofOfOwnershipRequestBuilder | ||
} | ||
export type ProofOfOwnershipRequest = InferOutput<typeof schema> | ||
|
||
const schema = object({ | ||
accountAddresses: optional(array(string())), | ||
identityAddress: optional(string()), | ||
}) | ||
|
||
export const proofOfOwnership = (initialData: ProofOfOwnershipRequest = {}) => { | ||
let data: ProofOfOwnershipRequest = produce(initialData, () => {}) | ||
|
||
const accounts = (value: string[]) => { | ||
if (data.identityAddress) { | ||
throw new Error( | ||
'ProofOfOwnershipRequest: accounts and identity cannot be set at the same time', | ||
) | ||
} | ||
data = produce(data, (draft) => { | ||
draft.accountAddresses = value | ||
}) | ||
return methods | ||
} | ||
|
||
const identity = (value: string) => { | ||
if (data.accountAddresses) { | ||
throw new Error( | ||
'ProofOfOwnershipRequest: accounts and identity cannot be set at the same time', | ||
) | ||
} | ||
data = produce(data, (draft) => { | ||
draft.identityAddress = value | ||
}) | ||
return methods | ||
} | ||
|
||
const _toObject = (): { proofOfOwnership: ProofOfOwnershipRequest } => ({ | ||
proofOfOwnership: data, | ||
}) | ||
|
||
const methods = { | ||
accounts, | ||
identity, | ||
_toObject, | ||
} | ||
|
||
return methods | ||
} |
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.