-
Notifications
You must be signed in to change notification settings - Fork 4
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
Updates soroban-client version, updates use of helpers #13
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5649da8
updates soroban-client version, updates use of helpers
aristidesstaffieri eb07f44
cleans up not needed xdr conversions and duplicate logic
aristidesstaffieri c3503b5
port new helper for signing auth entries
aristidesstaffieri 94af5b3
uses signAuthEntry while SWK adds new api
aristidesstaffieri 736cc1d
cleans up wip helper refactors
aristidesstaffieri 881f8c4
correctly fetched contract code expiration
aristidesstaffieri 58a4708
uses soroban rpc helpers to check simulation response types
aristidesstaffieri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,67 @@ | ||
import { | ||
Address, | ||
StrKey, | ||
xdr, | ||
nativeToScVal, | ||
Keypair, | ||
hash, | ||
} from "soroban-client"; | ||
|
||
// This can be replaced with the same helper in the sdk when it lands | ||
// https://github.com/stellar/js-stellar-base/pull/678 | ||
|
||
export async function authorizeEntry( | ||
entry: xdr.SorobanAuthorizationEntry, | ||
signer: (input: Buffer) => Promise<Buffer>, | ||
validUntilLedgerSeq: any, | ||
networkPassphrase: string, | ||
) { | ||
// no-op | ||
if ( | ||
entry.credentials().switch() !== | ||
xdr.SorobanCredentialsType.sorobanCredentialsAddress() | ||
) { | ||
return entry; | ||
} | ||
|
||
/** @type {xdr.SorobanAddressCredentials} */ | ||
const addrAuth = entry.credentials().address(); | ||
addrAuth.signatureExpirationLedger(validUntilLedgerSeq); | ||
|
||
const networkId = hash(Buffer.from(networkPassphrase)); | ||
const preimage = xdr.HashIdPreimage.envelopeTypeSorobanAuthorization( | ||
new xdr.HashIdPreimageSorobanAuthorization({ | ||
networkId, | ||
nonce: addrAuth.nonce(), | ||
invocation: entry.rootInvocation(), | ||
signatureExpirationLedger: addrAuth.signatureExpirationLedger(), | ||
}), | ||
); | ||
|
||
const signature = await signer(preimage.toXDR()); | ||
const publicKey = Address.fromScAddress(addrAuth.address()).toString(); | ||
|
||
if ( | ||
!Keypair.fromPublicKey(publicKey).verify(hash(preimage.toXDR()), signature) | ||
) { | ||
throw new Error(`signature doesn't match payload`); | ||
} | ||
|
||
const sigScVal = nativeToScVal( | ||
{ | ||
public_key: StrKey.decodeEd25519PublicKey(publicKey), | ||
signature, | ||
}, | ||
{ | ||
// force the keys to be interpreted as symbols (expected for | ||
// Soroban [contracttype]s) | ||
type: { | ||
public_key: ["symbol", null], | ||
signature: ["symbol", null], | ||
} as any, | ||
}, | ||
); | ||
|
||
addrAuth.signature(sigScVal); | ||
return entry; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ballsy 😝
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.
ah yeah lol fair call out I won't cast it 😄
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.
fixed in 736cc1d