Skip to content

Commit fa77a2e

Browse files
Merge branch 'master' into rel/latest
2 parents 48290af + c42cc74 commit fa77a2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2106
-232
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { BitGo, Wallet } from 'bitgo';
2+
3+
// change this to env: 'production' when you are ready for production
4+
const bitgo = new BitGo({ env: 'test' });
5+
6+
// this can be retrieved by logging into app.bitgo-test.com (app.bitgo.com for production)
7+
// and going to: User > User Settings > Access Tokens > (+ icon)
8+
// the token will need Spender permission
9+
const accessToken = '';
10+
11+
// change this to 'apt' when you are ready for production
12+
const coin = 'tapt';
13+
const walletId = '';
14+
const walletPassphrase = '';
15+
16+
// this will need to be a real OTP code on production
17+
const otp = '000000';
18+
19+
async function main() {
20+
bitgo.authenticateWithAccessToken({ accessToken });
21+
22+
const wallet: Wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
23+
if (!wallet) {
24+
throw new Error('Failed to retrieve wallet');
25+
}
26+
27+
// we have to unlock this session since we're sending funds
28+
const unlock = await bitgo.unlock({ otp, duration: 3600 });
29+
if (!unlock) {
30+
throw new Error('Unlock failed');
31+
}
32+
33+
const sendConsolidations = await wallet.sendAccountConsolidations({
34+
walletPassphrase,
35+
consolidateAddresses: [''],
36+
nftCollectionId: '',
37+
nftId: '',
38+
});
39+
console.dir(sendConsolidations, { depth: 6 });
40+
}
41+
42+
main().catch((e) => console.error(e));

modules/abstract-substrate/src/lib/iface.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,22 @@ export enum MethodNames {
3131
* @see https://polkadot.js.org/docs/substrate/extrinsics/#transferkeepalivedest-multiaddress-value-compactu128
3232
*/
3333
TransferKeepAlive = 'transferKeepAlive',
34+
/**
35+
* Transfer funds with an optional memo attached.
36+
* The memo allows adding context or metadata to the transaction, commonly used for recordkeeping or identification.
37+
*
38+
* @see https://developers.polymesh.network/sdk-docs/enums/Generated/Types/BalancesTx/#transferwithmemo
39+
*/
40+
TransferWithMemo = 'transferWithMemo',
3441
AddStake = 'addStake',
3542
RemoveStake = 'removeStake',
43+
44+
/**
45+
* Registers a Decentralized Identifier (DID) along with Customer Due Diligence (CDD) information.
46+
*
47+
* @see https://developers.polymesh.network/sdk-docs/enums/Generated/Types/IdentityTx/#cddregisterdidwithcdd
48+
*/
49+
RegisterDidWithCDD = 'cddRegisterDidWithCdd',
3650
}
3751

3852
/**
@@ -75,6 +89,12 @@ export interface TransferAllArgs {
7589
keepAlive: boolean;
7690
}
7791

92+
export interface TransferWithMemoArgs extends Args {
93+
dest: { id: string };
94+
value: string;
95+
memo: string;
96+
}
97+
7898
export interface AddStakeArgs extends Args {
7999
amountStaked: string;
80100
hotkey: string;

modules/abstract-substrate/src/lib/txnSchema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export const TransferAllTransactionSchema = joi.object({
4040
to: addressSchema.required(),
4141
});
4242

43+
export const TransferWithMemoTransactionSchema = joi.object({
44+
amount: joi.string().required(),
45+
to: addressSchema.required(),
46+
memo: joi.string().required(),
47+
});
48+
4349
export const StakeTransactionSchema = joi.object({
4450
amountStaked: joi.string().required(),
4551
hotkey: joi.string().required(),

modules/sdk-coin-fetch/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
"@bitgo/abstract-cosmos": "^11.7.3",
4444
"@bitgo/sdk-core": "^33.2.0",
4545
"@bitgo/statics": "^52.2.0",
46-
"@cosmjs/stargate": "^0.29.5"
46+
"@cosmjs/stargate": "^0.29.5",
47+
"@cosmjs/amino": "^0.29.5",
48+
"@cosmjs/encoding": "^0.29.5",
49+
"@cosmjs/stargate": "^0.29.5",
50+
"bignumber.js": "^9.1.1"
4751
},
4852
"devDependencies": {
4953
"@bitgo/sdk-api": "^1.62.3",

modules/sdk-coin-fetch/src/fetch.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
2-
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
1+
import { BaseCoin, BitGoBase, Environments } from '@bitgo/sdk-core';
2+
import { BaseUnit, BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
33
import { CosmosCoin, CosmosKeyPair, GasAmountDetails } from '@bitgo/abstract-cosmos';
4-
import { TransactionBuilderFactory } from './lib';
4+
import { KeyPair, TransactionBuilderFactory } from './lib';
5+
import { GAS_AMOUNT, GAS_LIMIT } from './lib/constants';
6+
import utils from './lib/utils';
57

8+
/**
9+
*
10+
* Full Name: Fetch
11+
* Website: https://innovationlab.fetch.ai/
12+
* Docs: https://website.prod.fetch-ai.com/docs/
13+
* GitHub : https://github.com/fetchai
14+
*/
615
export class Fetch extends CosmosCoin {
716
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
817

@@ -27,36 +36,39 @@ export class Fetch extends CosmosCoin {
2736

2837
/** @inheritDoc **/
2938
getBuilder(): TransactionBuilderFactory {
30-
throw new Error('Method not implemented.');
39+
return new TransactionBuilderFactory(coins.get(this.getChain()));
3140
}
3241

3342
/** @inheritDoc **/
3443
isValidAddress(address: string): boolean {
35-
throw new Error('Method not implemented.');
44+
return utils.isValidAddress(address) || utils.isValidValidatorAddress(address);
3645
}
3746

3847
/** @inheritDoc **/
3948
getDenomination(): string {
40-
throw new Error('Method not implemented');
49+
return BaseUnit.FETCH;
4150
}
4251

4352
/** @inheritDoc **/
4453
getGasAmountDetails(): GasAmountDetails {
45-
throw new Error('Method not implemented');
54+
return {
55+
gasAmount: GAS_AMOUNT,
56+
gasLimit: GAS_LIMIT,
57+
};
4658
}
4759

4860
/** @inheritDoc **/
4961
getKeyPair(publicKey: string): CosmosKeyPair {
50-
throw new Error('Method not implemented');
62+
return new KeyPair({ pub: publicKey });
5163
}
5264

5365
/** @inheritDoc **/
5466
protected getPublicNodeUrl(): string {
55-
throw new Error('Method not implemented');
67+
return Environments[this.bitgo.getEnv()].fetchNodeUrl;
5668
}
5769

5870
/** @inheritDoc **/
5971
getAddressFromPublicKey(pubKey: string): string {
60-
throw new Error('Method not implemented');
72+
return new KeyPair({ pub: pubKey }).getAddress();
6173
}
6274
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const validDenoms = ['fet', 'tfet', 'afet', 'atestfet'];
2+
export const accountAddressRegex = /^(fetch)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
3+
export const validatorAddressRegex = /^(fetchvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
4+
export const contractAddressRegex = /^(fetch)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
5+
export const ADDRESS_PREFIX = 'fetch';
6+
export const GAS_AMOUNT = '100000000000000';
7+
export const GAS_LIMIT = 100000;

modules/sdk-coin-fetch/src/lib/keyPair.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { KeyPairOptions } from '@bitgo/sdk-core';
2+
import { pubkeyToAddress } from '@cosmjs/amino';
23
import { CosmosKeyPair } from '@bitgo/abstract-cosmos';
4+
import { ADDRESS_PREFIX } from './constants';
35

46
/**
57
* Fetch keys and address management.
@@ -11,6 +13,13 @@ export class KeyPair extends CosmosKeyPair {
1113

1214
/** @inheritdoc */
1315
getAddress(): string {
14-
throw new Error('Method not implemented.');
16+
const base64String = Buffer.from(this.getKeys().pub.slice(0, 66), 'hex').toString('base64');
17+
return pubkeyToAddress(
18+
{
19+
type: 'tendermint/PubKeySecp256k1',
20+
value: base64String,
21+
},
22+
ADDRESS_PREFIX
23+
);
1524
}
1625
}

modules/sdk-coin-fetch/src/lib/utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
import { CosmosUtils } from '@bitgo/abstract-cosmos';
2+
import { InvalidTransactionError } from '@bitgo/sdk-core';
23
import { Coin } from '@cosmjs/stargate';
4+
import BigNumber from 'bignumber.js';
5+
import * as constants from './constants';
36

47
export class Utils extends CosmosUtils {
58
/** @inheritdoc */
69
isValidAddress(address: string): boolean {
7-
throw new Error('Method not implemented.');
10+
return this.isValidCosmosLikeAddressWithMemoId(address, constants.accountAddressRegex);
811
}
912

1013
/** @inheritdoc */
1114
isValidValidatorAddress(address: string): boolean {
12-
throw new Error('Method not implemented.');
15+
return this.isValidBech32AddressMatchingRegex(address, constants.validatorAddressRegex);
1316
}
1417

1518
/** @inheritdoc */
1619
isValidContractAddress(address: string): boolean {
17-
throw new Error('Method not implemented.');
20+
return this.isValidBech32AddressMatchingRegex(address, constants.contractAddressRegex);
1821
}
1922

2023
/** @inheritdoc */
2124
validateAmount(amount: Coin): void {
22-
throw new Error('Method not implemented.');
25+
const amountBig = BigNumber(amount.amount);
26+
if (amountBig.isLessThanOrEqualTo(0)) {
27+
throw new InvalidTransactionError('transactionBuilder: validateAmount: Invalid amount: ' + amount.amount);
28+
}
29+
if (!constants.validDenoms.find((denom) => denom === amount.denom)) {
30+
throw new InvalidTransactionError('transactionBuilder: validateAmount: Invalid denom: ' + amount.denom);
31+
}
2332
}
2433
}
2534

0 commit comments

Comments
 (0)