# @moonpay/moonpay-node

A node package for MoonPay server-side functions

## Setup

Set up the `MoonPay` class with your secret key.

Note: ⚠️ NEVER use your secret key in client side code. ⚠️

You will probably want to load the test key from an environment variable.

```typescript
const moonPay = new MoonPay('sk_test_...');
```

## Usage

Use the `moonPay` instance to access our functions.

### URL utilities

MoonPay URL utilities are namespaced under the `.url` property.

#### Signing your URL

If you include the `walletAddress` or `walletAddresses` query param, you'll need to sign the URL.

```typescript
const signature = moonPay.url.generateSignature(
  'https://buy.moonpay.com/?apiKey=pk_test_123&walletAddress=...',
);
```

Or, return the signed URL, using the `returnFullURL` option.

```typescript
const signedURL = moonPay.url.generateSignature(
  'https://buy.moonpay.com/?apiKey=pk_test_123&walletAddress=...',
  { returnFullURL: true },
);
```

#### Verifying a signature

Or, you can verify that a URL is correctly signed.

```typescript
const isSignatureValid = moonPay.url.isSignatureValid(
  '[...]/?apiKey=pk_test_123&signature=someSignature',
);
```

#### Generating a signed URL

You can also have us generate the full, signed URL, based on some input parameters.

```typescript
const params = {
  apiKey: 'pk_test_123',
  baseCurrencyCode: 'GBP',
};

const url = moonPay.url.generate({ flow: 'buy', params });
```
