diff --git a/libs/api/core/data-access/src/lib/protocol/api-core-protocol.service.ts b/libs/api/core/data-access/src/lib/protocol/api-core-protocol.service.ts index a9819f4c..f82b7000 100644 --- a/libs/api/core/data-access/src/lib/protocol/api-core-protocol.service.ts +++ b/libs/api/core/data-access/src/lib/protocol/api-core-protocol.service.ts @@ -1,18 +1,22 @@ import { AnchorProvider } from '@coral-xyz/anchor' import { Injectable, Logger, OnModuleInit } from '@nestjs/common' import { - PUBKEY_PROFILE_PROGRAM_ID, - PubKeyIdentityProvider, + AnchorKeypairWallet, + getKeypairFromByteArray, + IdentityProvider, + ProfileGetByProvider, + ProfileGetByUsername, + PUBKEY_PROTOCOL_PROGRAM_ID, + PubKeyCommunity, PubKeyPointer, PubKeyProfile, -} from '@pubkey-program-library/anchor' -import { AnchorKeypairWallet, GetProfileByUsername, PubKeyProfileSdk } from '@pubkey-program-library/sdk' -import { GetProfileByProvider } from '@pubkey-program-library/sdk/src/lib/pubkey-profile-sdk' + PubkeyProtocolSdk, +} from '@pubkey-protocol/sdk' import { Connection, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js' import { ApiCoreConfigService } from '../config/api-core-config.service' function isValidProvider(provider: string): boolean { - return Object.values(PubKeyIdentityProvider).includes(provider as PubKeyIdentityProvider) + return Object.values(IdentityProvider).includes(provider as IdentityProvider) } @Injectable() @@ -20,7 +24,7 @@ export class ApiCoreProtocolService implements OnModuleInit { private readonly logger = new Logger(ApiCoreProtocolService.name) private feePayer: Keypair | undefined private connection: Connection | undefined - private sdk: PubKeyProfileSdk | undefined + private sdk: PubkeyProtocolSdk | undefined constructor(private readonly config: ApiCoreConfigService) {} @@ -34,16 +38,16 @@ export class ApiCoreProtocolService implements OnModuleInit { return } - this.feePayer = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(this.config.pubkeyProtocolFeePayer))) + this.feePayer = getKeypairFromByteArray(JSON.parse(this.config.pubkeyProtocolFeePayer)) this.connection = new Connection(this.config.pubkeyProtocolEndpoint, 'confirmed') this.logger.verbose(`PubKey Protocol: Endpoint: ${this.config.pubkeyProtocolEndpoint}`) const balance = await this.connection.getBalance(this.feePayer.publicKey) this.logger.verbose( `PubKey Protocol: Fee payer: ${this.feePayer.publicKey}, balance: ${balance / LAMPORTS_PER_SOL}`, ) - this.sdk = new PubKeyProfileSdk({ + this.sdk = new PubkeyProtocolSdk({ connection: this.connection, - programId: PUBKEY_PROFILE_PROGRAM_ID, + programId: PUBKEY_PROTOCOL_PROGRAM_ID, provider: new AnchorProvider(this.connection, new AnchorKeypairWallet(this.feePayer), { commitment: this.connection.commitment, }), @@ -59,26 +63,34 @@ export class ApiCoreProtocolService implements OnModuleInit { return this.sdk } - async getProfileByProvider(options: GetProfileByProvider): Promise { + async getCommunity(options: { community: string }): Promise { + return this.ensureSdk().communityGet(options) + } + + async getCommunities(): Promise { + return this.ensureSdk().communityGetAll() + } + + async getProfileByProvider(options: ProfileGetByProvider): Promise { if (!isValidProvider(options.provider)) { throw new Error(`Invalid provider: ${options.provider}`) } - return this.ensureSdk().getProfileByProviderNullable(options) + return this.ensureSdk().profileGetByProviderNullable(options) } - async getProfileByUsername(options: GetProfileByUsername): Promise { - return this.ensureSdk().getProfileByUsernameNullable(options) + async getProfileByUsername(options: ProfileGetByUsername): Promise { + return this.ensureSdk().profileGetByUsernameNullable(options) } async getProfiles(): Promise { - return this.ensureSdk().getProfiles() + return this.ensureSdk().profileGetAll() } getProviders() { - return Object.values(PubKeyIdentityProvider) + return Object.values(IdentityProvider) } async getPointers(): Promise { - return this.ensureSdk().getPointers() + return this.ensureSdk().pointerGetAll() } } diff --git a/libs/api/core/feature/src/lib/api-core-protocol.controller.ts b/libs/api/core/feature/src/lib/api-core-protocol.controller.ts index 7d3f5925..f73a097e 100644 --- a/libs/api/core/feature/src/lib/api-core-protocol.controller.ts +++ b/libs/api/core/feature/src/lib/api-core-protocol.controller.ts @@ -1,11 +1,25 @@ -import { Controller, Get, Param } from '@nestjs/common' +import { Controller, Get, NotFoundException, Param } from '@nestjs/common' import { ApiCoreService } from '@pubkey-link/api-core-data-access' -import { PubKeyIdentityProvider } from '@pubkey-program-library/anchor' +import { IdentityProvider } from '@pubkey-protocol/sdk' -@Controller() +@Controller('ppl') export class ApiCoreProtocolController { constructor(private readonly service: ApiCoreService) {} + @Get('communities') + communities() { + return this.service.protocol.getCommunities() + } + + @Get('community/:community') + async community(@Param('community') community: string) { + const found = await this.service.protocol.getCommunity({ community }) + if (found) { + return found + } + throw new NotFoundException('Profile not found') + } + @Get('pointers') pointers() { return this.service.protocol.getPointers() @@ -22,12 +36,20 @@ export class ApiCoreProtocolController { } @Get('provider/:provider/:providerId') - profileByProvider(@Param('provider') provider: PubKeyIdentityProvider, @Param('providerId') providerId: string) { - return this.service.protocol.getProfileByProvider({ providerId, provider }) + async profileByProvider(@Param('provider') provider: IdentityProvider, @Param('providerId') providerId: string) { + const found = await this.service.protocol.getProfileByProvider({ providerId, provider }) + if (found) { + return found + } + throw new NotFoundException('Profile not found') } - @Get('username/:username') - profileByUsername(@Param('username') username: string) { - return this.service.protocol.getProfileByUsername({ username }) + @Get('profile/:username') + async profileByUsername(@Param('username') username: string) { + const found = await this.service.protocol.getProfileByUsername({ username }) + if (found) { + return found + } + throw new NotFoundException('Profile not found') } } diff --git a/libs/api/network/data-access/src/lib/api-network-cluster.service.ts b/libs/api/network/data-access/src/lib/api-network-cluster.service.ts index bf090cbc..8742acd2 100644 --- a/libs/api/network/data-access/src/lib/api-network-cluster.service.ts +++ b/libs/api/network/data-access/src/lib/api-network-cluster.service.ts @@ -6,7 +6,7 @@ import { Injectable, Logger } from '@nestjs/common' import { OnEvent } from '@nestjs/event-emitter' import { Network, NetworkCluster } from '@prisma/client' import { ApiCoreService } from '@pubkey-link/api-core-data-access' -import { AnchorKeypairWallet } from '@pubkey-program-library/sdk' +import { AnchorKeypairWallet } from '@pubkey-protocol/sdk' import { Connection, Keypair } from '@solana/web3.js' import { ChainId, Client } from '@solflare-wallet/utl-sdk' import { diff --git a/libs/api/user/data-access/src/lib/api-user-data.service.ts b/libs/api/user/data-access/src/lib/api-user-data.service.ts index 683c0305..057da183 100644 --- a/libs/api/user/data-access/src/lib/api-user-data.service.ts +++ b/libs/api/user/data-access/src/lib/api-user-data.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common' import { Prisma } from '@prisma/client' import { ApiCoreService, PagingInputFields } from '@pubkey-link/api-core-data-access' -import { PubKeyIdentityProvider } from '@pubkey-program-library/anchor' +import { IdentityProvider } from '@pubkey-protocol/sdk' import { UserPaging } from './entity/user.entity' @Injectable() @@ -77,7 +77,7 @@ export class ApiUserDataService { for (const identity of found.identities) { console.log(`Checking ${identity.provider} ${identity.providerId}`) foundPubkeyProfile = await this.core.protocol.getProfileByProvider({ - provider: identity.provider as PubKeyIdentityProvider, + provider: identity.provider as IdentityProvider, providerId: identity.providerId, }) if (foundPubkeyProfile) { diff --git a/package.json b/package.json index 1d126e66..a9411458 100644 --- a/package.json +++ b/package.json @@ -71,8 +71,7 @@ "@ogma/platform-express": "^5.0.1", "@ogma/platform-graphql": "^5.0.1", "@prisma/client": "5.18.0", - "@pubkey-program-library/anchor": "^1.7.1", - "@pubkey-program-library/sdk": "^1.7.1", + "@pubkey-protocol/sdk": "^1.0.0", "@pubkey-ui/core": "^1.7.0", "@pubkeyapp/wallet-adapter-mantine-ui": "^2.3.0", "@solana-developers/helpers": "^2.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9217c6dd..d9dbf1bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,12 +122,9 @@ importers: '@prisma/client': specifier: 5.18.0 version: 5.18.0(prisma@5.18.0) - '@pubkey-program-library/anchor': - specifier: ^1.7.1 - version: 1.7.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) - '@pubkey-program-library/sdk': - specifier: ^1.7.1 - version: 1.7.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@pubkey-protocol/sdk': + specifier: ^1.0.0 + version: 1.0.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@pubkey-ui/core': specifier: ^1.7.0 version: 1.7.0(@types/react@18.3.1)(dayjs@1.11.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -1662,16 +1659,30 @@ packages: bundledDependencies: - is-unicode-supported + '@coral-xyz/anchor-errors@0.30.1': + resolution: {integrity: sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ==} + engines: {node: '>=10'} + '@coral-xyz/anchor@0.29.0': resolution: {integrity: sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA==} engines: {node: '>=11'} + '@coral-xyz/anchor@0.30.1': + resolution: {integrity: sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ==} + engines: {node: '>=11'} + '@coral-xyz/borsh@0.29.0': resolution: {integrity: sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ==} engines: {node: '>=10'} peerDependencies: '@solana/web3.js': ^1.68.0 + '@coral-xyz/borsh@0.30.1': + resolution: {integrity: sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ==} + engines: {node: '>=10'} + peerDependencies: + '@solana/web3.js': ^1.68.0 + '@cspotcode/source-map-support@0.8.1': resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} @@ -3339,11 +3350,11 @@ packages: '@protobufjs/utf8@1.1.0': resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==} - '@pubkey-program-library/anchor@1.7.1': - resolution: {integrity: sha512-3GbBcr9+xggp0JHAEtHIN1ZjxAwIBVh66C+rjfX/lqkGFsmUHNNNVX81jB6C9P6S7WWbIvT84mPr3y6SoAZ41A==} + '@pubkey-protocol/anchor@1.0.0': + resolution: {integrity: sha512-nqkUe0XWpAS5CFz0PhQ9k2RNHmSB3lxzYHYPnRnpO532omc9od7kqyEHMGKRQQbRcIHy8Lrmk4/QBYaEOu+lJQ==} - '@pubkey-program-library/sdk@1.7.1': - resolution: {integrity: sha512-GEJEWxTVQ+C0xaZ9Yqvm3PeXHcB1uxaqDpGRqtoBAuXk5MHOsoWycQCXpLafnnfJtAaTiMG5e4fbWQVPj/wfoQ==} + '@pubkey-protocol/sdk@1.0.0': + resolution: {integrity: sha512-P7Qfk8BW3j3o16W99tDrT20CvmNzpw1aa6//54/WWDUE7u3yLydu4BSDnJWjhzdER/zstb1snE5/H5LI631gog==} '@pubkey-ui/core@1.7.0': resolution: {integrity: sha512-mVpdcnN+CeFqup0IGRZRLUvDiOWPBmcRILmitriLBB4089iAC9EzUM3loTYt9oxj/MDjkrbMmMiE50Uo0ai7fA==} @@ -11871,8 +11882,8 @@ snapshots: '@aws-crypto/sha1-browser': 3.0.0 '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.575.0(@aws-sdk/client-sts@3.575.0) - '@aws-sdk/client-sts': 3.575.0 + '@aws-sdk/client-sso-oidc': 3.575.0 + '@aws-sdk/client-sts': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0) '@aws-sdk/core': 3.575.0 '@aws-sdk/credential-provider-node': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0)(@aws-sdk/client-sts@3.575.0) '@aws-sdk/middleware-bucket-endpoint': 3.575.0 @@ -11929,11 +11940,11 @@ snapshots: transitivePeerDependencies: - aws-crt - '@aws-sdk/client-sso-oidc@3.575.0(@aws-sdk/client-sts@3.575.0)': + '@aws-sdk/client-sso-oidc@3.575.0': dependencies: '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sts': 3.575.0 + '@aws-sdk/client-sts': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0) '@aws-sdk/core': 3.575.0 '@aws-sdk/credential-provider-node': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0)(@aws-sdk/client-sts@3.575.0) '@aws-sdk/middleware-host-header': 3.575.0 @@ -11972,7 +11983,6 @@ snapshots: '@smithy/util-utf8': 3.0.0 tslib: 2.6.3 transitivePeerDependencies: - - '@aws-sdk/client-sts' - aws-crt '@aws-sdk/client-sso@3.575.0': @@ -12018,11 +12028,11 @@ snapshots: transitivePeerDependencies: - aws-crt - '@aws-sdk/client-sts@3.575.0': + '@aws-sdk/client-sts@3.575.0(@aws-sdk/client-sso-oidc@3.575.0)': dependencies: '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.575.0(@aws-sdk/client-sts@3.575.0) + '@aws-sdk/client-sso-oidc': 3.575.0 '@aws-sdk/core': 3.575.0 '@aws-sdk/credential-provider-node': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0)(@aws-sdk/client-sts@3.575.0) '@aws-sdk/middleware-host-header': 3.575.0 @@ -12061,6 +12071,7 @@ snapshots: '@smithy/util-utf8': 3.0.0 tslib: 2.6.3 transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' - aws-crt '@aws-sdk/core@3.575.0': @@ -12094,7 +12105,7 @@ snapshots: '@aws-sdk/credential-provider-ini@3.575.0(@aws-sdk/client-sso-oidc@3.575.0)(@aws-sdk/client-sts@3.575.0)': dependencies: - '@aws-sdk/client-sts': 3.575.0 + '@aws-sdk/client-sts': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0) '@aws-sdk/credential-provider-env': 3.575.0 '@aws-sdk/credential-provider-process': 3.575.0 '@aws-sdk/credential-provider-sso': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0) @@ -12151,7 +12162,7 @@ snapshots: '@aws-sdk/credential-provider-web-identity@3.575.0(@aws-sdk/client-sts@3.575.0)': dependencies: - '@aws-sdk/client-sts': 3.575.0 + '@aws-sdk/client-sts': 3.575.0(@aws-sdk/client-sso-oidc@3.575.0) '@aws-sdk/types': 3.575.0 '@smithy/property-provider': 3.0.0 '@smithy/types': 3.0.0 @@ -12267,7 +12278,7 @@ snapshots: '@aws-sdk/token-providers@3.575.0(@aws-sdk/client-sso-oidc@3.575.0)': dependencies: - '@aws-sdk/client-sso-oidc': 3.575.0(@aws-sdk/client-sts@3.575.0) + '@aws-sdk/client-sso-oidc': 3.575.0 '@aws-sdk/types': 3.575.0 '@smithy/property-provider': 3.0.0 '@smithy/shared-ini-file-loader': 3.0.0 @@ -13307,6 +13318,8 @@ snapshots: picocolors: 1.0.0 sisteransi: 1.0.5 + '@coral-xyz/anchor-errors@0.30.1': {} + '@coral-xyz/anchor@0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@coral-xyz/borsh': 0.29.0(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10)) @@ -13328,12 +13341,40 @@ snapshots: - encoding - utf-8-validate + '@coral-xyz/anchor@0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + dependencies: + '@coral-xyz/anchor-errors': 0.30.1 + '@coral-xyz/borsh': 0.30.1(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + '@noble/hashes': 1.4.0 + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) + bn.js: 5.2.1 + bs58: 4.0.1 + buffer-layout: 1.2.2 + camelcase: 6.3.0 + cross-fetch: 3.1.8 + crypto-hash: 1.3.0 + eventemitter3: 4.0.7 + pako: 2.1.0 + snake-case: 3.0.4 + superstruct: 0.15.5 + toml: 3.0.0 + transitivePeerDependencies: + - bufferutil + - encoding + - utf-8-validate + '@coral-xyz/borsh@0.29.0(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))': dependencies: '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) bn.js: 5.2.1 buffer-layout: 1.2.2 + '@coral-xyz/borsh@0.30.1(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))': + dependencies: + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) + bn.js: 5.2.1 + buffer-layout: 1.2.2 + '@cspotcode/source-map-support@0.8.1': dependencies: '@jridgewell/trace-mapping': 0.3.9 @@ -16054,9 +16095,9 @@ snapshots: '@protobufjs/utf8@1.1.0': {} - '@pubkey-program-library/anchor@1.7.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@pubkey-protocol/anchor@1.0.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: - '@coral-xyz/anchor': 0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@coral-xyz/anchor': 0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@noble/hashes': 1.4.0 '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) transitivePeerDependencies: @@ -16064,10 +16105,10 @@ snapshots: - encoding - utf-8-validate - '@pubkey-program-library/sdk@1.7.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@pubkey-protocol/sdk@1.0.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: - '@coral-xyz/anchor': 0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) - '@pubkey-program-library/anchor': 1.7.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@coral-xyz/anchor': 0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@pubkey-protocol/anchor': 1.0.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@solana-developers/helpers': 2.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) transitivePeerDependencies: