-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit - baseic firebase project
- Loading branch information
1 parent
957fdba
commit 864e24c
Showing
5 changed files
with
955 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const admin = require('firebase-admin'); | ||
|
||
const { Accounts } = require('web3-eth-accounts') //Web3js 1.0 dependencies | ||
const accounts = new Accounts('https://kovan.infura.io/v3/f1be797452774133a11f7688f5316a47'); | ||
|
||
const path = require('path'); | ||
|
||
const bucket = admin.storage().bucket('gs://mvp-blockchain-serverless'); | ||
|
||
exports.ethereumAccountCreate = async function ethereumAccountCreate(snap, context) { | ||
|
||
const pass = "12345678"; | ||
|
||
try { | ||
var accCreated = accounts.create(); | ||
var accEncrypted = accounts.encrypt(accCreated.privateKey, pass); | ||
|
||
if (!accEncrypted) | ||
console.error(new Error("Error while encrypting account")); | ||
|
||
} catch (error) { | ||
console.error(new Error("Error while creating account", error)); | ||
} | ||
|
||
let fileData = JSON.stringify(accEncrypted); | ||
let fileName = `${context.params.uid}.json`; | ||
let bucketfilePath = path.join(`/users/${context.params.uid}/ethereum/`, fileName); | ||
|
||
let file = bucket.file(bucketfilePath); | ||
await file.save(fileData, { contentType: "application/json" }); | ||
await snap.ref.update({ | ||
"ethereum": { | ||
"address": accCreated.address, | ||
"privateKey": accCreated.privateKey, | ||
"walletFile": accEncrypted | ||
} | ||
}); | ||
|
||
return true; | ||
} |
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 |
---|---|---|
@@ -1,8 +1,19 @@ | ||
const functions = require('firebase-functions'); | ||
|
||
// // Create and Deploy Your First Cloud Functions | ||
// // https://firebase.google.com/docs/functions/write-firebase-functions | ||
// | ||
// exports.helloWorld = functions.https.onRequest((request, response) => { | ||
// response.send("Hello from Firebase!"); | ||
// }); | ||
const admin = require('firebase-admin'); | ||
admin.initializeApp(); | ||
|
||
const db = admin.firestore(); | ||
db.settings({ timestampsInSnapshots: true }); | ||
|
||
const { ethereumAccountCreate } = require("./ethereumAccountCreate"); | ||
|
||
const runtimeOpts = { /* runtime options: https://firebase.google.com/docs/functions/manage-functions */ | ||
timeoutSeconds: 120, /* 1-540 (9 minutes) */ | ||
memory: '256MB' /* 128MB 256MB 512MB 1GB 2GB */ | ||
}; | ||
|
||
exports.ethereum = { | ||
accountCreate: functions.runWith(runtimeOpts).firestore.document('/users/{uid}') | ||
.onCreate((snap, context) => ethereumAccountCreate(snap, context)) | ||
} |
Oops, something went wrong.