Skip to content

Commit

Permalink
🔄 synced file(s) with circlefin/pw-sdk-nodejs-server-internal (#11)
Browse files Browse the repository at this point in the history
synced local file(s) with
[circlefin/pw-sdk-nodejs-server-internal](https://github.com/circlefin/pw-sdk-nodejs-server-internal).



<details>
<summary>Changed files</summary>
<ul>
<li>synced local <code>package.json</code> with remote
<code>package.json</code></li><li>synced local <code>yarn.lock</code>
with remote <code>yarn.lock</code></li><li>synced local directory
<code>src/</code> with remote directory <code>src/</code></li><li>synced
local <code>.nvmrc</code> with remote <code>.nvmrc</code></li>
</ul>
</details>

---

This PR was created automatically by the
[repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action)
workflow run
[#12641921424](https://github.com/circlefin/pw-sdk-nodejs-server-internal/actions/runs/12641921424)
  • Loading branch information
heondokim authored Jan 9, 2025
2 parents e5f8ea6 + e3e2dcb commit b86694c
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.9.0
v20.18.0
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"env:config": "cp .env.sample .env",
"test": "jest",
"test:coverage": "jest --coverage",
"dev": "tsx watch src/index.ts",
"start": "npx ts-node src/index.ts",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
Expand All @@ -16,7 +17,7 @@
"author": "@circle-fin",
"license": "ISC",
"dependencies": {
"@circle-fin/user-controlled-wallets": "^4.0.0",
"@circle-fin/user-controlled-wallets": "^4.1.1",
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.1",
Expand All @@ -42,7 +43,7 @@
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"tsx": "^4.7.2"
"tsx": "4.19.2"
},
"packageManager": "yarn@1.22.19"
}
3 changes: 2 additions & 1 deletion src/controllers/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const dripFaucet = async (
await circleUserSdk.requestTestnetTokens({
address: req.body.address,
blockchain: req.body.blockchain,
usdc: true
usdc: true,
native: req.body.blockchain === 'AVAX-FUJI'
});

res.status(200).send();
Expand Down
18 changes: 18 additions & 0 deletions src/controllers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Blockchain } from '@circle-fin/user-controlled-wallets';
import { circleUserSdk } from '../services';
import { Request, Response, NextFunction } from 'express';

Expand Down Expand Up @@ -67,3 +68,20 @@ export const getWallet = async (
next(error);
}
};

export const createWallet = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const response = await circleUserSdk.createWallet({
blockchains: [req.body.blockchain as Blockchain],
userToken: req.headers['token'] as string
});

res.status(200).send(response.data?.challengeId);
} catch (error: unknown) {
next(error);
}
};
35 changes: 34 additions & 1 deletion src/routers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ import {
validate,
walletTokenBalanceSchema
} from '../middleware';
import { getWallet, getWalletTokenBalance, listWallets } from '../controllers';
import {
createWallet,
getWallet,
getWalletTokenBalance,
listWallets
} from '../controllers';

import * as yup from 'yup';

const wallets = express.Router();

Expand Down Expand Up @@ -122,4 +129,30 @@ wallets.get(
*/
wallets.get('/:id', validate(getWalletSchema), getWallet);

/**
* POST - /wallets
* Creates a user controlled wallet with given blockchain.
*
* Body:
* blockchain: Blockchain - Blockchain network to create wallet on
*
* Returns:
* challengeId: string - used to initiate a challenge flow for the user to create new wallet
*
*/
wallets.post(
'/',
validate(
yup.object({
body: yup
.object({
blockchain: yup.string().required()
})
.noUnknown(true)
.strict()
})
),
createWallet
);

export { wallets };
Loading

0 comments on commit b86694c

Please sign in to comment.