Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Onbarding cancel signing (#23)
Browse files Browse the repository at this point in the history
* onboarding using sigPk

* Updated cancel and onboarding signing

* removed unwanted package

* Update package.json

* signature fixed for no ui flow

* latest sui
  • Loading branch information
yasserzubair authored Aug 17, 2023
1 parent 15f23ff commit 457ce1d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 198 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firefly-exchange/bluefin-client-sui",
"version": "0.0.10",
"version": "0.0.11",
"description": "The Bluefin client Library allows traders to sign, create, retrieve and listen to orders on Bluefin Exchange.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@firefly-exchange/library-sui": "0.1.40",
"@firefly-exchange/library-sui": "^0.1.41",
"@mysten/sui.js": "^0.35.0",
"@noble/hashes": "^1.2.0",
"@noble/secp256k1": "^1.7.1",
Expand Down
47 changes: 36 additions & 11 deletions src/bluefinClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class BluefinClient {
userOnBoarding = async (token?: string) => {
let userAuthToken = token;
if (!userAuthToken) {
let signature: string;
let signature: SigPK;

if (this.kmsSigner !== undefined) {
// const hashedMessageSHA = sha256(
Expand All @@ -317,15 +317,24 @@ export class BluefinClient {
// (signature = await this.kmsSigner._signDigest(hashedMessageETH));
} else {
// sign onboarding message

signature = await OnboardingSigner.createOnboardSignature(
this.network.onboardingUrl,
this.signer
);
// eslint-disable-next-line no-lonely-if
const onboardingSignature = {
onboardingUrl: this.network.onboardingUrl,
};
if (this.uiWallet) {
signature = await OrderSigner.signPayloadUsingWallet(
onboardingSignature,
this.uiWallet
);
} else {
signature = this.orderSigner.signPayload(onboardingSignature);
}
}

// authorize signature created by dAPI
const authTokenResponse = await this.authorizeSignedHash(signature);
const authTokenResponse = await this.authorizeSignedHash(
`${signature?.signature}${signature?.publicKey}`
);

if (!authTokenResponse.ok || !authTokenResponse.data) {
throw Error(
Expand Down Expand Up @@ -509,10 +518,26 @@ export class BluefinClient {
*/
createOrderCancellationSignature = async (
params: OrderCancelSignatureRequest
): Promise<string> => {
): Promise<SigPK> => {
// TODO: serialize correctly, this is the default method from suiet wallet docs
const serialized = new TextEncoder().encode(JSON.stringify(params));
return this.signer.signData(serialized);
// const serialized = new TextEncoder().encode(JSON.stringify(params));
// return this.signer.signData(serialized);
try {
let signature: SigPK;
if (this.uiWallet) {
signature = await OrderSigner.signPayloadUsingWallet(
{ orderHashes: params.hashes },
this.uiWallet
);
} else {
signature = this.orderSigner.signPayload({
orderHashes: params.hashes,
});
}
return signature;
} catch {
throw Error("Siging cancelled by user");
}
};

/**
Expand Down Expand Up @@ -548,7 +573,7 @@ export class BluefinClient {
const signature = await this.createOrderCancellationSignature(params);
const response = await this.placeCancelOrder({
...params,
signature,
signature: `${signature?.signature}${signature?.publicKey}`,
});
return response;
};
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Networks = {
dmsURL: "https://api.arbitrum-staging.firefly.exchange/dead-man-switch",
socketURL: "wss://dapi.api.arbitrum-staging.firefly.exchange",
webSocketURL: "wss://notifications.api.arbitrum-staging.firefly.exchange/",
onboardingUrl: "https://testnet.firefly.exchange",
onboardingUrl: "https://testnet.bluefin.io",
faucet: "https://faucet.devnet.sui.io",
},
PRODUCTION_SUI: {
Expand All @@ -18,7 +18,7 @@ export const Networks = {
socketURL: "wss://dapi.api.arbitrum-prod.firefly.exchange",
dmsURL: "https://api.arbitrum-prod.firefly.exchange/dead-man-switch",
webSocketURL: "wss://notifications.api.arbitrum-prod.firefly.exchange/",
onboardingUrl: "https://trade-arb.firefly.exchange",
onboardingUrl: "https://testnet.bluefin.io",
faucet: "does not exist",
},
LOCAL_SUI: {
Expand All @@ -28,7 +28,7 @@ export const Networks = {
dmsURL: "https://api.arbitrum-staging.firefly.exchange/dead-man-switch",
socketURL: "wss://dapi.api.arbitrum-staging.firefly.exchange",
webSocketURL: "wss://notifications.api.arbitrum-staging.firefly.exchange/",
onboardingUrl: "https://testnet.firefly.exchange",
onboardingUrl: "https://testnet.bluefin.io",
faucet: "http://127.0.0.1:5003/gas",
},
};
Expand Down
Loading

0 comments on commit 457ce1d

Please sign in to comment.