-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature/refactor lib #84
Conversation
@@ -249,7 +249,7 @@ const ERC20_TRANSFER_INTENT: TransferErc20 = { | |||
type: Intents.TRANSFER_ERC20, | |||
to: `eip155:137/0x031d8c0ca142921c459bcb28104c0ff37928f9ed` as AccountId, | |||
from: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.from.toLowerCase()}` as AccountId, | |||
contract: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as AccountId, | |||
token: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as AccountId, |
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.
token: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as AccountId, | |
token: getAccountId(`eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}`), |
Use the utility function to get an account ID to ensure the format is right on your tests.
@@ -267,7 +267,7 @@ const ERC721_SAFE_TRANSFER_FROM_INTENT: TransferErc721 = { | |||
to: `eip155:137/0xb253f6156e64b12ba0dec3974062dbbaee139f0c` as AccountId, | |||
from: `eip155:137/${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.from.toLowerCase()}` as AccountId, | |||
contract: `eip155:137/${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to?.toLowerCase()}` as AccountId, | |||
nftId: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as AssetId | |||
token: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as AssetId |
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.
token: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as AssetId | |
token: getAssetId(`eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173`) |
@@ -315,7 +315,7 @@ const ERC1155_SAFE_TRANSFER_FROM_INTENT: TransferErc1155 = { | |||
to: `eip155:137/0x00ca04c45da318d5b7e7b14d5381ca59f09c73f0` as AccountId, | |||
from: `eip155:137/${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.from.toLowerCase()}` as AccountId, | |||
contract: `eip155:137/${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to?.toLowerCase()}` as AccountId, | |||
transfers: [{ tokenId: `eip155:137/erc1155:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to}/175` as AssetId, amount: '1' }] | |||
transfers: [{ token: `eip155:137/erc1155:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to}/175` as AssetId, amount: '1' }] |
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.
Out of curiosity, why the amount is a string?
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.
Amount is a bigint encoded in Hex. So I decode it back to bigint and send it as a string, so that consumer decides how/if it needs to be encoded back into a number.
const result = safeDecode({ | ||
input: { | ||
type: InputType.TRANSACTION_REQUEST, | ||
txRequest: authzRequest.request.transactionRequest | ||
} | ||
}) |
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.
Do you think something like this would be possible?
const result = safeDecode({ | |
input: { | |
type: InputType.TRANSACTION_REQUEST, | |
txRequest: authzRequest.request.transactionRequest | |
} | |
}) | |
const result = safeDecode(authzRequest.request.transactionRequest) | |
// or | |
const result = safeDecode(authzRequest.request.message) |
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 guess it wouldn't be.
If you look at the shape of the safeDecode input, it's like so:
{ input, config = defaultConfig }: { input: DecodeInput; config?: Config }
config
include all the user trustworthy data that will be used to decode the input
.
- transaction registry
- contract registry
- set of supported methods and their decoder (default to my current set)
What is doable is determining the InputType, and then do something like this:
safeDecode({ input })
Or
safeDecode({ input, config })
} | ||
return intent | ||
return { | ||
to: toAccountIdLowerCase({ |
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.
Maybe you can use the toAccountId
again? I changed it last week to respect the given format. In other words, if you send checksummed address you should get checksummed ID, or if you send lower case address you'll get lower case ID
to: toAccountIdLowerCase({ | |
to: toAccountId({ |
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.
Gotcha
payload: input.raw.rawData | ||
} | ||
default: | ||
throw new Error('Invalid input type') |
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.
throw new Error('Invalid input type') | |
throw new DecodeError('Invalid input type') |
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.
Yes changing those
super(input) | ||
this.#input = input | ||
if (!isSupportedMethodId(methodId)) { | ||
throw new Error('Unsupported methodId') |
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.
throw new Error('Unsupported methodId') | |
throw new DecodeError('Unsupported methodId') |
} | ||
const params = extract(supportedMethods, data, methodId) as ApproveAllowanceParams | ||
if (!params) { | ||
throw new Error('Params do not match ERC20 transfer methodId') |
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.
throw new Error('Params do not match ERC20 transfer methodId') | |
throw new DecodeError('Params do not match ERC20 transfer methodId') |
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 left some comments. Nothing critical or blocking your PR.
If you CMD/CTRL + F "throw new Error" you'll notice a bunch of pending domain errors yet 😉
message: string | ||
} | ||
|
||
export type SignRawMessage = { | ||
type: Intents.SIGN_RAW_MESSAGE | ||
from: AccountId | ||
message: string |
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.
@Ptroger as discussed, you removed the wrong data
22a320b
to
6049c45
Compare
6049c45
to
744b769
Compare
* changed interface * changed intent naming, changed usage of lib in apps * format and lint * Update rego criteria * changed interface * used decoderErros * fix --------- Co-authored-by: samuel <samuel@narval.xyz>
No description provided.