Skip to content

add app migrate #423

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

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type {
AppSecretResponse,
AppBillingResponse,
} from './types/app';
import { Keystore } from './types';
import { buildClient } from './utils/client';
import { getOwnershipTransferTipBody, signEd25519PIN, signTipBody } from './utils';

// TODO add app api for developer document
/**
Expand All @@ -20,7 +22,7 @@ import { buildClient } from './utils/client';
* * Each Mixin user can only create two free apps
* https://developers.mixin.one/
*/
export const AppKeystoreClient = (axiosInstance: AxiosInstance) => ({
export const AppKeystoreClient = (axiosInstance: AxiosInstance, keystore: Keystore | undefined) => ({
/** Get information of current user's a specific app */
fetch: (appID: string): Promise<AppResponse> => axiosInstance.get<unknown, AppResponse>(`/apps/${appID}`),

Expand Down Expand Up @@ -74,6 +76,19 @@ export const AppKeystoreClient = (axiosInstance: AxiosInstance) => ({

/** Removing from your share list */
unfavorite: (appID: string): Promise<any> => axiosInstance.post<unknown, any>(`/apps/${appID}/unfavorite`),

// Migrate app to receiver id with the keystore of this app
// pin is the spend private key of this app
migrate: (pin: string, receiverID: string) => {
if (!keystore) throw new Error('invalid keystore to migrate app');
const msg = getOwnershipTransferTipBody(receiverID);
const signedTipPin = signTipBody(pin, msg);
const pin_base64 = signEd25519PIN(signedTipPin, keystore);
return axiosInstance.post<unknown, AppResponse>(`/apps/${keystore.app_id}/transfer`, {
pin_base64,
user_id: receiverID,
});
},
});

export const AppClient = buildClient(AppKeystoreClient);
Expand Down
2 changes: 1 addition & 1 deletion src/client/mixin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { SafeKeystoreClient } from './safe';

const KeystoreClient = (axiosInstance: AxiosInstance, keystore: Keystore | undefined, config: HTTPConfig) => ({
address: AddressKeystoreClient(axiosInstance, keystore),
app: AppKeystoreClient(axiosInstance),
app: AppKeystoreClient(axiosInstance, keystore),
asset: AssetKeystoreClient(axiosInstance),
blaze: BlazeKeystoreClient(keystore, config.blazeOptions),
attachment: AttachmentKeystoreClient(axiosInstance),
Expand Down
6 changes: 3 additions & 3 deletions src/client/types/utxo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export interface UtxoOutput {
}

export interface KernelDeposit {
chain: string;
deposit_hash: string;
deposit_index: number;
chain: string;
deposit_hash: string;
deposit_index: number;
}

export interface SafeUtxoOutput extends UtxoOutput {
Expand Down
5 changes: 5 additions & 0 deletions src/client/utils/pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export const getVerifyPinTipBody = (timestamp: number) => {
return Buffer.from(msg);
};

export const getOwnershipTransferTipBody = (user_id: string) => {
const msg = `TIP:APP:OWNERSHIP:TRANSFER:${user_id}`;
return sha256Hash(Buffer.from(msg));
};

export const signTipBody = (pin: string, msg: Buffer) => {
const signData = Buffer.from(ed25519.sign(msg, pin));
return signData.toString('hex');
Expand Down