Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
poolsar42 committed May 30, 2023
1 parent d88151c commit 1a03bae
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 36 deletions.
2 changes: 0 additions & 2 deletions platform/account/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ interface CreateInnerContextOptions
Analytics: AnalyticsEngineDataset
ServiceDeploymentMetadata: DeploymentMetadata
account?: DurableObjectStubProxy<Account>
JWKS_INTERNAL_URL_BASE: string

// accountURN?: AccountURN
}
/**
Expand Down
1 change: 0 additions & 1 deletion platform/account/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface Environment {
Edges: Fetcher
Analytics: AnalyticsEngineDataset
ServiceDeploymentMetadata: DeploymentMetadata
JWKS_INTERNAL_URL_BASE: string
}

// TODO: move to types packages
Expand Down
12 changes: 0 additions & 12 deletions platform/account/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ analytics_engine_datasets = [

unsafe.bindings = [{ type = "metadata", name = "ServiceDeploymentMetadata" }]

[vars]
JWKS_INTERNAL_URL_BASE = 'http://127.0.0.1:10001/.well-known/jwks.json'

[dev]
port = 10201
inspector_port = 11201
local_protocol = "http"

[env.dev.vars]
JWKS_INTERNAL_URL_BASE = "https://passport-dev.pz3r0.com/.well-known/jwks.json"

[env.dev]
durable_objects.bindings = [{ name = "Account", class_name = "Account" }]
services = [{ binding = "Edges", service = "edges-dev" }]
Expand All @@ -43,9 +37,6 @@ analytics_engine_datasets = [

unsafe.bindings = [{ type = "metadata", name = "ServiceDeploymentMetadata" }]

[env.next.vars]
JWKS_INTERNAL_URL_BASE = "https://passport-next.pz3r0.com/.well-known/jwks.json"

[env.next]
durable_objects.bindings = [{ name = "Account", class_name = "Account" }]
services = [{ binding = "Edges", service = "edges-next" }]
Expand All @@ -56,9 +47,6 @@ analytics_engine_datasets = [

unsafe.bindings = [{ type = "metadata", name = "ServiceDeploymentMetadata" }]

[env.current.vars]
JWKS_INTERNAL_URL_BASE = "https://passport.pz3r0.com/.well-known/jwks.json"

[env.current]
durable_objects.bindings = [{ name = "Account", class_name = "Account" }]
services = [{ binding = "Edges", service = "edges-current" }]
Expand Down
65 changes: 65 additions & 0 deletions platform/address/src/jsonrpc/methods/testSessionKey.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Context } from '../../context'
import { Wallet } from '@ethersproject/wallet'
import { Contract } from "@ethersproject/contracts"
import { createSessionKeySigner, getZeroDevSigner, revokeSessionKey } from '@zerodevapp/sdk'

export const testSessionKeyMethod = async ({
ctx,
}: {
ctx: Context
}): Promise<void> => {


const privateSigner = new Wallet("0xb1c63e8417063a3e329c6d6144d1f8085e13dc5a8befe88867f620887ae4fa79")

const sessionKeySigner = await createSessionKeySigner({
projectId: "d4bb41a1-fff1-48b6-afbd-11d302f63994",
skipFetchSetup: true,
sessionKeyData: "eyJvd25lckFkZHJlc3MiOiIweDM5OURCYTREM0E0OTBlZkMyNWY5RDM5M0E4NDc3YjM5MEM1NTBmOTIiLCJvd25lckluZGV4IjowLCJzaWduYXR1cmUiOiIweGU3ZmM0ZDcyZTUzMjI5M2UyNmY2NjBjYTRlZGY4NzgzNWY4ZjFmMGRjMjNjZGU1ODFlY2UzZDc3OTFiODlkMmE2YjBiODZjMDFmNzAzODkwYWNiZGQ1ODUzMTFlZDU5OTkzZjA0ZmViNzY1ZjZkZjA4NmQ2YWU2ZjkyNDczOGY0MWMiLCJ3aGl0ZWxpc3QiOltdLCJ2YWxpZFVudGlsIjo5NDYwMjY0MTg4fQ==",
privateSigner,
})

const contractAddress =
"0x34bE7f35132E97915633BC1fc020364EA5134863";
const contractABI = [
"function mint(address _to) public",
"function balanceOf(address owner) external view returns (uint256 balance)",
];
const nftContract = new Contract(
contractAddress,
contractABI,
sessionKeySigner
);
console.log({ HELLO: "EMIL" })
console.log({ address: await sessionKeySigner.getAddress() })
try {
// const receipt = await nftContract.mint("0x7a5F6EA3be6dB9dbe2bf436715a278b284ADeF61");
// await receipt.wait();
console.log({ done: "yes" })
// console.log({ hash: receipt.hash })
}
catch (e) {
console.log("MINT", e)
}

try {
const zdSigner = await getZeroDevSigner({
projectId: "d4bb41a1-fff1-48b6-afbd-11d302f63994",
owner: privateSigner,
skipFetchSetup: true,
})

console.log({
zdSigner: await zdSigner.getAddress()
})

await revokeSessionKey(zdSigner, await privateSigner.getAddress(), {
gasLimit: 300000000,
})
} catch (e) {
console.log("ZD SIGNER or REVOKE", e)
}



}
4 changes: 0 additions & 4 deletions platform/address/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ MAX_ATTEMPTS = 5
DELAY_BETWEEN_REGENERATION_ATTEMPTS_IN_MS = 2_000
REGENERATION_COOLDOWN_PERIOD_IN_MS = 30_000
MAX_ATTEMPTS_TIME_PERIOD_IN_MS = 300_000
JWKS_INTERNAL_URL_BASE = "http://127.0.0.1:10001/.well-known/jwks.json"

[dev]
port = 10102
Expand Down Expand Up @@ -81,7 +80,6 @@ MAX_ATTEMPTS = 5
DELAY_BETWEEN_REGENERATION_ATTEMPTS_IN_MS = 2_000
REGENERATION_COOLDOWN_PERIOD_IN_MS = 30_000
MAX_ATTEMPTS_TIME_PERIOD_IN_MS = 300_000
JWKS_INTERNAL_URL_BASE = "https://passport-dev.pz3r0.com/.well-known/jwks.json"

[env.next]
durable_objects.bindings = [{ name = "Address", class_name = "Address" }]
Expand Down Expand Up @@ -109,7 +107,6 @@ MAX_ATTEMPTS = 5
DELAY_BETWEEN_REGENERATION_ATTEMPTS_IN_MS = 30_000
REGENERATION_COOLDOWN_PERIOD_IN_MS = 600_000
MAX_ATTEMPTS_TIME_PERIOD_IN_MS = 300_000
JWKS_INTERNAL_URL_BASE = "https://passport-next.pz3r0.com/.well-known/jwks.json"

[env.current]
durable_objects.bindings = [{ name = "Address", class_name = "Address" }]
Expand All @@ -136,4 +133,3 @@ MAX_ATTEMPTS = 5
DELAY_BETWEEN_REGENERATION_ATTEMPTS_IN_MS = 30_000
REGENERATION_COOLDOWN_PERIOD_IN_MS = 600_000
MAX_ATTEMPTS_TIME_PERIOD_IN_MS = 300_000
JWKS_INTERNAL_URL_BASE = "https://passport.pz3r0.com/.well-known/jwks.json"
1 change: 0 additions & 1 deletion platform/galaxy/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default interface Env {
Address: Fetcher
Starbase: Fetcher
Access: Fetcher
JWKS_INTERNAL_URL_BASE: string
}

export const required = ['Account', 'Address', 'Starbase', 'Access']
23 changes: 20 additions & 3 deletions platform/galaxy/src/schema/resolvers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
validateApiKey,
logAnalytics,
getConnectedAddresses,
temporaryConvertToPublic,
requestLogging,
} from './utils'

Expand All @@ -20,7 +21,10 @@ import { ResolverContext } from './common'
import { PlatformAddressURNHeader } from '@proofzero/types/headers'
import { getAuthzHeaderConditionallyFromToken } from '@proofzero/utils'
import type { AccountURN } from '@proofzero/urns/account'
import { generateTraceContextHeaders } from '@proofzero/packages/platform-middleware/trace'
import {
generateTraceContextHeaders,
TraceSpan,
} from '@proofzero/packages/platform-middleware/trace'

const accountResolvers: Resolvers = {
Query: {
Expand Down Expand Up @@ -154,16 +158,29 @@ const ProfileResolverComposition = {
'Query.profile': [
requestLogging(),
setupContext(),
isAuthorized('profile'),
validateApiKey(),
logAnalytics(),
],
'Query.authorizedApps': [
requestLogging(),
setupContext(),
validateApiKey(),
logAnalytics(),
],
'Query.connectedAddresses': [
requestLogging(),
setupContext(),
// isAuthorized('connected_accounts'),
validateApiKey(),
logAnalytics(),
temporaryConvertToPublic(),
],

'Mutation.disconnectAddress': [
requestLogging(),
setupContext(),
validateApiKey(),
isAuthorized(),
logAnalytics(),
],
}

Expand Down
18 changes: 7 additions & 11 deletions platform/galaxy/src/schema/resolvers/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,29 +179,25 @@ const addressResolvers: Resolvers = {

// TODO: add address middleware
const AddressResolverComposition = {
'Query.account': [
'Query.account': [requestLogging(), setupContext(), validateApiKey()],
'Query.addressProfile': [requestLogging(), setupContext(), validateApiKey()],
'Query.addressProfiles': [requestLogging(), setupContext(), validateApiKey()],
'Mutation.updateAddressNickname': [
requestLogging(),
setupContext(),
isAuthorized('profile'),
validateApiKey(),
isAuthorized(),
],

'Query.addressProfile': [
'Mutation.updateConnectedAddressesProperties': [
requestLogging(),
setupContext(),
isAuthorized('profile'),
validateApiKey(),
],
'Query.addressProfiles': [
requestLogging(),
setupContext(),
isAuthorized('connected_accounts'),
validateApiKey(),
isAuthorized(),
],
'Mutation.registerSessionKey': [
requestLogging(),
setupContext(),
isAuthorized('erc_4337'),
validateApiKey(),
],
}
Expand Down
16 changes: 14 additions & 2 deletions platform/galaxy/src/schema/resolvers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@ const appResolvers: Resolvers = {
}

const AppResolverComposition = {
//Leaving this here in case we want to (securely) expose these resolvers
//through a scope later
'Query.scopes': [
requestLogging(),
setupContext(),
validateApiKey(),
isAuthorized(),
logAnalytics(),
],
'Mutation.revokeAppAuthorization': [
requestLogging(),
setupContext(),
validateApiKey(),
isAuthorized(),
logAnalytics(),
],
}

export default composeResolvers(appResolvers, AppResolverComposition)

0 comments on commit 1a03bae

Please sign in to comment.