-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(icp): adapt to new signing method
- Loading branch information
Showing
7 changed files
with
111 additions
and
47 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
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 |
---|---|---|
@@ -1,52 +1,42 @@ | ||
import { IDL } from "@dfinity/candid"; | ||
import type { ActorSubclass } from "@dfinity/agent"; | ||
import type { Ed25519KeyIdentity } from "@dfinity/identity"; | ||
import { Principal } from "@dfinity/principal"; | ||
import * as ed from "@noble/ed25519"; | ||
import type { _SERVICE } from "../../../contractsTypes/icp/bridge/bridge.did"; | ||
import type { TNftTransferDetailsObject } from "../../types"; | ||
|
||
export default async function signClaimData( | ||
data: TNftTransferDetailsObject, | ||
identity: Ed25519KeyIdentity, | ||
bc: ActorSubclass<_SERVICE>, | ||
) { | ||
const encoded = ClaimData.encodeValue({ | ||
const encoded = await bc.encode_claim_data({ | ||
destination_chain: data.destinationChain, | ||
destination_user_address: Principal.fromText(data.destinationUserAddress), | ||
fee: BigInt(data.fee), | ||
source_chain: data.sourceChain, | ||
lock_tx_chain: data.lockTxChain, | ||
transaction_hash: data.transactionHash, | ||
token_amount: BigInt(data.tokenAmount), | ||
destination_chain: data.destinationChain, | ||
token_id: data.tokenId, | ||
source_nft_contract_address: data.sourceNftContractAddress, | ||
metadata: data.metadata, | ||
name: data.name, | ||
nft_type: data.nftType, | ||
royalty: BigInt(data.royalty), | ||
royalty_receiver: Principal.fromText(data.royaltyReceiver), | ||
destination_user_address: Principal.fromText(data.destinationUserAddress), | ||
source_chain: data.sourceChain, | ||
source_nft_contract_address: data.sourceNftContractAddress, | ||
symbol: data.symbol, | ||
token_amount: BigInt(data.tokenAmount), | ||
token_id: BigInt(data.tokenId), | ||
transaction_hash: data.transactionHash, | ||
}); | ||
|
||
const signature = await identity.sign(encoded); | ||
const signature = await ed.sign( | ||
Buffer.from(encoded), | ||
Buffer.from(identity.getKeyPair().secretKey), | ||
); | ||
|
||
return { | ||
signer: Buffer.from(identity.getPublicKey().toRaw()).toString("hex"), | ||
signer: Buffer.from( | ||
await ed.getPublicKey(Buffer.from(identity.getKeyPair().secretKey)), | ||
).toString("hex"), | ||
signature: `0x${Buffer.from(signature).toString("hex")}`, | ||
}; | ||
} | ||
|
||
const ClaimData = IDL.Record({ | ||
fee: IDL.Nat64, | ||
source_chain: IDL.Text, | ||
lock_tx_chain: IDL.Text, | ||
transaction_hash: IDL.Text, | ||
token_amount: IDL.Nat, | ||
destination_chain: IDL.Text, | ||
token_id: IDL.Nat, | ||
source_nft_contract_address: IDL.Text, | ||
metadata: IDL.Text, | ||
name: IDL.Text, | ||
nft_type: IDL.Text, | ||
royalty: IDL.Nat, | ||
royalty_receiver: IDL.Principal, | ||
destination_user_address: IDL.Principal, | ||
symbol: IDL.Text, | ||
}); |
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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
import type { ActorSubclass } from "@dfinity/agent"; | ||
import type { Ed25519KeyIdentity } from "@dfinity/identity"; | ||
import { Principal } from "@dfinity/principal"; | ||
import * as ed from "@noble/ed25519"; | ||
import type { _SERVICE } from "../../../contractsTypes/icp/bridge/bridge.did"; | ||
|
||
export default async function signData( | ||
buf: string, | ||
identity: Ed25519KeyIdentity, | ||
bc: ActorSubclass<_SERVICE>, | ||
) { | ||
const signtureBytes = await identity.sign(Buffer.from(buf, "hex")); | ||
const [principal, pubk] = buf.split(","); | ||
const body = await bc.encode_add_validator({ | ||
principal: Principal.fromText(principal), | ||
public_key: pubk, | ||
}); | ||
const signtureBytes = await ed.sign( | ||
Buffer.from(body), | ||
Buffer.from(identity.getKeyPair().secretKey), | ||
); | ||
const signature = Buffer.from(signtureBytes).toString("hex"); | ||
return { | ||
signature, | ||
signer: Buffer.from(identity.getPublicKey().toRaw()).toString("hex"), | ||
signer: Buffer.from( | ||
await ed.getPublicKey(Buffer.from(identity.getPublicKey().toRaw())), | ||
).toString("hex"), | ||
}; | ||
} |