diff --git a/.changeset/witty-walls-leave.md b/.changeset/witty-walls-leave.md new file mode 100644 index 0000000..512de11 --- /dev/null +++ b/.changeset/witty-walls-leave.md @@ -0,0 +1,5 @@ +--- +'@aurora-is-near/backstage-plugin-blockchainradar-backend': patch +--- + +feat: add longer keyscheme support diff --git a/plugins/blockchainradar-backend/src/entities/BlockchainAddress.ts b/plugins/blockchainradar-backend/src/entities/BlockchainAddress.ts index 22f2f9e..21add88 100644 --- a/plugins/blockchainradar-backend/src/entities/BlockchainAddress.ts +++ b/plugins/blockchainradar-backend/src/entities/BlockchainAddress.ts @@ -4,15 +4,9 @@ import { BlockchainProcessor } from '../processors/BlockchainProcessor'; import { BlockchainHandler } from './BlockchainHandler'; -import * as crypto from 'crypto'; -import * as bs58 from 'bs58'; import { AdapterFactory } from '../adapters/AdapterFactory'; import { SILO_NAMES_BY_CHAIN_ID, isSiloChainId } from '../lib/networks'; - -function base58EncodeSha256(str: string): string { - const hash = crypto.createHash('sha256').update(str).digest(); - return bs58.encode(hash); -} +import { base58EncodeSha256 } from '../lib/utils'; const TESTNET_IDS = ['testnet', 'goerli']; const SIGNER_KINDS = ['Group', 'User']; diff --git a/plugins/blockchainradar-backend/src/entities/NearKey.ts b/plugins/blockchainradar-backend/src/entities/NearKey.ts index 69273b1..18b23a5 100644 --- a/plugins/blockchainradar-backend/src/entities/NearKey.ts +++ b/plugins/blockchainradar-backend/src/entities/NearKey.ts @@ -1,6 +1,7 @@ import { BlockchainHandler } from './BlockchainHandler'; import { Entity } from '@backstage/catalog-model'; import { BlockchainProcessor } from '../processors/BlockchainProcessor'; +import { base58EncodeSha256 } from '../lib/utils'; export class NearKey extends BlockchainHandler { publicKey: string; @@ -19,6 +20,10 @@ export class NearKey extends BlockchainHandler { } entityName() { + if (this.publicKey.length > 63) { + const [scheme] = this.publicKey.split(':'); + return `${scheme}-${base58EncodeSha256(this.publicKey)}`; + } return this.publicKey.replace(':', '-'); } @@ -50,7 +55,10 @@ export class NearKey extends BlockchainHandler { apiVersion: 'backstage.io/v1alpha1', kind: 'Resource', metadata: this.entityMetadata(), - spec: this.entitySpec(), + spec: { + ...this.entitySpec(), + type: 'access-key', + }, }; } } diff --git a/plugins/blockchainradar-backend/src/lib/utils.ts b/plugins/blockchainradar-backend/src/lib/utils.ts new file mode 100644 index 0000000..2e17109 --- /dev/null +++ b/plugins/blockchainradar-backend/src/lib/utils.ts @@ -0,0 +1,7 @@ +import * as crypto from 'crypto'; +import * as bs58 from 'bs58'; + +export function base58EncodeSha256(str: string): string { + const hash = crypto.createHash('sha256').update(str).digest(); + return bs58.encode(hash); +}