Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This SDK provides a simple interface for interacting with the Hedera Hashgraph u
No installation needed. Reference the script directly in your HTML:

```html
<script data-src="hcs://1/0.0.7473819" data-script-id="wallet-connect"></script>
<script data-src="hcs://1/0.0.8084872" data-script-id="wallet-connect"></script>
```

### For NPM projects (ESM)
Expand Down
30 changes: 27 additions & 3 deletions dist/es/hashinal-wc.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dist/es/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ declare class HashinalsWalletConnectSDK {
getAccountNFTs(accountId: string, tokenId?: string): Promise<Nft[]>;
validateNFTOwnership(serialNumber: string, accountId: string, tokenId: string): Promise<Nft | null>;
readSmartContract(data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number): Promise<any>;
generatePrivateAndPublicKey(): Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic(topicId: string, memo: string, adminKey: string): Promise<string>;
}
export * from './types';
export * from './sign';
Expand Down
6 changes: 6 additions & 0 deletions dist/es/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,10 @@ export type HashinalsWalletConnectSDK = {
validateNFTOwnership: (serialNumber: string, accountId: string, tokenId: string) => Promise<Nft | null>;
readSmartContract: (data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number) => Promise<any>;
HashgraphSDK: typeof hashgraph;
generatePrivateAndPublicKey: () => Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic: (topicId: string, memo: string, adminKey: string) => Promise<string>;

};
5 changes: 5 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ declare class HashinalsWalletConnectSDK {
getAccountNFTs(accountId: string, tokenId?: string): Promise<Nft[]>;
validateNFTOwnership(serialNumber: string, accountId: string, tokenId: string): Promise<Nft | null>;
readSmartContract(data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number): Promise<any>;
generatePrivateAndPublicKey(): Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic(topicId: string, memo: string, adminKey: string): Promise<string>;
}
export * from './types';
export * from './sign';
Expand Down
5 changes: 5 additions & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,9 @@ export type HashinalsWalletConnectSDK = {
validateNFTOwnership: (serialNumber: string, accountId: string, tokenId: string) => Promise<Nft | null>;
readSmartContract: (data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number) => Promise<any>;
HashgraphSDK: typeof hashgraph;
generatePrivateAndPublicKey: () => Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic: (topicId: string, memo: string, adminKey: string) => Promise<string>;
};
5 changes: 5 additions & 0 deletions dist/umd/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ declare class HashinalsWalletConnectSDK {
getAccountNFTs(accountId: string, tokenId?: string): Promise<Nft[]>;
validateNFTOwnership(serialNumber: string, accountId: string, tokenId: string): Promise<Nft | null>;
readSmartContract(data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number): Promise<any>;
generatePrivateAndPublicKey(): Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic(topicId: string, memo: string, adminKey: string): Promise<string>;
}
export * from './types';
export * from './sign';
Expand Down
5 changes: 5 additions & 0 deletions dist/umd/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,9 @@ export type HashinalsWalletConnectSDK = {
validateNFTOwnership: (serialNumber: string, accountId: string, tokenId: string) => Promise<Nft | null>;
readSmartContract: (data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number) => Promise<any>;
HashgraphSDK: typeof hashgraph;
generatePrivateAndPublicKey: () => Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic: (topicId: string, memo: string, adminKey: string) => Promise<string>;
};
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ declare class HashinalsWalletConnectSDK {
getAccountTokens(accountId: string): Promise<{
tokens: TokenBalance[];
}>;
generatePrivateAndPublicKey(): Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic(topicId: string, memo: string, adminKey: string): Promise<string>;
}

declare global {
Expand Down
37 changes: 34 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
AccountUpdateTransaction,
AccountAllowanceApproveTransaction,
TokenId,
client,
TopicUpdateTransaction
} from '@hashgraph/sdk';
import * as HashgraphSDK from '@hashgraph/sdk';
import {
Expand Down Expand Up @@ -420,19 +422,48 @@ class HashinalsWalletConnectSDK {
};
}


public async generatePrivateAndPublicKey(): Promise<{
privateKey: string;
publicKey: string;
}> {
this.ensureInitialized();
const privateKey = await PrivateKey.generateED25519Async();
const publicKey = privateKey.publicKey;
return {
privateKey: privateKey.toString(),
publicKey: publicKey.toString()
};
}

public async updateTopic(topicId: string, memo: string, adminKey: string): Promise<string> {
this.ensureInitialized();
let transaction = new TopicUpdateTransaction()
.setTopicId(TopicId.fromString(topicId))
.setTopicMemo(memo || "")
.freezeWith(client);

// Convert the adminKey string back to a PrivateKey object
const privateKey = PrivateKey.fromString(adminKey);
const signedTx = await transaction.sign(privateKey);

const receipt = await this.executeTransaction(signedTx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're already signing the transaction, the signer should be disabled in executeTransaction

return receipt.topicId!.toString();
}

public async createTopic(
memo?: string,
adminKey?: string,
submitKey?: string
): Promise<string> {
this.ensureInitialized();

let transaction = new TopicCreateTransaction().setTopicMemo(memo || '');
let transaction = new TopicCreateTransaction().setTopicMemo(memo || "");

if (adminKey) {
const adminWithPrivateKey = PrivateKey.fromString(adminKey);
transaction.setAdminKey(adminWithPrivateKey.publicKey);
transaction = await transaction.sign(adminWithPrivateKey);
transaction.freezeWith(client); // Freeze after setting the admin key
transaction = await transaction.sign(adminWithPrivateKey); // Then sign
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're not disabling the signing in executeTransaction, so ultimately this transaction will still fail because its already frozen

}

if (submitKey) {
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ export type HashinalsWalletConnectSDK = {
adminKey?: string,
submitKey?: string
) => Promise<string>;
generatePrivateAndPublicKey: () => Promise<{
privateKey: string;
publicKey: string;
}>;
updateTopic: (topicId: string, memo: string, adminKey: string) => Promise<string>;
createToken: (
name: string,
symbol: string,
Expand Down