-
Notifications
You must be signed in to change notification settings - Fork 865
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
refactor(experimental): implement getBase58EncodedAddressForSeed #1563
Conversation
This works from root: pnpm eslint --fix packages/addresses/src/__tests__/base58-test.ts Curious what you think of |
this doesnt run the other linter... it turns out the command was
sounds good! |
5500277
to
0f8fe6c
Compare
ab0535c
to
bdda9c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good and definitely matches the legacy library's implementation, however I wonder why the legacy lib doesn't look more like the Rust side of things.
Why doesn't it have the checks that solana_program
does (MAX_SEED_LENGTH
, PDA_MARKER
), any idea?
I think we should probably add these checks even though they weren't originally there, unless we have good reason not to.
Hang on one sec before you ship this. I’ll make some suggestions tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…I wonder why the legacy lib doesn't look more like the Rust side of things.
Yeah, 100%. I remember seeing that code and being like ‘hmm, we should roll that in.’ Add to this implementation:
- A check for max seed length like we did for program-derived-address (add tests)
- The Rust-style check for a forged PDA marker. What you're trying to protect against is this super weird edge case:
create(baseAddress, seed, '4vJ9JU1bJJE96FbKdjWme2JfVK1knU936FHTDZV7AC2')
. The last 21 bytes of4vJ9JU1bJJE96FbKdjWme2JfVK1knU936FHTDZV7AC2
just happen to decode to the ASCII stringProgramDerivedAddress
. (add tests)
Just one other thought: I think this is one of those APIs where a struct arg would be better. See createProgramDerivedAddress(pdaInput: PdaInput)
.
packages/addresses/src/base58.ts
Outdated
programAddress: Base58EncodedAddress | ||
): Promise<Base58EncodedAddress> { | ||
const { serialize, deserialize } = getBase58EncodedAddressCodec(); | ||
const seedBytes = new TextEncoder().encode(seed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to point out that TextEncoder
isn't available in React Native, but:
- We also use it in
program-derived-address.ts
- We should presume that, in React Native, we need to call out to an async API to do this encoding, but you've already made this method
async
so… carry on.
@@ -132,4 +133,16 @@ describe('base58', () => { | |||
]); | |||
}); | |||
}); | |||
describe('createBase58AddressWithSeed', () => { | |||
it('works', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the benefit of the next reader who doesn't know what this is supposed to do in the first place.
it('works', async () => { | |
it('returns an address that is the SHA-256 hash of the concatenated base address, seed, and program address', async () => { |
packages/addresses/src/base58.ts
Outdated
@@ -52,3 +52,18 @@ export function getBase58EncodedAddressComparator(): (x: string, y: string) => n | |||
usage: 'sort', | |||
}).compare; | |||
} | |||
|
|||
export async function createBase58AddressWithSeed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For pedantry:
export async function createBase58AddressWithSeed( | |
export async function createBase58EncodedAddressWithSeed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Akshually; I just renamed everything to *Address*
didn't I? So createAddressWithSeed
is the thing that would match everything else now.
bdda9c5
to
3d76d55
Compare
ok i
|
note ci failure is due to a bug in node nodejs/node#49497 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 This PR is included in version 1.78.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
doing this now because its a blocker for me. straightforward reimpl of
createWithSeed
:not ready to merge as-is, pls let me know:
lint:fix
, theres no command for it so i have no ideaCloses #999.