Skip to content

Commit

Permalink
feat: add longer keyscheme support
Browse files Browse the repository at this point in the history
Tested with secp256k1
  • Loading branch information
diegofigs committed Dec 12, 2024
1 parent e8ab551 commit 9431b35
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-walls-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aurora-is-near/backstage-plugin-blockchainradar-backend': patch
---

feat: add longer keyscheme support
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
10 changes: 9 additions & 1 deletion plugins/blockchainradar-backend/src/entities/NearKey.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(':', '-');
}

Expand Down Expand Up @@ -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',
},
};
}
}
7 changes: 7 additions & 0 deletions plugins/blockchainradar-backend/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 9431b35

Please sign in to comment.