Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RPC for validating address #3842

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ironfish/src/rpc/routes/chain/isValidPublicAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { isValidPublicAddress } from '@ironfish/rust-nodejs'
import * as yup from 'yup'
import { ApiNamespace, router } from '../router'

export type IsValidPublicAddressRequest = {
address: string
}

export type IsValidPublicAddressResponse = {
valid: boolean
}

export const IsValidPublicAddressRequestSchema: yup.ObjectSchema<IsValidPublicAddressRequest> =
yup
.object({
address: yup.string().defined(),
})
.defined()

export const IsValidPublicAddressResponseSchema: yup.ObjectSchema<IsValidPublicAddressResponse> =
yup
.object({
valid: yup.boolean().defined(),
})
.defined()

router.register<typeof IsValidPublicAddressRequestSchema, IsValidPublicAddressResponse>(
`${ApiNamespace.chain}/isValidPublicAddress`,
IsValidPublicAddressRequestSchema,
(request): void => {
request.end({
valid: isValidPublicAddress(request.data.address),
Copy link
Contributor

@ygao76 ygao76 Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to use this isValidPublicAddress

export function isValidPublicAddress(publicAddress: string): boolean {
under the hood its the same thing but in case in the future we add logic to the address validation in ts layer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it won't practically make a difference, but I think this is a good idea. We should have a cleanup task for standardizing all uses of the function to go through the SDK, and this function is exported through the SDK + used in the wallet

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea sounds good I updated it

})
},
)