@@ -10,7 +10,9 @@ import type {
10
10
AppSecretResponse ,
11
11
AppBillingResponse ,
12
12
} from './types/app' ;
13
+ import { Keystore } from './types' ;
13
14
import { buildClient } from './utils/client' ;
15
+ import { getOwnershipTransferTipBody , signEd25519PIN , signTipBody } from './utils' ;
14
16
15
17
// TODO add app api for developer document
16
18
/**
@@ -20,7 +22,7 @@ import { buildClient } from './utils/client';
20
22
* * Each Mixin user can only create two free apps
21
23
* https://developers.mixin.one/
22
24
*/
23
- export const AppKeystoreClient = ( axiosInstance : AxiosInstance ) => ( {
25
+ export const AppKeystoreClient = ( axiosInstance : AxiosInstance , keystore : Keystore | undefined ) => ( {
24
26
/** Get information of current user's a specific app */
25
27
fetch : ( appID : string ) : Promise < AppResponse > => axiosInstance . get < unknown , AppResponse > ( `/apps/${ appID } ` ) ,
26
28
@@ -74,6 +76,19 @@ export const AppKeystoreClient = (axiosInstance: AxiosInstance) => ({
74
76
75
77
/** Removing from your share list */
76
78
unfavorite : ( appID : string ) : Promise < any > => axiosInstance . post < unknown , any > ( `/apps/${ appID } /unfavorite` ) ,
79
+
80
+ // Migrate app to receiver id with the keystore of this app
81
+ // pin is the spend private key of this app
82
+ migrate : ( pin : string , receiverID : string ) => {
83
+ if ( ! keystore ) throw new Error ( 'invalid keystore to migrate app' ) ;
84
+ const msg = getOwnershipTransferTipBody ( receiverID ) ;
85
+ const signedTipPin = signTipBody ( pin , msg ) ;
86
+ const pin_base64 = signEd25519PIN ( signedTipPin , keystore ) ;
87
+ return axiosInstance . post < unknown , AppResponse > ( `/apps/${ keystore . app_id } /transfer` , {
88
+ pin_base64,
89
+ user_id : receiverID ,
90
+ } ) ;
91
+ } ,
77
92
} ) ;
78
93
79
94
export const AppClient = buildClient ( AppKeystoreClient ) ;
0 commit comments