-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from near/fix-and-keys
Fix and keys
- Loading branch information
Showing
17 changed files
with
176 additions
and
410 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,36 @@ | ||
import * as vscode from 'vscode'; | ||
import { APP_NAME } from '../config'; | ||
import { KeyPair } from 'near-api-js'; | ||
import { addToContext, getFromContext } from '../extension'; | ||
|
||
export const addKeyForContract = async (context: vscode.ExtensionContext, localWorkspace: string) => { | ||
const contractId = await vscode.window.showInputBox({ placeHolder: 'Which contract do you want to call?' }); | ||
const accountId = getFromContext(localWorkspace, "accountId"); | ||
|
||
if(!accountId){ | ||
return vscode.window.showErrorMessage('Please login first'); | ||
} | ||
|
||
if (contractId) { | ||
const publisher = context.extension.packageJSON.publisher; | ||
const name = context.extension.packageJSON.name; | ||
const callback = `${vscode.env.uriScheme}://${publisher}.${name}`; | ||
|
||
// Create a private key to interact with the social contract | ||
const keyPair = KeyPair.fromRandom("ED25519"); | ||
const publicKey = keyPair.getPublicKey().toString(); | ||
|
||
// Save the private access key in context.json | ||
await addToContext(localWorkspace, 'accessKey', keyPair.toString()); | ||
|
||
context.globalState.update('addKeyForContract', true); | ||
|
||
// Create the login URL and redirect the user to login | ||
const networkId = await getFromContext(localWorkspace, 'networkId') || "mainnet"; | ||
|
||
let url = `https://wallet.${networkId}.near.org/login/?title=${APP_NAME}&success_url=${callback}&contract_id=${contractId}&public_key=${publicKey}&account_id=${accountId}`; | ||
vscode.env.openExternal(vscode.Uri.parse(url)); | ||
} else { | ||
vscode.window.showErrorMessage('Invalid Contract ID'); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import * as vscode from 'vscode'; | ||
import { APP_NAME } from '../config'; | ||
import { APP_NAME, contractAccountForNetwork } from '../config'; | ||
import { KeyPair } from 'near-api-js'; | ||
import { addToContext } from '../extension'; | ||
import { addToContext, getFromContext } from '../extension'; | ||
|
||
export const loginAccount = async (context: vscode.ExtensionContext, network: string, localWorkspace: string) => { | ||
export const loginAccount = async (context: vscode.ExtensionContext, localWorkspace: string) => { | ||
const publisher = context.extension.packageJSON.publisher; | ||
const name = context.extension.packageJSON.name; | ||
const callback = `${vscode.env.uriScheme}://${publisher}.${name}`; | ||
|
||
// Create a private key to interact with the social contract | ||
const contractId = "social.near"; | ||
const keyPair = KeyPair.fromRandom("ED25519"); | ||
const publicKey = keyPair.getPublicKey().toString(); | ||
|
||
// Save the private access key in context.json | ||
await addToContext(localWorkspace, 'accessKey', keyPair.toString()); | ||
|
||
const networkId = await getFromContext(localWorkspace, 'networkId') || "mainnet"; | ||
const contractId = contractAccountForNetwork(networkId); | ||
|
||
// Create the login URL and redirect the user to login | ||
let url = `https://wallet.${network}.near.org/login/?title=${APP_NAME}&success_url=${callback}&contract_id=${contractId}&public_key=${publicKey}`; | ||
let url = `https://wallet.${networkId}.near.org/login/?title=${APP_NAME}&success_url=${callback}&contract_id=${contractId}&public_key=${publicKey}&methodNames=set`; | ||
vscode.env.openExternal(vscode.Uri.parse(url)); | ||
}; |
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
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
Oops, something went wrong.