-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Merge branch 'main' into deployment
- Loading branch information
Showing
7 changed files
with
121 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { create } from './createUser'; | ||
import { IUser, ProgressHookType, SignerType } from '../types'; | ||
import { profileUpdate } from './profile.updateUser'; | ||
import { decryptPGPKey } from '../../../src/lib/helpers'; | ||
import Constants, { ENV } from '../constants'; | ||
|
||
export type CreateUserPropsWithProfile = { | ||
env?: ENV; | ||
account?: string; | ||
signer?: SignerType; | ||
version?: typeof Constants.ENC_TYPE_V1 | typeof Constants.ENC_TYPE_V3; | ||
additionalMeta?: { | ||
NFTPGP_V1?: { | ||
password: string; | ||
}; | ||
}; | ||
profile?: { | ||
name?: string; | ||
desc?: string; | ||
picture?: string; | ||
blockedUsersList?: Array<string>; | ||
}; | ||
progressHook?: (progress: ProgressHookType) => void; | ||
}; | ||
|
||
export const createUserWithProfile = async ( | ||
userOptions: CreateUserPropsWithProfile | ||
): Promise<IUser> => { | ||
try { | ||
let user = await create(userOptions); | ||
|
||
if (userOptions.profile) { | ||
const pk = await decryptPGPKey({ | ||
account: user.did, | ||
encryptedPGPPrivateKey: user.encryptedPrivateKey, | ||
env: userOptions.env, | ||
signer: userOptions.signer, | ||
}); | ||
|
||
|
||
user = await profileUpdate({ | ||
account: user.did, | ||
env: userOptions.env, | ||
pgpPrivateKey: pk, | ||
profile: userOptions.profile | ||
}); | ||
} | ||
return user; | ||
} catch (err) { | ||
throw new Error(`[Push SDK] - Error in createUserWithProfile -: ${err}`); | ||
} | ||
}; |
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
60 changes: 60 additions & 0 deletions
60
packages/restapi/tests/lib/user/createUserWithProfile.test.ts
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as path from 'path'; | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config({ path: path.resolve(__dirname, '../../.env') }); | ||
import * as chai from 'chai'; | ||
import { expect } from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import { createUserWithProfile } from '../../../src/lib/user'; | ||
import { ethers } from 'ethers'; | ||
import Constants from '../../../src/lib/constants'; | ||
chai.use(chaiAsPromised); | ||
|
||
describe('Create Push Profile with Profile update', () => { | ||
const _env = Constants.ENV.DEV; | ||
let provider = ethers.getDefaultProvider(5); | ||
let _signer: any; | ||
let walletAddress: string; | ||
let account: string; | ||
|
||
|
||
beforeEach(() => { | ||
provider = ethers.getDefaultProvider(5); | ||
const WALLET = ethers.Wallet.createRandom(); | ||
_signer = new ethers.Wallet(WALLET.privateKey, provider); | ||
walletAddress = _signer.address; | ||
account = `eip155:${walletAddress}`; | ||
}); | ||
|
||
|
||
it('Push Profile V3', async () => { | ||
const name = 'John'; | ||
const desc = 'He is web3 dev' | ||
const picture = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvUlEQVR4AcXBsa3CMBiF0Y+rFNarM0Jqi1EoU2QIj+IxPACTuGYEBnAH7Q+FI/SKe87lflxfGAkzYSbMFr7kMoh6TUTb2ph5PHeiXAZRr4lImAkzYbbkMoh6TUTb2vjFtjaiXneiXAaRMBNmwmzhxN9xI+o1MZPL4ENNzAgzYSbMFk70mohyGcz0mviFMBNmwmzhxLY2Pt2Y2dZG9HjuzAgzYSbMLvfj+mIil8F/9JqYEWbCTJgJM2EmzITZG0wkJb/EapQdAAAAAElFTkSuQmCC', | ||
const user = await createUserWithProfile({ | ||
account: account, | ||
env: _env, | ||
signer: _signer, | ||
profile: { | ||
name: name, | ||
desc: desc, | ||
picture: picture, | ||
}, | ||
}); | ||
console.log(user) | ||
expect(user).to.be.an('object'); | ||
expect(user).not.to.be.null; | ||
expect(user).not.to.be.undefined; | ||
expect(user.did).to.be.equal(account); | ||
expect(user.wallets).to.be.equal(account); | ||
expect(user.publicKey).to.contains( | ||
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n' | ||
); | ||
expect(user.encryptedPrivateKey).to.contains( | ||
`"version":"${Constants.ENC_TYPE_V3}"` | ||
); | ||
expect(user.profile.name).to.be.equal(name); | ||
expect(user.profile.desc).to.be.equal(desc); | ||
expect(user.profile.picture).to.be.equal(picture);; | ||
expect(user.msgSent).to.be.equal(0); | ||
}); | ||
}); |